Back to index

php5  5.3.10
Defines | Typedefs | Functions
timelib.h File Reference
#include "timelib_structs.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define TIMELIB_VERSION   201102
#define TIMELIB_NONE   0x00
#define TIMELIB_OVERRIDE_TIME   0x01
#define TIMELIB_NO_CLONE   0x02
#define TIMELIB_UNSET   -99999
#define TIMELIB_SPECIAL_WEEKDAY   0x01
#define TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH   0x02
#define TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH   0x03
#define LONG_MAX   2147483647L
#define LONG_MIN   (- LONG_MAX - 1)

Typedefs

typedef timelib_tzinfo *(* timelib_tz_get_wrapper )(char *tzname, const timelib_tzdb *tzdb)

Functions

timelib_sll timelib_day_of_week (timelib_sll y, timelib_sll m, timelib_sll d)
timelib_sll timelib_iso_day_of_week (timelib_sll y, timelib_sll m, timelib_sll d)
timelib_sll timelib_day_of_year (timelib_sll y, timelib_sll m, timelib_sll d)
timelib_sll timelib_daynr_from_weeknr (timelib_sll y, timelib_sll w, timelib_sll d)
timelib_sll timelib_days_in_month (timelib_sll y, timelib_sll m)
void timelib_isoweek_from_date (timelib_sll y, timelib_sll m, timelib_sll d, timelib_sll *iw, timelib_sll *iy)
int timelib_valid_time (timelib_sll h, timelib_sll i, timelib_sll s)
int timelib_valid_date (timelib_sll y, timelib_sll m, timelib_sll d)
timelib_timetimelib_strtotime (char *s, int len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper)
timelib_timetimelib_parse_from_format (char *format, char *s, int len, timelib_error_container **errors, const timelib_tzdb *tzdb, timelib_tz_get_wrapper tz_get_wrapper)
void timelib_fill_holes (timelib_time *parsed, timelib_time *now, int options)
char * timelib_timezone_id_from_abbr (const char *abbr, long gmtoffset, int isdst)
const timelib_tz_lookup_tabletimelib_timezone_abbreviations_list (void)
void timelib_strtointerval (char *s, int len, timelib_time **begin, timelib_time **end, timelib_rel_time **period, int *recurrences, struct timelib_error_container **errors)
void timelib_update_ts (timelib_time *time, timelib_tzinfo *tzi)
void timelib_do_normalize (timelib_time *base)
void timelib_do_rel_normalize (timelib_time *base, timelib_rel_time *rt)
int timelib_apply_localtime (timelib_time *t, unsigned int localtime)
void timelib_unixtime2gmt (timelib_time *tm, timelib_sll ts)
void timelib_unixtime2local (timelib_time *tm, timelib_sll ts)
void timelib_update_from_sse (timelib_time *tm)
void timelib_set_timezone (timelib_time *t, timelib_tzinfo *tz)
int timelib_timezone_id_is_valid (char *timezone, const timelib_tzdb *tzdb)
timelib_tzinfotimelib_parse_tzfile (char *timezone, const timelib_tzdb *tzdb)
int timelib_timestamp_is_in_dst (timelib_sll ts, timelib_tzinfo *tz)
timelib_time_offsettimelib_get_time_zone_info (timelib_sll ts, timelib_tzinfo *tz)
timelib_sll timelib_get_current_offset (timelib_time *t)
void timelib_dump_tzinfo (timelib_tzinfo *tz)
const timelib_tzdbtimelib_builtin_db (void)
const timelib_tzdb_index_entrytimelib_timezone_builtin_identifiers_list (int *count)
timelib_tzinfotimelib_tzinfo_ctor (char *name)
void timelib_time_tz_abbr_update (timelib_time *tm, char *tz_abbr)
void timelib_time_tz_name_update (timelib_time *tm, char *tz_name)
void timelib_tzinfo_dtor (timelib_tzinfo *tz)
timelib_tzinfotimelib_tzinfo_clone (timelib_tzinfo *tz)
timelib_rel_timetimelib_rel_time_ctor (void)
void timelib_rel_time_dtor (timelib_rel_time *t)
timelib_rel_timetimelib_rel_time_clone (timelib_rel_time *tz)
timelib_timetimelib_time_ctor (void)
void timelib_time_set_option (timelib_time *tm, int option, void *option_value)
void timelib_time_dtor (timelib_time *t)
timelib_timetimelib_time_clone (timelib_time *orig)
timelib_time_offsettimelib_time_offset_ctor (void)
void timelib_time_offset_dtor (timelib_time_offset *t)
void timelib_error_container_dtor (timelib_error_container *errors)
signed long timelib_date_to_int (timelib_time *d, int *error)
void timelib_dump_date (timelib_time *d, int options)
void timelib_dump_rel_time (timelib_rel_time *d)
void timelib_decimal_hour_to_hms (double h, int *hour, int *min, int *sec)
double timelib_ts_to_juliandate (timelib_sll ts)
int timelib_astro_rise_set_altitude (timelib_time *time, double lon, double lat, double altit, int upper_limb, double *h_rise, double *h_set, timelib_sll *ts_rise, timelib_sll *ts_set, timelib_sll *ts_transit)
 Note: timestamp = unixtimestamp (NEEDS to be 00:00:00 UT) Eastern longitude positive, Western longitude negative Northern latitude positive, Southern latitude negative The longitude value IS critical in this function! altit = the altitude which the Sun should cross Set to -35/60 degrees for rise/set, -6 degrees for civil, -12 degrees for nautical and -18 degrees for astronomical twilight.
timelib_rel_timetimelib_diff (timelib_time *one, timelib_time *two)

Define Documentation

#define LONG_MAX   2147483647L

Definition at line 42 of file timelib.h.

#define LONG_MIN   (- LONG_MAX - 1)

Definition at line 46 of file timelib.h.

#define TIMELIB_NO_CLONE   0x02

Definition at line 33 of file timelib.h.

#define TIMELIB_NONE   0x00

Definition at line 31 of file timelib.h.

#define TIMELIB_OVERRIDE_TIME   0x01

Definition at line 32 of file timelib.h.

Definition at line 38 of file timelib.h.

Definition at line 39 of file timelib.h.

#define TIMELIB_SPECIAL_WEEKDAY   0x01

Definition at line 37 of file timelib.h.

#define TIMELIB_UNSET   -99999

Definition at line 35 of file timelib.h.

#define TIMELIB_VERSION   201102

Definition at line 29 of file timelib.h.


Typedef Documentation

typedef timelib_tzinfo*(* timelib_tz_get_wrapper)(char *tzname, const timelib_tzdb *tzdb)

Definition at line 58 of file timelib.h.


Function Documentation

int timelib_apply_localtime ( timelib_time t,
unsigned int  localtime 
)

Definition at line 245 of file unixtime2tm.c.

{
       if (localtime) {
              /* Converting from GMT time to local time */
              TIMELIB_DEBUG(printf("Converting from GMT time to local time\n"););

              /* Check if TZ is set */
              if (!t->tz_info) {
                     TIMELIB_DEBUG(printf("E: No timezone configured, can't switch to local time\n"););
                     return -1;
              }

              timelib_unixtime2local(t, t->sse);
       } else {
              /* Converting from local time to GMT time */
              TIMELIB_DEBUG(printf("Converting from local time to GMT time\n"););

              timelib_unixtime2gmt(t, t->sse);
       }
       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int timelib_astro_rise_set_altitude ( timelib_time t_loc,
double  lon,
double  lat,
double  altit,
int  upper_limb,
double *  h_rise,
double *  h_set,
timelib_sll ts_rise,
timelib_sll ts_set,
timelib_sll ts_transit 
)

Note: timestamp = unixtimestamp (NEEDS to be 00:00:00 UT) Eastern longitude positive, Western longitude negative Northern latitude positive, Southern latitude negative The longitude value IS critical in this function! altit = the altitude which the Sun should cross Set to -35/60 degrees for rise/set, -6 degrees for civil, -12 degrees for nautical and -18 degrees for astronomical twilight.

    upper_limb: non-zero -> upper limb, zero -> center         
          Set to non-zero (e.g. 1) when computing rise/set     
          times, and to zero when computing start/end of       
          twilight.                                            
   *rise = where to store the rise time                        
   *set  = where to store the set  time                        
           Both times are relative to the specified altitude,  
           and thus this function can be used to compute       
           various twilight times, as well as rise/set times   

Return value: 0 = sun rises/sets this day, times stored at *trise and *tset. +1 = sun above the specified "horizon" 24 hours. *trise set to time when the sun is at south, minus 12 hours while *tset is set to the south time plus 12 hours. "Day" length = 24 hours -1 = sun is below the specified "horizon" 24 hours "Day" length = 0 hours, *trise and *tset are both set to the time when the sun is at south.

Definition at line 207 of file astro.c.

{
       double  d,  /* Days since 2000 Jan 0.0 (negative before) */
       sr,         /* Solar distance, astronomical units */
       sRA,        /* Sun's Right Ascension */
       sdec,       /* Sun's declination */
       sradius,    /* Sun's apparent radius */
       t,          /* Diurnal arc */
       tsouth,     /* Time when Sun is at south */
       sidtime;    /* Local sidereal time */
       timelib_time *t_utc;
       timelib_sll   timestamp, old_sse;

       int rc = 0; /* Return cde from function - usually 0 */

       /* Normalize time */
       old_sse = t_loc->sse;
       t_loc->h = 12;
       t_loc->i = t_loc->s = 0;
       timelib_update_ts(t_loc, NULL);

       /* Calculate TS belonging to UTC 00:00 of the current day */
       t_utc = timelib_time_ctor();
       t_utc->y = t_loc->y;
       t_utc->m = t_loc->m;
       t_utc->d = t_loc->d;
       t_utc->h = t_utc->i = t_utc->s = 0;
       timelib_update_ts(t_utc, NULL);

       /* Compute d of 12h local mean solar time */
       timestamp = t_loc->sse;
       d = timelib_ts_to_juliandate(timestamp) - lon/360.0;

       /* Compute local sidereal time of this moment */
       sidtime = astro_revolution(astro_GMST0(d) + 180.0 + lon);

       /* Compute Sun's RA + Decl at this moment */
       astro_sun_RA_dec( d, &sRA, &sdec, &sr );

       /* Compute time when Sun is at south - in hours UT */
       tsouth = 12.0 - astro_rev180(sidtime - sRA) / 15.0;

       /* Compute the Sun's apparent radius, degrees */
       sradius = 0.2666 / sr;

       /* Do correction to upper limb, if necessary */
       if (upper_limb) {
              altit -= sradius;
       }

       /* Compute the diurnal arc that the Sun traverses to reach */
       /* the specified altitude altit: */
       {
              double cost;
              cost = (sind(altit) - sind(lat) * sind(sdec)) / (cosd(lat) * cosd(sdec));
              *ts_transit = t_utc->sse + (tsouth * 3600);
              if (cost >= 1.0) {
                     rc = -1;
                     t = 0.0;       /* Sun always below altit */

                     *ts_rise = *ts_set = t_utc->sse + (tsouth * 3600);
              } else if (cost <= -1.0) {
                     rc = +1;
                     t = 12.0;      /* Sun always above altit */

                     *ts_rise = t_loc->sse - (12 * 3600);
                     *ts_set  = t_loc->sse + (12 * 3600);
              } else {
                     t = acosd(cost) / 15.0;   /* The diurnal arc, hours */

                     /* Store rise and set times - as Unix Timestamp */
                     *ts_rise = ((tsouth - t) * 3600) + t_utc->sse;
                     *ts_set  = ((tsouth + t) * 3600) + t_utc->sse;

                     *h_rise = (tsouth - t);
                     *h_set  = (tsouth + t);
              }
       }

       /* Kill temporary time and restore original sse */
       timelib_time_dtor(t_utc);
       t_loc->sse = old_sse;

       return rc;
}

Here is the call graph for this function:

Here is the caller graph for this function:

const timelib_tzdb* timelib_builtin_db ( void  )

Definition at line 298 of file parse_tz.c.

{
       return &timezonedb_builtin;
}

Here is the caller graph for this function:

signed long timelib_date_to_int ( timelib_time d,
int error 
)

Definition at line 177 of file timelib.c.

{
       timelib_sll ts;

       ts = d->sse;

       if (ts < LONG_MIN || ts > LONG_MAX) {
              if (error) {
                     *error = 1;
              }
              return 0;
       }
       if (error) {
              *error = 0;
       }
       return (signed long) d->sse;
}

Here is the caller graph for this function:

Definition at line 56 of file dow.c.

{
       return timelib_day_of_week_ex(y, m, d, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 72 of file dow.c.

{
       return (timelib_is_leap(y) ? d_table_leap[m] : d_table_common[m]) + d - 1;
}

Here is the caller graph for this function:

Definition at line 130 of file dow.c.

{
       timelib_sll dow, day;
       
       /* Figure out the dayofweek for y-1-1 */
       dow = timelib_day_of_week(y, 1, 1);
       /* then use that to figure out the offset for day 1 of week 1 */
       day = 0 - (dow > 4 ? dow - 7 : dow);

       /* Add weeks and days */
       return day + ((w - 1) * 7) + d;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file dow.c.

Here is the caller graph for this function:

void timelib_decimal_hour_to_hms ( double  h,
int hour,
int min,
int sec 
)

Definition at line 195 of file timelib.c.

{
       *hour = floor(h);
       *min =  floor((h - *hour) * 60);
       *sec =  (h - *hour - ((float) *min / 60)) * 3600;
}

Definition at line 24 of file interval.c.

{
       timelib_rel_time *rt;
       timelib_time *swp;
       timelib_sll dst_h_corr = 0, dst_m_corr = 0;
       timelib_time one_backup, two_backup;

       rt = timelib_rel_time_ctor();
       rt->invert = 0;
       if (one->sse > two->sse) {
              swp = two;
              two = one;
              one = swp;
              rt->invert = 1;
       }

       /* Calculate correction for DST change over, but only if the TZ type is ID
        * and it's the same */
       if (one->zone_type == 3 && two->zone_type == 3
              && (strcmp(one->tz_info->name, two->tz_info->name) == 0)
              && (one->z != two->z))
       {
              dst_h_corr = (two->z - one->z) / 3600;
              dst_m_corr = ((two->z - one->z) % 3600) / 60;
       }

       /* Save old TZ info */
       memcpy(&one_backup, one, sizeof(one_backup));
       memcpy(&two_backup, two, sizeof(two_backup));

    timelib_apply_localtime(one, 0);
    timelib_apply_localtime(two, 0);

       rt->y = two->y - one->y;
       rt->m = two->m - one->m;
       rt->d = two->d - one->d;
       rt->h = two->h - one->h + dst_h_corr;
       rt->i = two->i - one->i + dst_m_corr;
       rt->s = two->s - one->s;
       rt->days = abs(floor((one->sse - two->sse - (dst_h_corr * 3600) - (dst_m_corr * 60)) / 86400));

       timelib_do_rel_normalize(rt->invert ? one : two, rt);

       /* Restore old TZ info */
       memcpy(one, &one_backup, sizeof(one_backup));
       memcpy(two, &two_backup, sizeof(two_backup));

       return rt;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 182 of file tm2unixtime.c.

{
       if (time->s != TIMELIB_UNSET) do {} while (do_range_limit(0, 60, 60, &time->s, &time->i));
       if (time->s != TIMELIB_UNSET) do {} while (do_range_limit(0, 60, 60, &time->i, &time->h));
       if (time->s != TIMELIB_UNSET) do {} while (do_range_limit(0, 24, 24, &time->h, &time->d));
       do {} while (do_range_limit(1, 13, 12, &time->m, &time->y));

       do {} while (do_range_limit_days(&time->y, &time->m, &time->d));
       do {} while (do_range_limit(1, 13, 12, &time->m, &time->y));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 171 of file tm2unixtime.c.

{
       do {} while (do_range_limit(0, 60, 60, &rt->s, &rt->i));
       do {} while (do_range_limit(0, 60, 60, &rt->i, &rt->h));
       do {} while (do_range_limit(0, 24, 24, &rt->h, &rt->d));
       do {} while (do_range_limit(0, 12, 12, &rt->m, &rt->y));

       do_range_limit_days_relative(&base->y, &base->m, &rt->y, &rt->m, &rt->d, rt->invert);
       do {} while (do_range_limit(0, 12, 12, &rt->m, &rt->y));
}

Here is the call graph for this function:

Here is the caller graph for this function:

void timelib_dump_date ( timelib_time d,
int  options 
)

Definition at line 202 of file timelib.c.

{
       if ((options & 2) == 2) {
              printf("TYPE: %d ", d->zone_type);
       }
       printf("TS: %lld | %s%04lld-%02lld-%02lld %02lld:%02lld:%02lld",
              d->sse, d->y < 0 ? "-" : "", TIMELIB_LLABS(d->y), d->m, d->d, d->h, d->i, d->s);
       if (d->f > +0.0) {
              printf(" %.5f", d->f);
       }

       if (d->is_localtime) {
              switch (d->zone_type) {
                     case TIMELIB_ZONETYPE_OFFSET: /* Only offset */
                            printf(" GMT %05d%s", d->z, d->dst == 1 ? " (DST)" : "");
                            break;
                     case TIMELIB_ZONETYPE_ID: /* Timezone struct */
                            /* Show abbreviation if wanted */
                            if (d->tz_abbr) {
                                   printf(" %s", d->tz_abbr);
                            }
                            /* Do we have a TimeZone struct? */
                            if (d->tz_info) {
                                   printf(" %s", d->tz_info->name);
                            }
                            break;
                     case TIMELIB_ZONETYPE_ABBR:
                            printf(" %s", d->tz_abbr);
                            printf(" %05d%s", d->z, d->dst == 1 ? " (DST)" : "");
                            break;
              }
       }

       if ((options & 1) == 1) {
              if (d->have_relative) {
                     printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS", 
                            d->relative.y, d->relative.m, d->relative.d, d->relative.h, d->relative.i, d->relative.s);
                     if (d->relative.first_last_day_of != 0) {
                            switch (d->relative.first_last_day_of) {
                                   case 1:
                                          printf(" / first day of");
                                          break;
                                   case 2:
                                          printf(" / last day of");
                                          break;
                            }
                     }
                     if (d->relative.have_weekday_relative) {
                            printf(" / %d.%d", d->relative.weekday, d->relative.weekday_behavior);
                     }
                     if (d->relative.have_special_relative) {
                            switch (d->relative.special.type) {
                                   case TIMELIB_SPECIAL_WEEKDAY:
                                          printf(" / %lld weekday", d->relative.special.amount);
                                          break;
                                   case TIMELIB_SPECIAL_DAY_OF_WEEK_IN_MONTH:
                                          printf(" / x y of z month");
                                          break;
                                   case TIMELIB_SPECIAL_LAST_DAY_OF_WEEK_IN_MONTH:
                                          printf(" / last y of z month");
                                          break;
                            }
                     }
              }
       }
       printf("\n");
}

Definition at line 270 of file timelib.c.

{
       printf("%3lldY %3lldM %3lldD / %3lldH %3lldM %3lldS (days: %lld)%s", 
              d->y, d->m, d->d, d->h, d->i, d->s, d->days, d->invert ? " inverted" : "");
       if (d->first_last_day_of != 0) {
              switch (d->first_last_day_of) {
                     case 1:
                            printf(" / first day of");
                            break;
                     case 2:
                            printf(" / last day of");
                            break;
              }
       }
       printf("\n");
}

Definition at line 216 of file parse_tz.c.

{
       uint32_t i;

       printf("Country Code:      %s\n", tz->location.country_code);
       printf("Geo Location:      %f,%f\n", tz->location.latitude, tz->location.longitude);
       printf("Comments:\n%s\n",          tz->location.comments);
       printf("BC:                %s\n",  tz->bc ? "" : "yes");
       printf("UTC/Local count:   %lu\n", (unsigned long) tz->ttisgmtcnt);
       printf("Std/Wall count:    %lu\n", (unsigned long) tz->ttisstdcnt);
       printf("Leap.sec. count:   %lu\n", (unsigned long) tz->leapcnt);
       printf("Trans. count:      %lu\n", (unsigned long) tz->timecnt);
       printf("Local types count: %lu\n", (unsigned long) tz->typecnt);
       printf("Zone Abbr. count:  %lu\n", (unsigned long) tz->charcnt);

       printf ("%8s (%12s) = %3d [%5ld %1d %3d '%s' (%d,%d)]\n",
              "", "", 0,
              (long int) tz->type[0].offset,
              tz->type[0].isdst,
              tz->type[0].abbr_idx,
              &tz->timezone_abbr[tz->type[0].abbr_idx],
              tz->type[0].isstdcnt,
              tz->type[0].isgmtcnt
              );
       for (i = 0; i < tz->timecnt; i++) {
              printf ("%08X (%12d) = %3d [%5ld %1d %3d '%s' (%d,%d)]\n",
                     tz->trans[i], tz->trans[i], tz->trans_idx[i],
                     (long int) tz->type[tz->trans_idx[i]].offset,
                     tz->type[tz->trans_idx[i]].isdst,
                     tz->type[tz->trans_idx[i]].abbr_idx,
                     &tz->timezone_abbr[tz->type[tz->trans_idx[i]].abbr_idx],
                     tz->type[tz->trans_idx[i]].isstdcnt,
                     tz->type[tz->trans_idx[i]].isgmtcnt
                     );
       }
       for (i = 0; i < tz->leapcnt; i++) {
              printf ("%08X (%12ld) = %d\n",
                     tz->leap_times[i].trans,
                     (long) tz->leap_times[i].trans,
                     tz->leap_times[i].offset);
       }
}

Definition at line 162 of file timelib.c.

{
       int i;

       for (i = 0; i < errors->warning_count; i++) {
              free(errors->warning_messages[i].message);
       }
       free(errors->warning_messages);
       for (i = 0; i < errors->error_count; i++) {
              free(errors->error_messages[i].message);
       }
       free(errors->error_messages);
       free(errors);
}

Here is the caller graph for this function:

void timelib_fill_holes ( timelib_time parsed,
timelib_time now,
int  options 
)

Definition at line 25115 of file parse_date.c.

{
       if (!(options & TIMELIB_OVERRIDE_TIME) && parsed->have_date && !parsed->have_time) {
              parsed->h = 0;
              parsed->i = 0;
              parsed->s = 0;
              parsed->f = 0;
       }
       if (parsed->y == TIMELIB_UNSET) parsed->y = now->y != TIMELIB_UNSET ? now->y : 0;
       if (parsed->d == TIMELIB_UNSET) parsed->d = now->d != TIMELIB_UNSET ? now->d : 0;
       if (parsed->m == TIMELIB_UNSET) parsed->m = now->m != TIMELIB_UNSET ? now->m : 0;
       if (parsed->h == TIMELIB_UNSET) parsed->h = now->h != TIMELIB_UNSET ? now->h : 0;
       if (parsed->i == TIMELIB_UNSET) parsed->i = now->i != TIMELIB_UNSET ? now->i : 0;
       if (parsed->s == TIMELIB_UNSET) parsed->s = now->s != TIMELIB_UNSET ? now->s : 0;
       if (parsed->f == TIMELIB_UNSET) parsed->f = now->f != TIMELIB_UNSET ? now->f : 0;
       if (parsed->z == TIMELIB_UNSET) parsed->z = now->z != TIMELIB_UNSET ? now->z : 0;
       if (parsed->dst == TIMELIB_UNSET) parsed->dst = now->dst != TIMELIB_UNSET ? now->dst : 0;

       if (!parsed->tz_abbr) {
              parsed->tz_abbr = now->tz_abbr ? strdup(now->tz_abbr) : NULL;
       }
       if (!parsed->tz_info) {
              parsed->tz_info = now->tz_info ? (!(options & TIMELIB_NO_CLONE) ? timelib_tzinfo_clone(now->tz_info) : now->tz_info) : NULL;
       }
       if (parsed->zone_type == 0 && now->zone_type != 0) {
              parsed->zone_type = now->zone_type;
/*            parsed->tz_abbr = now->tz_abbr ? strdup(now->tz_abbr) : NULL;
              parsed->tz_info = now->tz_info ? timelib_tzinfo_clone(now->tz_info) : NULL;
*/            parsed->is_localtime = 1;
       }
/*     timelib_dump_date(parsed, 2);
       timelib_dump_date(now, 2);
*/
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 438 of file parse_tz.c.

{
       timelib_time_offset *gmt_offset;
       timelib_sll retval;
                     
       switch (t->zone_type) {
              case TIMELIB_ZONETYPE_ABBR:
              case TIMELIB_ZONETYPE_OFFSET:
                     return (t->z + t->dst) * -60;
                     
              case TIMELIB_ZONETYPE_ID:
                     gmt_offset = timelib_get_time_zone_info(t->sse, t->tz_info);
                     retval = gmt_offset->offset;
                     timelib_time_offset_dtor(gmt_offset);
                     return retval;

              default:
                     return 0;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 406 of file parse_tz.c.

{
       ttinfo *to;
       tlinfo *tl;
       int32_t offset = 0, leap_secs = 0;
       char *abbr;
       timelib_time_offset *tmp = timelib_time_offset_ctor();
       timelib_sll                transistion_time;

       if ((to = fetch_timezone_offset(tz, ts, &transistion_time))) {
              offset = to->offset;
              abbr = &(tz->timezone_abbr[to->abbr_idx]);
              tmp->is_dst = to->isdst;
              tmp->transistion_time = transistion_time;
       } else {
              offset = 0;
              abbr = tz->timezone_abbr;
              tmp->is_dst = 0;
              tmp->transistion_time = 0;
       }

       if ((tl = fetch_leaptime_offset(tz, ts))) {
              leap_secs = -tl->offset;
       }

       tmp->offset = offset;
       tmp->leap_secs = leap_secs;
       tmp->abbr = abbr ? strdup(abbr) : strdup("GMT");

       return tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 61 of file dow.c.

{
       return timelib_day_of_week_ex(y, m, d, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 82 of file dow.c.

{
       int y_leap, prev_y_leap, doy, jan1weekday, weekday;

       y_leap = timelib_is_leap(y);
       prev_y_leap = timelib_is_leap(y-1);
       doy = timelib_day_of_year(y, m, d) + 1;
       if (y_leap && m > 2) {
              doy++;
       }
       jan1weekday = timelib_day_of_week(y, 1, 1);
       weekday = timelib_day_of_week(y, m, d);
       if (weekday == 0) weekday = 7;
       if (jan1weekday == 0) jan1weekday = 7;
       /* Find if Y M D falls in YearNumber Y-1, WeekNumber 52 or 53 */
       if (doy <= (8 - jan1weekday) && jan1weekday > 4) {
              *iy = y - 1;
              if (jan1weekday == 5 || (jan1weekday == 6 && prev_y_leap)) {
                     *iw = 53;
              } else {
                     *iw = 52;
              }
       } else {
              *iy = y;
       }
       /* 8. Find if Y M D falls in YearNumber Y+1, WeekNumber 1 */
       if (*iy == y) {
              int i;

              i = y_leap ? 366 : 365;
              if ((i - (doy - y_leap)) < (4 - weekday)) {
                     *iy = y + 1;
                     *iw = 1;
                     return;
              }
       }
       /* 9. Find if Y M D falls in YearNumber Y, WeekNumber 1 through 53 */
       if (*iy == y) {
              int j;

              j = doy + (7 - weekday) + (jan1weekday - 1);
              *iw = j / 7;
              if (jan1weekday > 4) {
                     *iw -= 1;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

timelib_time* timelib_parse_from_format ( char *  format,
char *  s,
int  len,
timelib_error_container **  errors,
const timelib_tzdb tzdb,
timelib_tz_get_wrapper  tz_get_wrapper 
)

Definition at line 24785 of file parse_date.c.

{
       char       *fptr = format;
       char       *ptr = string;
       char       *begin;
       timelib_sll tmp;
       Scanner in;
       Scanner *s = &in;
       int allow_extra = 0;

       memset(&in, 0, sizeof(in));
       in.errors = malloc(sizeof(struct timelib_error_container));
       in.errors->warning_count = 0;
       in.errors->warning_messages = NULL;
       in.errors->error_count = 0;
       in.errors->error_messages = NULL;

       in.time = timelib_time_ctor();
       in.time->y = TIMELIB_UNSET;
       in.time->d = TIMELIB_UNSET;
       in.time->m = TIMELIB_UNSET;
       in.time->h = TIMELIB_UNSET;
       in.time->i = TIMELIB_UNSET;
       in.time->s = TIMELIB_UNSET;
       in.time->f = TIMELIB_UNSET;
       in.time->z = TIMELIB_UNSET;
       in.time->dst = TIMELIB_UNSET;
       in.tzdb = tzdb;
       in.time->is_localtime = 0;
       in.time->zone_type = 0;

       /* Loop over the format string */
       while (*fptr && *ptr) {
              begin = ptr;
              switch (*fptr) {
                     case 'D': /* three letter day */
                     case 'l': /* full day */
                            {
                                   const timelib_relunit* tmprel = 0;

                                   tmprel = timelib_lookup_relunit((char **) &ptr);
                                   if (!tmprel) {
                                          add_pbf_error(s, "A textual day could not be found", string, begin);
                                          break;
                                   } else {
                                          in.time->have_relative = 1; 
                                          in.time->relative.have_weekday_relative = 1;
                                          in.time->relative.weekday = tmprel->multiplier;
                                          in.time->relative.weekday_behavior = 1;
                                   }
                            }
                            break;
                     case 'd': /* two digit day, with leading zero */
                     case 'j': /* two digit day, without leading zero */
                            TIMELIB_CHECK_NUMBER;
                            if ((s->time->d = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A two digit day could not be found", string, begin);
                            }
                            break;
                     case 'S': /* day suffix, ignored, nor checked */
                            timelib_skip_day_suffix((char **) &ptr);
                            break;
                     case 'z': /* day of year - resets month (0 based) - also initializes everything else to !TIMELIB_UNSET */
                            TIMELIB_CHECK_NUMBER;
                            if ((tmp = timelib_get_nr((char **) &ptr, 3)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A three digit day-of-year could not be found", string, begin);
                            } else {
                                   s->time->m = 1;
                                   s->time->d = tmp + 1;
                                   timelib_do_normalize(s->time);
                            }
                            break;

                     case 'm': /* two digit month, with leading zero */
                     case 'n': /* two digit month, without leading zero */
                            TIMELIB_CHECK_NUMBER;
                            if ((s->time->m = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A two digit month could not be found", string, begin);
                            }
                            break;
                     case 'M': /* three letter month */
                     case 'F': /* full month */
                            tmp = timelib_lookup_month((char **) &ptr);
                            if (!tmp) {
                                   add_pbf_error(s, "A textual month could not be found", string, begin);
                            } else {
                                   s->time->m = tmp;
                            }
                            break;
                     case 'y': /* two digit year */
                            {
                                   int length = 0;
                                   TIMELIB_CHECK_NUMBER;
                                   if ((s->time->y = timelib_get_nr_ex((char **) &ptr, 2, &length)) == TIMELIB_UNSET) {
                                          add_pbf_error(s, "A two digit year could not be found", string, begin);
                                   }
                                   TIMELIB_PROCESS_YEAR(s->time->y, length);
                            }
                            break;
                     case 'Y': /* four digit year */
                            TIMELIB_CHECK_NUMBER;
                            if ((s->time->y = timelib_get_nr((char **) &ptr, 4)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A four digit year could not be found", string, begin);
                            }
                            break;
                     case 'g': /* two digit hour, with leading zero */
                     case 'h': /* two digit hour, without leading zero */
                            TIMELIB_CHECK_NUMBER;
                            if ((s->time->h = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A two digit hour could not be found", string, begin);
                            }
                            if (s->time->h > 12) {
                                   add_pbf_error(s, "Hour can not be higher than 12", string, begin);
                            }
                            break;
                     case 'G': /* two digit hour, with leading zero */
                     case 'H': /* two digit hour, without leading zero */
                            TIMELIB_CHECK_NUMBER;
                            if ((s->time->h = timelib_get_nr((char **) &ptr, 2)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A two digit hour could not be found", string, begin);
                            }
                            break;
                     case 'a': /* am/pm/a.m./p.m. */
                     case 'A': /* AM/PM/A.M./P.M. */
                            if (s->time->h == TIMELIB_UNSET) {
                                   add_pbf_error(s, "Meridian can only come after an hour has been found", string, begin);
                            } else if ((tmp = timelib_meridian_with_check((char **) &ptr, s->time->h)) == TIMELIB_UNSET) {
                                   add_pbf_error(s, "A meridian could not be found", string, begin);
                            } else {
                                   s->time->h += tmp;
                            }
                            break;
                     case 'i': /* two digit minute, with leading zero */
                            {
                                   int length;
                                   timelib_sll min;

                                   TIMELIB_CHECK_NUMBER;
                                   min = timelib_get_nr_ex((char **) &ptr, 2, &length);
                                   if (min == TIMELIB_UNSET || length != 2) {
                                          add_pbf_error(s, "A two digit minute could not be found", string, begin);
                                   } else {
                                          s->time->i = min;
                                   }
                            }
                            break;
                     case 's': /* two digit second, with leading zero */
                            {
                                   int length;
                                   timelib_sll sec;

                                   TIMELIB_CHECK_NUMBER;
                                   sec = timelib_get_nr_ex((char **) &ptr, 2, &length);
                                   if (sec == TIMELIB_UNSET || length != 2) {
                                          add_pbf_error(s, "A two second minute could not be found", string, begin);
                                   } else {
                                          s->time->s = sec;
                                   }
                            }
                            break;
                     case 'u': /* up to six digit millisecond */
                            {
                                   double f;
                                   char *tptr;

                                   TIMELIB_CHECK_NUMBER;
                                   tptr = ptr;
                                   if ((f = timelib_get_nr((char **) &ptr, 6)) == TIMELIB_UNSET || (ptr - tptr < 1)) {
                                          add_pbf_error(s, "A six digit millisecond could not be found", string, begin);
                                   } else {
                                          s->time->f = (f / pow(10, (ptr - tptr)));
                                   }
                            }
                            break;
                     case ' ': /* any sort of whitespace (' ' and \t) */
                            timelib_eat_spaces((char **) &ptr);
                            break;
                     case 'U': /* epoch seconds */
                            TIMELIB_CHECK_NUMBER;
                            TIMELIB_HAVE_RELATIVE();
                            tmp = timelib_get_unsigned_nr((char **) &ptr, 24);
                            s->time->y = 1970;
                            s->time->m = 1;
                            s->time->d = 1;
                            s->time->h = s->time->i = s->time->s = 0;
                            s->time->f = 0.0;
                            s->time->relative.s += tmp;
                            s->time->is_localtime = 1;
                            s->time->zone_type = TIMELIB_ZONETYPE_OFFSET;
                            s->time->z = 0;
                            break;

                     case 'e': /* timezone */
                     case 'P': /* timezone */
                     case 'T': /* timezone */
                     case 'O': /* timezone */
                            {
                                   int tz_not_found;
                                   s->time->z = timelib_get_zone((char **) &ptr, &s->time->dst, s->time, &tz_not_found, s->tzdb, tz_get_wrapper);
                                   if (tz_not_found) {
                                          add_pbf_error(s, "The timezone could not be found in the database", string, begin);
                                   }
                            }
                            break;

                     case '#': /* separation symbol */
                            if (*ptr == ';' || *ptr == ':' || *ptr == '/' || *ptr == '.' || *ptr == ',' || *ptr == '-' || *ptr == '(' || *ptr == ')') {
                                   ++ptr;
                            } else {
                                   add_pbf_error(s, "The separation symbol ([;:/.,-]) could not be found", string, begin);
                            }
                            break;

                     case ';':
                     case ':':
                     case '/':
                     case '.':
                     case ',':
                     case '-':
                     case '(':
                     case ')':
                            if (*ptr == *fptr) {
                                   ++ptr;
                            } else {
                                   add_pbf_error(s, "The separation symbol could not be found", string, begin);
                            }
                            break;

                     case '!': /* reset all fields to default */
                            timelib_time_reset_fields(s->time);
                            break; /* break intentionally not missing */

                     case '|': /* reset all fields to default when not set */
                            timelib_time_reset_unset_fields(s->time);
                            break; /* break intentionally not missing */

                     case '?': /* random char */
                            ++ptr;
                            break;

                     case '\\': /* escaped char */
                            *fptr++;
                            if (*ptr == *fptr) {
                                   ++ptr;
                            } else {
                                   add_pbf_error(s, "The escaped character could not be found", string, begin);
                            }
                            break;

                     case '*': /* random chars until a separator or number ([ \t.,:;/-0123456789]) */
                            timelib_eat_until_separator((char **) &ptr);
                            break;

                     case '+': /* allow extra chars in the format */
                            allow_extra = 1;
                            break;

                     default:
                            if (*fptr != *ptr) {
                                   add_pbf_error(s, "The format separator does not match", string, begin);
                            }
                            ptr++;
              }
              fptr++;
       }
       if (*ptr) {
              if (allow_extra) {
                     add_pbf_warning(s, "Trailing data", string, ptr);
              } else {
                     add_pbf_error(s, "Trailing data", string, ptr);
              }
       }
       /* ignore trailing +'s */
       while (*fptr == '+') {
              fptr++;
       }
       if (*fptr) {
              /* Trailing | and ! specifiers are valid. */
              int done = 0;
              while (*fptr && !done) {
                     switch (*fptr++) {
                            case '!': /* reset all fields to default */
                                   timelib_time_reset_fields(s->time);
                                   break;

                            case '|': /* reset all fields to default when not set */
                                   timelib_time_reset_unset_fields(s->time);
                                   break;

                            default:
                                   add_pbf_error(s, "Data missing", string, ptr);
                                   done = 1;
                     }
              }
       }

       /* clean up a bit */
       if (s->time->h != TIMELIB_UNSET || s->time->i != TIMELIB_UNSET || s->time->s != TIMELIB_UNSET) {
              if (s->time->h == TIMELIB_UNSET ) {
                     s->time->h = 0;
              }
              if (s->time->i == TIMELIB_UNSET ) {
                     s->time->i = 0;
              }
              if (s->time->s == TIMELIB_UNSET ) {
                     s->time->s = 0;
              }
       }

       /* do funky checking whether the parsed time was valid time */
       if (s->time->h != TIMELIB_UNSET && s->time->i != TIMELIB_UNSET &&
              s->time->s != TIMELIB_UNSET && 
              !timelib_valid_time( s->time->h, s->time->i, s->time->s)) {
              add_pbf_warning(s, "The parsed time was invalid", string, ptr);
       }
       /* do funky checking whether the parsed date was valid date */
       if (s->time->y != TIMELIB_UNSET && s->time->m != TIMELIB_UNSET &&
              s->time->d != TIMELIB_UNSET && 
              !timelib_valid_date( s->time->y, s->time->m, s->time->d)) {
              add_pbf_warning(s, "The parsed date was invalid", string, ptr);
       }

       if (errors) {
              *errors = in.errors;
       } else {
              timelib_error_container_dtor(in.errors);
       }
       return in.time;
}

Here is the call graph for this function:

Here is the caller graph for this function:

timelib_tzinfo* timelib_parse_tzfile ( char *  timezone,
const timelib_tzdb tzdb 
)

Definition at line 315 of file parse_tz.c.

{
       const unsigned char *tzf;
       timelib_tzinfo *tmp;

       if (seek_to_tz_position(&tzf, timezone, tzdb)) {
              tmp = timelib_tzinfo_ctor(timezone);

              read_preamble(&tzf, tmp);
              read_header(&tzf, tmp);
              read_transistions(&tzf, tmp);
              read_types(&tzf, tmp);
              read_location(&tzf, tmp);
       } else {
              tmp = NULL;
       }

       return tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 62 of file timelib.c.

{
       timelib_rel_time *tmp = timelib_rel_time_ctor();
       memcpy(tmp, rel, sizeof(timelib_rel_time));
       return tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 41 of file timelib.c.

{
       timelib_rel_time *t;
       t = calloc(1, sizeof(timelib_rel_time));

       return t;
}

Here is the caller graph for this function:

Definition at line 86 of file timelib.c.

Here is the caller graph for this function:

Definition at line 218 of file unixtime2tm.c.

{
       timelib_time_offset *gmt_offset;

       gmt_offset = timelib_get_time_zone_info(t->sse, tz);
       t->z = gmt_offset->offset;
/*
       if (t->dst != gmt_offset->is_dst) {
              printf("ERROR (%d, %d)\n", t->dst, gmt_offset->is_dst);
              exit(1);
       }
*/
       t->dst = gmt_offset->is_dst;
       t->tz_info = tz;
       if (t->tz_abbr) {
              free(t->tz_abbr);
       }
       t->tz_abbr = strdup(gmt_offset->abbr);
       timelib_time_offset_dtor(gmt_offset);

       t->have_zone = 1;
       t->zone_type = TIMELIB_ZONETYPE_ID;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void timelib_strtointerval ( char *  s,
int  len,
timelib_time **  begin,
timelib_time **  end,
timelib_rel_time **  period,
int recurrences,
struct timelib_error_container **  errors 
)

Definition at line 1042 of file parse_iso_intervals.c.

{
       Scanner in;
       int t;
       char *e = s + len - 1;

       memset(&in, 0, sizeof(in));
       in.errors = malloc(sizeof(struct timelib_error_container));
       in.errors->warning_count = 0;
       in.errors->warning_messages = NULL;
       in.errors->error_count = 0;
       in.errors->error_messages = NULL;

       if (len > 0) {
              while (isspace(*s) && s < e) {
                     s++;
              }
              while (isspace(*e) && e > s) {
                     e--;
              }
       }
       if (e - s < 0) {
              add_error(&in, "Empty string");
              if (errors) {
                     *errors = in.errors;
              } else {
                     timelib_error_container_dtor(in.errors);
              }
              return;
       }
       e++;

       /* init cursor */
       in.str = malloc((e - s) + YYMAXFILL);
       memset(in.str, 0, (e - s) + YYMAXFILL);
       memcpy(in.str, s, (e - s));
       in.lim = in.str + (e - s) + YYMAXFILL;
       in.cur = in.str;

       /* init value containers */
       in.begin = timelib_time_ctor();
       in.begin->y = TIMELIB_UNSET;
       in.begin->d = TIMELIB_UNSET;
       in.begin->m = TIMELIB_UNSET;
       in.begin->h = TIMELIB_UNSET;
       in.begin->i = TIMELIB_UNSET;
       in.begin->s = TIMELIB_UNSET;
       in.begin->f = 0;
       in.begin->z = 0;
       in.begin->dst = 0;
       in.begin->is_localtime = 0;
       in.begin->zone_type = TIMELIB_ZONETYPE_OFFSET;

       in.end = timelib_time_ctor();
       in.end->y = TIMELIB_UNSET;
       in.end->d = TIMELIB_UNSET;
       in.end->m = TIMELIB_UNSET;
       in.end->h = TIMELIB_UNSET;
       in.end->i = TIMELIB_UNSET;
       in.end->s = TIMELIB_UNSET;
       in.end->f = 0;
       in.end->z = 0;
       in.end->dst = 0;
       in.end->is_localtime = 0;
       in.end->zone_type = TIMELIB_ZONETYPE_OFFSET;

       in.period = timelib_rel_time_ctor();
       in.period->y = 0;
       in.period->d = 0;
       in.period->m = 0;
       in.period->h = 0;
       in.period->i = 0;
       in.period->s = 0;
       in.period->weekday = 0;
       in.period->weekday_behavior = 0;
       in.period->first_last_day_of = 0;
       in.period->days = TIMELIB_UNSET;

       in.recurrences = 1;

       do {
              t = scan(&in);
#ifdef DEBUG_PARSER
              printf("%d\n", t);
#endif
       } while(t != EOI);

       free(in.str);
       if (errors) {
              *errors = in.errors;
       } else {
              timelib_error_container_dtor(in.errors);
       }
       if (in.have_begin_date) {
              *begin = in.begin;
       } else {
              timelib_time_dtor(in.begin);
       }
       if (in.have_end_date) {
              *end   = in.end;
       } else {
              timelib_time_dtor(in.end);
       }
       if (in.have_period) {
              *period = in.period;
       } else {
              timelib_rel_time_dtor(in.period);
       }
       if (in.have_recurrences) {
              *recurrences = in.recurrences;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

timelib_time* timelib_strtotime ( char *  s,
int  len,
timelib_error_container **  errors,
const timelib_tzdb tzdb,
timelib_tz_get_wrapper  tz_get_wrapper 
)

Definition at line 24675 of file parse_date.c.

{
       Scanner in;
       int t;
       char *e = s + len - 1;

       memset(&in, 0, sizeof(in));
       in.errors = malloc(sizeof(struct timelib_error_container));
       in.errors->warning_count = 0;
       in.errors->warning_messages = NULL;
       in.errors->error_count = 0;
       in.errors->error_messages = NULL;

       if (len > 0) {
              while (isspace(*s) && s < e) {
                     s++;
              }
              while (isspace(*e) && e > s) {
                     e--;
              }
       }
       if (e - s < 0) {
              in.time = timelib_time_ctor();
              add_error(&in, "Empty string");
              if (errors) {
                     *errors = in.errors;
              } else {
                     timelib_error_container_dtor(in.errors);
              }
              in.time->y = in.time->d = in.time->m = in.time->h = in.time->i = in.time->s = in.time->f = in.time->dst = in.time->z = TIMELIB_UNSET;
              in.time->is_localtime = in.time->zone_type = 0;
              return in.time;
       }
       e++;

       in.str = malloc((e - s) + YYMAXFILL);
       memset(in.str, 0, (e - s) + YYMAXFILL);
       memcpy(in.str, s, (e - s));
       in.lim = in.str + (e - s) + YYMAXFILL;
       in.cur = in.str;
       in.time = timelib_time_ctor();
       in.time->y = TIMELIB_UNSET;
       in.time->d = TIMELIB_UNSET;
       in.time->m = TIMELIB_UNSET;
       in.time->h = TIMELIB_UNSET;
       in.time->i = TIMELIB_UNSET;
       in.time->s = TIMELIB_UNSET;
       in.time->f = TIMELIB_UNSET;
       in.time->z = TIMELIB_UNSET;
       in.time->dst = TIMELIB_UNSET;
       in.tzdb = tzdb;
       in.time->is_localtime = 0;
       in.time->zone_type = 0;

       do {
              t = scan(&in, tz_get_wrapper);
#ifdef DEBUG_PARSER
              printf("%d\n", t);
#endif
       } while(t != EOI);

       /* do funky checking whether the parsed time was valid time */
       if (in.time->have_time && !timelib_valid_time( in.time->h, in.time->i, in.time->s)) {
              add_warning(&in, "The parsed time was invalid");
       }
       /* do funky checking whether the parsed date was valid date */
       if (in.time->have_date && !timelib_valid_date( in.time->y, in.time->m, in.time->d)) {
              add_warning(&in, "The parsed date was invalid");
       }

       free(in.str);
       if (errors) {
              *errors = in.errors;
       } else {
              timelib_error_container_dtor(in.errors);
       }
       return in.time;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 49 of file timelib.c.

{
       timelib_time *tmp = timelib_time_ctor();
       memcpy(tmp, orig, sizeof(timelib_time));
       if (orig->tz_abbr) {
              tmp->tz_abbr = strdup(orig->tz_abbr);
       }
       if (orig->tz_info) {
              tmp->tz_info = orig->tz_info;
       }
       return tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 33 of file timelib.c.

{
       timelib_time *t;
       t = calloc(1, sizeof(timelib_time));

       return t;
}

Here is the caller graph for this function:

Definition at line 80 of file timelib.c.

Here is the caller graph for this function:

Definition at line 91 of file timelib.c.

{
       timelib_time_offset *t;
       t = calloc(1, sizeof(timelib_time_offset));

       return t;
}

Here is the caller graph for this function:

Definition at line 99 of file timelib.c.

Here is the caller graph for this function:

void timelib_time_set_option ( timelib_time tm,
int  option,
void *  option_value 
)
void timelib_time_tz_abbr_update ( timelib_time tm,
char *  tz_abbr 
)

Definition at line 69 of file timelib.c.

{
       unsigned int i;
       
       TIMELIB_TIME_FREE(tm->tz_abbr);
       tm->tz_abbr = strdup(tz_abbr);
       for (i = 0; i < strlen(tz_abbr); i++) {
              tm->tz_abbr[i] = toupper(tz_abbr[i]);
       }
}

Here is the caller graph for this function:

void timelib_time_tz_name_update ( timelib_time tm,
char *  tz_name 
)

Definition at line 395 of file parse_tz.c.

{
       ttinfo *to;
       timelib_sll dummy;
       
       if ((to = fetch_timezone_offset(tz, ts, &dummy))) {
              return to->isdst;
       }
       return -1;
}

Here is the call graph for this function:

Definition at line 25162 of file parse_date.c.

Here is the caller graph for this function:

Definition at line 303 of file parse_tz.c.

{
       *count = sizeof(timezonedb_idx_builtin) / sizeof(*timezonedb_idx_builtin);
       return timezonedb_idx_builtin;
}
char* timelib_timezone_id_from_abbr ( const char *  abbr,
long  gmtoffset,
int  isdst 
)

Definition at line 25150 of file parse_date.c.

{
       const timelib_tz_lookup_table *tp;

       tp = zone_search(abbr, gmtoffset, isdst);
       if (tp) {
              return (tp->full_tz_name);
       } else {
              return NULL;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int timelib_timezone_id_is_valid ( char *  timezone,
const timelib_tzdb tzdb 
)

Definition at line 309 of file parse_tz.c.

{
       const unsigned char *tzf;
       return (seek_to_tz_position(&tzf, timezone, tzdb));
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 293 of file astro.c.

{
       double tmp;

       tmp = ts;
       tmp /= 86400;
       tmp += 2440587.5;
       tmp -= 2451543;

       return tmp;
}

Here is the caller graph for this function:

Definition at line 114 of file timelib.c.

{
       timelib_tzinfo *tmp = timelib_tzinfo_ctor(tz->name);
       tmp->ttisgmtcnt = tz->ttisgmtcnt;
       tmp->ttisstdcnt = tz->ttisstdcnt;
       tmp->leapcnt = tz->leapcnt;
       tmp->timecnt = tz->timecnt;
       tmp->typecnt = tz->typecnt;
       tmp->charcnt = tz->charcnt;
       
       tmp->trans = (int32_t *) malloc(tz->timecnt * sizeof(int32_t));
       tmp->trans_idx = (unsigned char*) malloc(tz->timecnt * sizeof(unsigned char));
       memcpy(tmp->trans, tz->trans, tz->timecnt * sizeof(int32_t));
       memcpy(tmp->trans_idx, tz->trans_idx, tz->timecnt * sizeof(unsigned char));

       tmp->type = (ttinfo*) malloc(tz->typecnt * sizeof(struct ttinfo));
       memcpy(tmp->type, tz->type, tz->typecnt * sizeof(struct ttinfo));

       tmp->timezone_abbr = (char*) malloc(tz->charcnt);
       memcpy(tmp->timezone_abbr, tz->timezone_abbr, tz->charcnt);

       tmp->leap_times = (tlinfo*) malloc(tz->leapcnt * sizeof(tlinfo));
       memcpy(tmp->leap_times, tz->leap_times, tz->leapcnt * sizeof(tlinfo));

       return tmp;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 105 of file timelib.c.

{
       timelib_tzinfo *t;
       t = calloc(1, sizeof(timelib_tzinfo));
       t->name = strdup(name);

       return t;
}

Here is the caller graph for this function:

Definition at line 141 of file timelib.c.

Here is the caller graph for this function:

Definition at line 40 of file unixtime2tm.c.

{
       timelib_sll days, remainder, tmp_days;
       timelib_sll cur_year = 1970;
       timelib_sll i;
       timelib_sll hours, minutes, seconds;
       int *months;

       days = ts / SECS_PER_DAY;
       remainder = ts - (days * SECS_PER_DAY);
       if (ts < 0 && remainder == 0) {
              days++;
              remainder -= SECS_PER_DAY;
       }
       TIMELIB_DEBUG(printf("days=%lld, rem=%lld\n", days, remainder););

       if (ts >= 0) {
              tmp_days = days + 1;

              if (tmp_days >= DAYS_PER_LYEAR_PERIOD || tmp_days <= -DAYS_PER_LYEAR_PERIOD) {
                     cur_year += YEARS_PER_LYEAR_PERIOD * (tmp_days / DAYS_PER_LYEAR_PERIOD);
                     tmp_days -= DAYS_PER_LYEAR_PERIOD * (tmp_days / DAYS_PER_LYEAR_PERIOD);
              }

              while (tmp_days >= DAYS_PER_LYEAR) {
                     cur_year++;
                     if (timelib_is_leap(cur_year)) {
                            tmp_days -= DAYS_PER_LYEAR;
                     } else {
                            tmp_days -= DAYS_PER_YEAR;
                     }
              }
       } else {
              tmp_days = days;

              /* Guess why this might be for, it has to do with a pope ;-). It's also
               * only valid for Great Brittain and it's colonies. It needs fixing for
               * other locales. *sigh*, why is this crap so complex! */
              /*
              if (ts <= TIMELIB_LL_CONST(-6857352000)) {
                     tmp_days -= 11;
              }
              */

              while (tmp_days <= 0) {
                     if (tmp_days < -1460970) {
                            cur_year -= 4000;
                            TIMELIB_DEBUG(printf("tmp_days=%lld, year=%lld\n", tmp_days, cur_year););
                            tmp_days += 1460970;
                     } else {
                            cur_year--;
                            TIMELIB_DEBUG(printf("tmp_days=%lld, year=%lld\n", tmp_days, cur_year););
                            if (timelib_is_leap(cur_year)) {
                                   tmp_days += DAYS_PER_LYEAR;
                            } else {
                                   tmp_days += DAYS_PER_YEAR;
                            }
                     }
              }
              remainder += SECS_PER_DAY;
       }
       TIMELIB_DEBUG(printf("tmp_days=%lld, year=%lld\n", tmp_days, cur_year););

       months = timelib_is_leap(cur_year) ? month_tab_leap : month_tab;
       if (timelib_is_leap(cur_year) && cur_year < 1970) {
              tmp_days--;
       }
       i = 11;
       while (i > 0) {
              TIMELIB_DEBUG(printf("month=%lld (%d)\n", i, months[i]););
              if (tmp_days > months[i]) {
                     break;
              }
              i--;
       }
       TIMELIB_DEBUG(printf("A: ts=%lld, year=%lld, month=%lld, day=%lld,", ts, cur_year, i + 1, tmp_days - months[i]););

       /* That was the date, now we do the tiiiime */
       hours = remainder / 3600;
       minutes = (remainder - hours * 3600) / 60;
       seconds = remainder % 60;
       TIMELIB_DEBUG(printf(" hour=%lld, minute=%lld, second=%lld\n", hours, minutes, seconds););

       tm->y = cur_year;
       tm->m = i + 1;
       tm->d = tmp_days - months[i];
       tm->h = hours;
       tm->i = minutes;
       tm->s = seconds;
       tm->z = 0;
       tm->dst = 0;
       tm->sse = ts;
       tm->sse_uptodate = 1;
       tm->tim_uptodate = 1;
       tm->is_localtime = 0;
}

Here is the caller graph for this function:

Definition at line 176 of file unixtime2tm.c.

{
       timelib_time_offset *gmt_offset;
       timelib_tzinfo      *tz = tm->tz_info;

       switch (tm->zone_type) {
              case TIMELIB_ZONETYPE_ABBR:
              case TIMELIB_ZONETYPE_OFFSET: {
                     int z = tm->z;
                     signed int dst = tm->dst;
                     
                     timelib_unixtime2gmt(tm, ts - (tm->z * 60) + (tm->dst * 3600));

                     tm->z = z;
                     tm->dst = dst;
                     break;
              }

              case TIMELIB_ZONETYPE_ID:
                     gmt_offset = timelib_get_time_zone_info(ts, tz);
                     timelib_unixtime2gmt(tm, ts + gmt_offset->offset);

                     /* we need to reset the sse here as unixtime2gmt modifies it */
                     tm->sse = ts; 
                     tm->dst = gmt_offset->is_dst;
                     tm->z = gmt_offset->offset;
                     tm->tz_info = tz;

                     timelib_time_tz_abbr_update(tm, gmt_offset->abbr);
                     timelib_time_offset_dtor(gmt_offset);
                     break;

              default:
                     tm->is_localtime = 0;
                     tm->have_zone = 0;
                     return;
       }

       tm->is_localtime = 1;
       tm->have_zone = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 137 of file unixtime2tm.c.

{
       timelib_sll sse;

       sse = tm->sse;
       
       switch (tm->zone_type) {
              case TIMELIB_ZONETYPE_ABBR:
              case TIMELIB_ZONETYPE_OFFSET: {
                     int z = tm->z;
                     signed int dst = tm->dst;
                     
                     timelib_unixtime2gmt(tm, tm->sse - (tm->z * 60) + (tm->dst * 3600));

                     tm->z = z;
                     tm->dst = dst;
                     goto cleanup;
              }

              case TIMELIB_ZONETYPE_ID: {
                     timelib_time_offset *gmt_offset;
                     
                     gmt_offset = timelib_get_time_zone_info(tm->sse, tm->tz_info);
                     timelib_unixtime2gmt(tm, tm->sse + gmt_offset->offset);
                     timelib_time_offset_dtor(gmt_offset);
                     
                     goto cleanup;
              }

              default:
                     timelib_unixtime2gmt(tm, tm->sse);
                     goto cleanup;
       }
cleanup:
       tm->sse = sse;
       tm->is_localtime = 1;
       tm->have_zone = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void timelib_update_ts ( timelib_time time,
timelib_tzinfo tzi 
)

Definition at line 430 of file tm2unixtime.c.

{
       timelib_sll res = 0;

       do_adjust_special_early(time);
       do_adjust_relative(time);
       do_adjust_special(time);
       res += do_years(time->y);
       res += do_months(time->m, time->y);
       res += do_days(time->d);
       res += do_time(time->h, time->i, time->s);
       time->sse = res;

       res += do_adjust_timezone(time, tzi);
       time->sse = res;

       time->sse_uptodate = 1;
       time->have_relative = time->relative.have_weekday_relative = time->relative.have_special_relative = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 151 of file dow.c.

{
       if (m < 1 || m > 12 || d < 1 || d > timelib_days_in_month(y, m)) {
              return 0;
       }
       return 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 143 of file dow.c.

{
       if (h < 0 || h > 23 || i < 0 || i > 59 || s < 0 || s > 59) {
              return 0;
       }
       return 1;
}

Here is the caller graph for this function: