JCTIME(3)
π JCTIME(3) π
okay bestie, welcome to JCTIME(3) β straight out of the libjalali Manual, and it's a whole journey. This is part 1, so grab a boba and lock in. π§β¨
π NAME π
jasctime, jctime, jgmtime, jlocaltime, jmktime, jasctime_r, jctime_r, jgmtime_r, jlocaltime_r β the girlies that transform a jalali date and time into either a broken-down jalali time or straight-up ASCII. π
π SYNOPSIS π
#include <jtime.h>
char *jasctime(const struct jtm *jtm);
char *jasctime_r(const struct jtm *jtm, char *buf);
char *jctime(const time_t *timep);
char *jctime_r(const time_t *timep, char *buf);
struct jtm *jgmtime(const time_t *timep);
struct jtm *jgmtime_r(const time_t *timep, struct jtm *result);
struct jtm *jlocaltime(const time_t *timep);
struct jtm *jlocaltime_r(const time_t *timep, struct jtm *result);
time_t jmktime(struct jtm *jtm);
#include <jalali.h>
int jalali_is_jleap(int year);
void jalali_create_time_from_secs(time_t time, struct ab_jtm* ab_jtm);
time_t jalali_create_secs_from_time(const struct ab_jtm* ab_jtm);
int jalali_create_date_from_days(struct jtm* jtm);
int jalali_create_days_from_date(struct jtm* jtm);
void jalali_get_jyear_info(struct jyinfo* jyinfo);
void jalali_get_date(int p, struct jtm* jtm);
int jalali_get_diff(const struct jtm* jtm);
void jalali_update(struct jtm* jtm);
and when you compile, link with -ljalali or nothing works, no cap. π
β¨ DESCRIPTION β¨
So jctime(), jgmtime() and jlocaltime() all take one lil argument of type time_t that represents calendar time. And when you read it as an absolute time value? It's literally the number of seconds that have elapsed since the Epoch β that's 1970-01-01 (1348-10-11 in Jalali), 00:00:00 +0000 (UTC). β³
Meanwhile jasctime() and jmktime() both take an argument that's a broken-down jalali time β meaning it's been separated into year, month, day, etc. ποΈ
Broken-down jalali time lives in the structure jtm, which is defined in <jtime.h> like this:
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 */
};
And here's the rundown of every jtm member, one by one, no skips:
tm_secβ the number of seconds after the minute, range0to59. β±οΈtm_minβ the number of minutes after the hour, range0to59. β±οΈtm_hourβ the number of hours past midnight, range0to23. β±οΈtm_mdayβ the day of the month, range1to31. πtm_monβ the number of months since Farvadin, range0to11. πtm_yearβ absolute year number, century included. πtm_wdayβ the number of days since Saturday, range0to6. ποΈtm_ydayβ the number of days since Farvadin 1, range0to365. ποΈtm_isdstβ a flag saying whether daylight saving time is in effect at the described time. Positive value = DST is in effect, zero = it isn't. βοΈ
Now, info about a certain year in the jalali system is stored in the structure jyinfo, formatted like this:
struct jyinfo {
int lf; /* leap indicator flag */
int y; /* year */
int r; /* reamining years in grand cycle */
int p; /* passed years from grand cycle*/
int rl; /* remaining leap years in grand cycle */
int pl; /* passed leap years in grand cycle */
int apl; /* absolute passed leaps */
};
And the members of jyinfo, decoded for you:
lfβ a flag that says whether a year is leap or not. πΈyβ absolute year number, century included. πrβ the number of remaining years in the grand cycle. (That cycle is2820years long, fyi.) πpβ the number of passed years in the grand cycle. βοΈrlβ the number of remaining leap years in the grand cycle. πΈplβ the number of passed leap years in the grand cycle. βοΈaplβ the absolute number of passed leaps since Epoch. π
The internal jalali date functions use passed days since the UTC Epoch to work out date and time. And to store all that, this structure is also defined:
struct ab_jtm {
int ab_sec;
int ab_min;
int ab_hour;
int ab_days;
};
And the members of ab_jtm go like this:
ab_secβ the number of seconds. β±οΈab_minβ the number of minutes. β±οΈab_hourβ the number of hours. β±οΈab_daysβ the absolute number of days since UTC Epoch. (1348-10-11) π
So the call jctime(t) is equivalent to jasctime(jlocaltime(t)). It converts the calendar time t into a null-terminated string shaped like:
"Jom Kho 06 22:59:17 1390\n"
The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat". And the Farsi transliteration for the days of the week are "Sha", "Yek", "Dos", "Ses", "Cha", "Pan", and "Jom". The abbreviations for the months are "Far", "Ord", "Kho", "Tir", "Mor", "Sha", "Meh", "Aba", "Aza", "Dey", "Bah", and "Esf". π
β οΈ The return value points to a statically allocated string, so it might get overwritten by later calls to any of the date and time functions. Not a forever girl, she's reusable. π
The reentrant version jctime_r() does the same thing, except it stores the string in a user-supplied buffer, which needs room for at least 26 bytes. π¦
jgmtime() converts the calendar time timep into a broken-down jalali time representation, expressed in Coordinated Universal Time (UTC). The return value points to a statically allocated struct that might be overwritten by subsequent calls to any of the jalali date and time functions. jgmtime_r() does the same, but stores the data in a user-supplied struct. The function acts as if it called tzset(3). π
jlocaltime() converts the calendar time timep into a broken-down jalali time representation, expressed relative to the user's specified timezone. The function acts as if it called tzset(3) and sets the external variables tzname with info about the current timezone, timezone with the difference between Coordinated Universal Time (UTC) and local standard time in seconds, and daylight to a nonzero value if daylight savings time rules apply during some part of the year. The return value points to a statically allocated struct which might be overwritten by subsequent calls to any of the jalali date and time functions. jlocaltime_r() does the same, but stores the data in a user-supplied struct. π°οΈ
jasctime() converts the broken-down jalali time value jtm into a null-terminated string with the same format as jctime(). The return value points to a statically allocated string which might be overwritten by subsequent calls to any of the date and time functions. jasctime_r() does the same, but stores the string in a user-supplied buffer which should have room for at least 26 bytes. π¦
jmktime() converts a broken-down jalali time structure, expressed as local time, into calendar time representation. It ignores the values supplied by the caller in the tm_wday field. π The value specified in tm_isdst informs jmktime() whether or not daylight saving time (DST) is in effect for the time supplied in the jtm structure: a positive value means DST is in effect; zero means that DST is not in effect. βοΈ
jmktime() also modifies the fields of the jtm structure like this: tm_wday and tm_yday get set to values determined from the contents of the other fields; and if structure members are outside their valid interval, they get normalized (so for example, 40 Bahman is changed into 10 Esfand β she will fix your mess π
). Calling jmktime() also sets the external variable tzname with information about the current timezone. π
There are a whole bunch of non-standard functions provided too, for working with jalali date and time:
jalali_is_jleap() returns an integer indicating whether the year specified is leap or not. It returns 1 on the event of encountering a leap year, 0 otherwise. πΈ
jalali_create_time_from_secs() fills out the ab_jtm structure members based on the absolute number of seconds elapsed since UTC Epoch. β³
jalali_create_secs_from_time() is the converse function to jalali_create_time_from_secs(), and it returns the absolute number of seconds elapsed since UTC Epoch based on the supplied ab_jtm structure. π
jalali_create_date_from_days() alters the tm_mon and tm_mday fields of the broken-down jalali time structure based on its tm_yday field. It returns -1 on the event of encountering any errors, and the structure fields remain untouched. π
jalali_create_days_from_date() alters the tm_yday field of the broken-down jalali time structure based on its tm_mon and tm_mday fields. It returns -1 on the event of encountering any errors, and the structure fields remain untouched. π
jalali_get_jyear_info() modifies jyinfo structure fields to match information for the year specified by its y field. Info about a year in the jalali system includes the leap flag, passed and remaining years in the grand cycle, passed and remaining leap years in the grand cycle, and the absolute number of passed leaps since UTC Epoch. π
jalali_get_date() calculates the jalali date based on the number of days since UTC epoch. It alters the broken-down jalali time structure fields accordingly. π
jalali_get_diff() is the converse function of jalali_get_date(), and it calculates the number of days passed since UTC Epoch based on a broken-down jalali time structure supplied to it. π
jalali_update() updates the tm_wday and tm_yday fields of the broken-down jalali time structure based on its tm_year, tm_mon, tm_mday, tm_hour, tm_min and tm_sec fields. If structure members are outside their valid interval, they get normalized (so, again, 40 Bahman becomes 10 Esfand π
). tm_isdst, tm_gmtoff and tm_zone fields are set accordingly. β¨
πΈ EXAMPLES πΈ
This lil program converts a jalali date to gregorian, and it's giving main character energy:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <jalali.h>
#include <jtime.h>
int
main(int argc, char ** argv)
{
struct tm tm;
struct jtm jtm;
time_t t;
jtm.tm_year = atoi(argv[1]);
jtm.tm_mon = atoi(argv[2]);
jtm.tm_mday = atoi(argv[3]);
t = jmktime(&jtm);
localtime_r(&t, &tm);
printf("%d/%d/%d \n", tm.tm_year, tm.tm_mon, tm.tm_mday);
exit(EXIT_SUCCESS);
}
β RETURN VALUE β
Every one of these functions returns the value described above, or NULL β and that's -1 in the case of jmktime() β if an error was detected. So check your returns, bestie, fr fr. π«Ά
okay that's part 1, don't go anywhere β more of this page is coming π
β¨ CONFORMING TO β¨
okay bestie so C99 Standards. These functions are provided with APIs similar to that of POSIX.1-2001 date and time manipulation and are NOT part of POSIX standard. For thread safety jasctime(), jctime(), gmtime(), localtime(), and mktime() set of functions should nout be used. See reentrant versions.
like POSIX.1-2008, the following functions: jasctime(), jasctime_r(), jctime(), and jctime_r() should be considered obsolete. Use jstrftime(3) instead.
πΈ NOTES πΈ
The four functions jasctime(), jctime(), jgmtime() and jlocaltime() return a pointer to static data and hence are not thread-safe. Thread-safe versions are jasctime_r(), jctime_r(), jgmtime_r() and jlocaltime_r()
libjalali version of struct jtm has additional fields
long tm_gmtoff; /* Seconds east of UTC */
const char *tm_zone; /* Timezone abbreviation */
π SEE ALSO π
jdate(1)jcal(1)gettimeofday(2)time(2)utime(2)clock(3)difftime(3)jstrftime(3)jstrptime(3)timegm(3)tzset(3)time(7)
π COLOPHON π
This page is part of release 0.2 of the libjalali man-pages
π«Ά AUTHOR π«Ά
Written by Ashkan Ghassemi. <ghassemi@ftml.net>
π 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.
and thatβs the whole vibe check, bestie π this page comes from release 0.2 of the libjalali man-pages, dated 2011-05-28, and itβs JCTIME(3) β go forth and maybe use the reentrant versions, fr fr π¦β¨
π¦ where this page comes from
- debian trixie: jcal 0.5.1-0.2
- 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