Content-type: text/html
#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);
Link with -ljalali
The jasctime() and jmktime() functions both take an argument representing broken-down jalali time which is a representation separated into year, month, day, etc.
Broken-down jalali time is stored in the structure jtm which 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 */ };
The members of the jtm structure are:
Information about a certain year in jalali system is stored in the structure jyinfo in the following format:
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 */ };
The members of the jyinfo structure are:
Internal jalali date functions make use of passed days since UTC Epoch to calculate date and time. To store these information, the following structure is also defined:
struct ab_jtm { int ab_sec; int ab_min; int ab_hour; int ab_days; };
The members of the ab_jtm structure are as follows:
The call jctime(t) is equivalent to jasctime(jlocaltime(t)). It converts the calendar time t into a null-terminated string of the form
The abbreviations for the days of the week are "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", and "Sat". 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 which might be overwritten by subsequent calls to any of the date and time functions. The reentrant version jctime_r() does the same, but stores the string in a user-supplied buffer which should have room for at least 26 bytes.
The jgmtime() function converts the calendar time timep to broken-down jalali time representation, expressed in Coordinated Universal Time (UTC). 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. The jgmtime_r() function does the same, but stores the data in a user-supplied struct. The function acts as if it called tzset(3)
The jlocaltime() function converts the calendar time timep to 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 information 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. The jlocaltime_r() function does the same, but stores the data in a user-supplied struct.
The jasctime() function 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. The jasctime_r() function does the same, but stores the string in a user-supplied buffer which should have room for at least 26 bytes.
The jmktime() function converts a broken-down jalali time structure, expressed as local time, to calendar time representation. The function ignores the values supplied by the caller in the tm_wday field. The value specified in the tm_isdst field 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;
The jmktime() function modifies the fields of the jtm structure as follows: tm_wday and tm_yday are set to values determined from the contents of the other fields; if structure members are outside their valid interval, they will be normalized (so that, for example, 40 Bahman is changed into 10 Esfand); Calling jmktime() also sets the external variable tzname with information about the current timezone.
jmktime() function does not check the values of the jtm structure.
There are a number of non-standard functions also provided to work with jalali date and time.
The jalali_is_jleap() function 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.
The jalali_create_time_from_secs() function fills out the ab_jtm structure members based on the absolute number of seconds elapsed since UTC Epoch.
The jalali_create_secs_from_time() function is the converse function to jalali_create_time_from_secs() which returns absolute number of seconds elapsed since UTC Epoch based on the supplied ab_jtm structure.
The jalali_create_date_from_days() function alters tm_mon and tm_mday fields of the broken-down jalali time strucutre based on it's tm_yday field. It returns -1 on the event of encountering any errors and structure fields remain untouched.
The jalali_create_days_from_date() function alters tm_yday field of the broken-down jalali time structure based on it's tm_mon and tm_mday fields. It returns -1 on the event of encountering any errors and structure fields remain untouched.
The jalali_get_jyear_info() function modifies jyinfo structure fields to match information for year specified by it's y field. Information regarding a year in jalali system includes leap flag, passed and reamining years in the grand cycle, passed and remaining leap years in the grand cycle and absolute number of passed leaps since UTC Epoch.
The jalali_get_date() function calculates the jalali date based on number of days since UTC epoch. It alters the broken-down jalali time structure fields accordingly.
The jalali_get_diff() function is the converse function of jalali_get_date() and calculates the number of days passed since UTC Epoch based on a broken-down jalali time structure supplied to it.
The jalali_update() function updates tm_wday and tm_yday fields of the broken-down jalali time structure based on it's tm_year , tm_mon and tm_mday. tm_isdst, tm_gmtoff and tm_zone fields are set accordingly. tm_hour, tm_min and tm_sec fields remain untouched.
#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]); jalali_update(&jtm); t = jmktime(&jtm); localtime_r(&t, &tm); printf("%d/%d/%d \n", tm.tm_year, tm.tm_mon, tm.tm_mday); exit(EXIT_SUCCESS); }
like POSIX.1-2008, the following functions: jasctime(), jasctime_r(), jctime(), and jctime_r() should be considered obsolete. Use jstrftime(3) instead.
libjalali version of struct jtm has additional fields
long tm_gmtoff; /* Seconds east of UTC */ const char *tm_zone; /* Timezone abbreviation */
libjalali home page: <http://savannah.nongnu.org/projects/jcal/>
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.