Time management


Detailed Description

Time function handle time calculations and daylight saving time (DST).

DST rules are recorded in the file tzinfo.txt. The file loaded is the first found according the following search sequence:

DST rules are recorded in the Posix-compliant format for the TZ environment variable:

        STZ[hh[:mm][DTZ][,M#[#].#.#/hh:mm,M#[#].#.#/hh:mm]]


Defines

#define DAY   (86400*TS_SECOND)
 the number of ticks in one day
#define HOUR   (3600*TS_SECOND)
 the number of ticks in one hour
#define MICROSECOND   (TS_SECOND/1000000)
 the number of ticks in one microsecond
#define MINUTE   (60*TS_SECOND)
 the number of ticks in one minute
#define SECOND   (TS_SECOND)
 the number of ticks in one second

Typedefs

typedef struct s_datetime DATETIME
 the s_datetime structure

Functions

TIMESTAMP compute_dstevent (int year, SPEC *spec, time_t offset)
 Computes the GMT time of a DST event Offset indicates the time offset to include.
int convert_from_timestamp (TIMESTAMP ts, char *buffer, int size)
 Convert from a timestamp to a string.
TIMESTAMP convert_to_timestamp (char *value)
 Convert from a string to a timestamp.
int isdst (TIMESTAMP t)
 Determine whether a GMT timestamp is under DST rules.
void load_tzspecs (char *tz)
 Load a timezone from the timezone info file.
int local_datetime (TIMESTAMP ts, DATETIME *dt)
 Converts a GMT timestamp to local datetime struct Adjusts to TZ if possible.
int local_tzoffset (TIMESTAMP t)
 Calculate the current TZ offset in seconds.
TIMESTAMP mkdatetime (DATETIME *dt)
 Convert a datetime struct into a GMT timestamp.
void set_tzspec (int year, char *tzname, SPEC *pStart, SPEC *pEnd)
 Apply a timezone spec to the current tz rules.
int strdatetime (DATETIME *t, char *buffer, int size)
 Convert a datetime struct to a string.
char * timestamp_current_timezone (void)
 Read the current timezone specification.
char * timestamp_set_tz (char *tz_name)
 Establish the default timezone for time conversion.
int timestamp_test (void)
 Test the daylight saving time calculations.
int timestamp_year (TIMESTAMP ts, TIMESTAMP *remainder)
 Determine the year of a GMT timestamp Apply remainder if given.
char * tz_dst (char *tzspec)
 Get the std timezone name.
int tz_info (char *tzspec, char *tzname, char *std, char *dst, time_t *offset)
 Extract information from an ISO timezone specification.
char * tz_name (char *tzspec)
 Converts a timezone spec into a standard timezone name Populate tzspec if provided, otherwise returns a static buffer.
time_t tz_offset (char *tzspec)
 Compute the offset of a tz spec.
char * tz_std (char *tzspec)
 Get the std timezone name.


Function Documentation

char * timestamp_current_timezone ( void   ) 

Read the current timezone specification.

Returns:
a pointer to the first character in the timezone spec string

Definition at line 74 of file timestamp.c.

Referenced by cmex_get().

char * timestamp_set_tz ( char *  tz_name  ) 

Establish the default timezone for time conversion.

NULL tzname uses TZ environment for default

Definition at line 647 of file timestamp.c.

References load_tzspecs(), and throw_exception().

Referenced by exec_init().

int timestamp_test ( void   ) 

Test the daylight saving time calculations.

Returns:
the number of test the failed

Definition at line 830 of file timestamp.c.

References convert_from_timestamp(), convert_to_timestamp(), DAY, FMT_INT64, HOUR, local_datetime(), mkdatetime(), output_test(), output_verbose(), SECOND, and strdatetime().

Referenced by cmdarg_load().


GridLAB-DTM Version 2.0
An open-source project initiated by the US Department of Energy