JSTRPTIME(3)
π JSTRPTIME(3) π
okay so this is jstrptime, bestie β it lives in the libjalali Manual and it's about turning a string that looks like a jalali date into an actual jalali time jtm struct. it's giving time-travel but make it parsing. π°οΈβ¨
πΈ NAME πΈ
jstrptime β convert a string representation of jalali date and time to a jalali time jtm structure. literally the glow-up from text to struct. π
β¨ SYNOPSIS β¨
#include <time.h>
char *jstrptime(const char *s, const char *format, struct jtm *jtm);
and like, don't forget:
Link with -ljalali
π¦ DESCRIPTION π¦
So jstrptime() is the converse function to jstrftime(3) β they're besties who do opposite things. It takes the character string pointed to by s and converts it into values which are stored in the jtm structure pointed to by jtm, using the format specified by format.
Now format? It's a character string made of field descriptors and text characters, and it's very reminiscent of scanf(3). Each field descriptor is a % character followed by another character that specifies the replacement for the field descriptor. Every other character in the format string must have a matching character in the input string. And there should be whitespace or other alphanumeric characters between any two field descriptors β no squishing them together, that's not the vibe. π
ββοΈ
The jstrptime() function processes the input string from left to right. Each of the three possible input elements (whitespace, literal, or format) are handled one after the other. If the input cannot be matched to the format string, the function stops β and the remainder of the format and input strings are not processed. it justβ¦ walks away. iconic behavior honestly. π
The supported input field descriptors are listed below. In case a text string (such as a weekday or month name) is to be matched, the comparison is case insensitive. In case a number is to be matched, leading zeros are permitted but not required. π
%%β The%character.%aor%Aor%hor%qβ The weekday name in abbreviated form or the full name.%bor%Bβ The month name in abbreviated form or the full name.%dor%eβ The day of month (1-31).%Hβ The hour (0-23).%jβ The day number in the year (1-366).%mβ The month number (1-12).%Mβ The minute (0-59).%sβ Seconds since UTC Epoch.%Sβ The second (0-59).%yβ The year within century (0-99). When a century is not otherwise specified, values in the range 19-99 refer to years in the fourteenth century (1319-1399); values in the range 00-18 refer to years in the fifteenth century (1400-1418).%Yβ The year, including century (for example, 1390).
π the jtm struct, served fresh π
The broken-down jalali time structure jtm is defined in <jtime.h> as follows:
struct jtm {
int tm_sec; /* seconds */
int tm_min; /* minutes */
int tm_hour; /* hours */
int tm_mday; /* day of the month */
int tm_mon; /* month */
int tm_year; /* year */
int tm_wday; /* day of the week */
int tm_yday; /* day in the year */
int tm_isdst; /* daylight saving time */
};
look at her. nine ints. main character energy. π
π«Ά RETURN VALUE π«Ά
The return value of the function is a pointer to the first character not processed in this function call. π―
- In case the input string contains more characters than required by the format string, the return value points right after the last consumed input character.
- In case the whole input string is consumed, the return value points to the null byte at the end of the string.
- If
jstrptime()fails to match all of the format string and therefore an error occurred, the function returnsNULL. π
π CONFORMING TO π
C99. she's certified, no cap. π
β NOTES β
In principle, this function does not initializejtmbut only stores the values specified. This means thatjtmshould be initialized before the call. libjalali does not touch those fields which are not explicitly specified.
so likeβ¦ memset first, bestie. don't rawdog an uninitialized struct. π
π EXAMPLE π
The following example demonstrates the use of jstrptime(3) and jstrftime(3). they're a duo, a package deal, a power couple. π
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <jalali.h>
#include <jtime.h>
int
main(void)
{
struct jtm tm;
char buf[255];
memset(&jtm, 0, sizeof(struct jtm));
jstrptime("1390-03-17 08:33:01", "%Y-%m-%d %H:%M:%S", &jtm);
jstrftime(buf, sizeof(buf), "%d %b %Y %H:%M", &jtm);
puts(buf);
exit(EXIT_SUCCESS);
}
π₯ SEE ALSO π₯
time(2), jdate(1), jcal(1), getdate(3), scanf(3), jstrftime(3), jctime(3), feature_test_macros(7)
the whole friend group fr fr. go say hi. π«
π COLOPHON π
This page is part of release 0.2 of the libjalali man-pages. β¨
π AUTHOR π
Written by Ashkan Ghassemi. <ghassemi@ftml.net> β king behavior, we stan. π
π REPORTING BUGS π
Report libjalali bugs to <ghassemi@ftml.net> π¬
libjalali home page: <http://savannah.nongnu.org/projects/jcal/>
π COPYRIGHT π
Copyright (C) 2011 Ashkan Ghassemi.
License LGPLv3+: GNU LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. β οΈ (yes, the caps are doing the heavy lifting there. it's serious.)
and that's the whole page, bestie β brought to you by GNU, dated 2011-05-28, filed under JSTRPTIME(3). go parse something gorgeous. ππ¦π
π¦ where this page comes from
- debian trixie: jcal 0.5.1-0.2
- fedora 43: libjalali-devel 0.4.1-32.fc43 Β· GPL-3.0-or-later
- fedora 43: libjalali-devel 0.4.1-32.fc43 Β· GPL-3.0-or-later
- fedora 44: libjalali-devel 0.4.1-33.fc44 Β· GPL-3.0-or-later
- fedora 44: libjalali-devel 0.4.1-33.fc44 Β· GPL-3.0-or-later
- nixos 26.05: jcal 0.5.1
- nixpkgs unstable: jcal 0.5.1
- ubuntu questing: jcal 0.5.1-0.2
- ubuntu resolute: jcal 0.5.1-0.2build1
- ubuntu stonking: jcal 0.5.1-0.2build1
- Copyright (C) 2006, 2007, 2009, 2010, 2011 Ashkan Ghassemi
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms