JCTIME(3)

NAME
jasctime, jctime, jgmtime, jlocaltime, jmktime, jasctime_r, jctime_r, jgmtime_r, jlocaltime_r - transform jalali date and time to broken-down jalali time or 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);

Link with -ljalali

DESCRIPTION
The jctime(), jgmtime() and jlocaltime() functions all take an argument of data type time_t which represents calendar time. When interpreted as an absolute time value, it represents the number of seconds elapsed since the Epoch, 1970-01-01 (1348-10-11 in Jalali) 00:00:00 +0000 (UTC).

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:

tm_sec
    The number of seconds after the minute, in the range 0 to 59.

tm_min
    The number of minutes after the hour, in the range 0 to 59.

tm_hour
    The number of hours past midnight, in the range 0 to 23.

tm_mday
    The day of the month, in the range 1 to 31.

tm_mon
    The number of months since Farvadin, in the range 0 to 11.

tm_year
    Absolute year number including the century.

tm_wday
    The number of days since Saturday, in the range 0 to 6.

tm_yday
    The number of days since Farvadin 1, in the range 0 to 365.

tm_isdst
    A flag that indicates whether daylight saving time is in effect at the time described. The value is positive if daylight saving time is in effect, zero otherwise.

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:

lf  A flag that indicates whether a year is leap or not.

y   Absolute year number including the century.

r   The number of remaining years in the grand cycle. (2820 years in length)

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.

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:

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)

The call jctime(t) is equivalent to jasctime(jlocaltime(t)). It converts the calendar time t into a null-terminated string of the form

    "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". 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.

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, tm_mday, tm_hour, tm_min and tm_sec fields. If structure members are outside their valid interval, they will be normalized (so that, for example, 40 Bahman is changed into 10 Esfand). tm_isdst, tm_gmtoff and tm_zone fields are set accordingly.

EXAMPLES
The following program converts a jalali date to gregorian
#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
Each of these functions returns the value described, or NULL (-1 in case of jmktime()) in case an error was detected.

CONFORMING TO
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.