Time management
[GridLAB-D Core]


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]]


Classes

struct  s_datetime

Defines

#define _timezone   timezone
#define _tzname   tzname
#define DAY   (86400*TS_SECOND)
 the number of ticks in one day
#define DOW0   (4)
#define GMTIME(T)   ((T)+tzoffset-(isdst((T)+tzoffset)?3600:0))
#define HOUR   (3600*TS_SECOND)
 the number of ticks in one hour
#define ISLEAPYEAR(Y)   ((Y)%4==0 && ((Y)%100!=0 || (Y)%400==0))
#define LOCALTIME(T)   ((T)-tzoffset+(isdst((T))?3600:0))
#define MAXYEAR   2969
#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 MINYEAR   1970
#define NORMALRES
#define SECOND   (TS_SECOND)
 the number of ticks in one second
#define TS_INVALID   ((int64)-1)
#define TS_MAX   (32482080000LL)
#define TS_NEVER   ((int64)(((unsigned int64)-1)>>1))
#define TS_RESOLUTION   (1)
#define TS_SCALE   (0)
#define TS_SECOND   ((int64)1)
#define TS_ZERO   ((int64)0)
#define TZFILE   "tzinfo.txt"
#define YEAR0   (1970)
#define YEAR0_ISLY   (0)

Typedefs

typedef s_datetime DATETIME
 the s_datetime structure
typedef int64 TIMESTAMP

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.
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.
double timestamp_to_days (TIMESTAMP t)
double timestamp_to_hours (TIMESTAMP t)
double timestamp_to_minutes (TIMESTAMP t)
double timestamp_to_seconds (TIMESTAMP t)
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 70 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 430 of file timestamp.c.

References _timezone, _tzname, 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 571 of file timestamp.c.

References convert_from_timestamp(), convert_to_timestamp(), DAY, FMT_INT64, HOUR, s_datetime::is_dst, local_datetime(), mkdatetime(), output_debug(), output_test(), output_verbose(), SECOND, strdatetime(), TS_INVALID, and YEAR0.

Referenced by cmdarg_load().


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