Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Examples  

date.h File Reference

Go to the source code of this file.

Data Structures

struct  timezones
 Data structure that defines a time zone (for example "MET DST -3600"). More...

struct  tstamp_ref
 The data structure defines a couple (date, timestamp) used as reference. More...

struct  ttref_tab
 The data structure defines the list of couples (date, timestamp) loaded from the timestamps reference file). More...

struct  tz_tab
 Data structure that contains all the time zone configuration extracted from the time zones configuration file. This structure is set up by the function load_timezones() (calling the time zones configuration file parser). More...


Defines

#define TZSET_MAX_SIZE   256
 Maximum number of bytes for the environment variable "TZ" (ex: "TZ=GMT +0").

#define TIMEZONE_SIZE   50
 Maximum number of bytes for the tag that defines the time zone (MET, CEST, ...).

#define DAYLIGHT_SIZE   50
 Maximum number of bytes for the tag that defines the time daylight saving mode (DST, ...).

#define MAX_TSM_DATE_SIZE   256
 This defines the maximum number of bytes for a TSM formated date (ex: Thu Aug 30 01:00:48 MET DST 2001).

#define MAX_TZ_DEF   300
 This defines the maximum number of lines in the time zones configuration file. One line is a set of 3 vales: (time zone, daylight saving mode, time shift) - for example (MET DST -3600).

#define TIME_ZONES_DEF_OVERFLOW   -1
 Return value for the function load_timezones(). Too many time zones definitions in the time zones configuration file. This maximum number is represented by the constant MAX_TZ_DEF.

#define TIME_ZONES_NO_MEM   -2
 Return value for the function load_timezones(). This means that the program is running out of memory.

#define TIME_ZONES_TIMEZONE_OVERFLOW   -3
 Return value for the function load_timezones() (or via the time zone configuration parser). This means that the time zone configuration file is not valid. One time zone tag is too long (too many characters).

#define TIME_ZONES_DAYLIGHT_OVERFLOW   -4
 Return value for the function load_timezones() (or via the time zone configuration parser). This means that the time zone configuration file is not valid. One daylight saving tag is too long.

#define TIME_ZONES_PARSE_ERROR   -5
 Return value for the function load_timezones() (or via the time zone configuration parser). This means that the time zone configuration file is not valid. The parser found a syntax error.

#define TIME_ZONES_NO_FILE   -6
 Return value for the function load_timezones(). No time zones configuration file specified. Please read the documentation for the function load_timezones().

#define TIME_ZONES_NO_DEF_FOUND   -7
 Return value for the function load_timezones(). This means that the time zones configuration file is empty (no configuration found).

#define TIME_ZONES_CAN_NOT_OPEN_FILE   -8
 Return value for the function load_timezones(). Can not open the time zones configuration file.

#define TIME_ZONES_LOAD_OK   -9
 Return value for the function load_timezones(). This means that the function loaded the time zones configuration file successfully.

#define AUTOMATIC_TIME_SHIFT_COMPUTATION   86400
 If the last argument of the function date2timestamp() is set to AUTOMATIC_TIME_SHIFT_COMPUTATION, then the function date2timestamp() will use the external timezone configuration file to find out the correct time shift. please note that AUTOMATIC_TIME_SHIFT_COMPUTATION = 24*3600 (one day shift).

#define TTREF_MAX_DATE_SIZE   1020
 Maximum size for a reference date (load the timestamps reference parser).

#define TTREF_MAX_TIMESTAMP_SIZE   100
 Maximum size for a reference timestamp (load the timestamps reference parser).

#define MAX_TTREF_ENTRIES   300
 Maximum number of entries in the reference timestamp configuration file.

#define TTREF_TOO_MANY_REF   -1
 Return value for the timestamps reference parser.

#define TTREF_NO_MEM   -2
 Return value for the timestamps reference parser.

#define TTREF_SYNTAX_ERROR   -3
 Return value for the timestamps reference parser.

#define TTREF_DATE_TOO_LONG   -4
 Return value for the timestamps reference parser.

#define TTREF_REF_TOO_LONG   -5
 Return value for the timestamps reference parser.

#define TTREF_CAN_NOT_OPEN_CONF_FILE   -6
 Return value for the function test_tz_conf(). This means that this function could not open the configuration file.

#define TTREF_INVALID_DATE   -7
 Return value for the function test_tz_conf(). This means that one of the input date was invalid (the input date comes from the timestamps reference configuration file.

#define TTREF_OK   0
 Return value for the function test_tz_conf(). This means that the timestamps' computation was correct.

#define TTREF_KO   1
 Return value for the function test_tz_conf(). This means that the timestamps' computation was not correct.

#define TZ_AUTOCONF_ON   0
 Configuration value for the function test_tz_conf(). This means that we request the time zone auto configuration mode.

#define TZ_AUTOCONF_OFF   1
 Configuration value for the function test_tz_conf(). This means that we do NOT request the time zone auto configuration mode.

#define DAY_OF_THE_WEEK   0
 This defines fields' indexes. The day of the week is the field number 0 (the first one) in the TSM's date.

#define MONTH   1
 This defines fields' indexes. The month is the field numbre 1 (the second one) in the TSM's date.

#define DAY_OF_THE_MONTH   2
 This defines fields' indexes. The day of the month is the field number 2 (the third one) in the TSM's date.

#define CLOCK   3
 This defines fields' indexes. The clock time is the field number 3 (the fourth one) in the TSM's date.

#define HOUR   0
 This defines fields' indexes. The hour is the field number 0 (the first one) in the TSM's clock time.

#define MINUTES   1
 This defines fields' indexes. The minute is the field number 1 (the second one) in the TSM's clock time.

#define SECONDS   2
 This defines fields' indexes. The second is the field number 2 (the third one) in the TSM's clock time.

#define TAG1   4
 This defines fields' indexes. The tag "MET" should be the field number 4 (the fifth one) in the TSM's date.

#define TAG2   5
 This defines fields' indexes. The tag "DST" should be the field number 5 (the sixth one) in the TSM's date.

#define YEAR   6
 This defines fields' indexes. The year should be the field number 6 (the seventh one) in the TSM's date.

#define MAX_TIMER_SIZE   256
 The maximum number of bytes used to save the current date.

#define DATE_HPP

Functions

int set_local_TZ_to_GMT ()
 Set the local time zone to GTM (which is equivalent to UTC).

char * print_tz_conf ()
 Returns a zero terminated string of characters that represents the time zones configuration.

int test_tz_conf (char *config_file, int auto_conf)
 Check the time zone configuration data against well known couple (date, timestamps).

int load_timezones (char *filename)
 Load time zones definitions.

int tzfound (struct timezones *tzz)
 Find a time zone data structure in the time zone configuration file.

int tzcmp (struct timezones *tz1, struct timezones *tz2)
 Compare 2 timezone structures.

int get_day (char *day)
 Returns the index of the day (starting at 0, so the returned value is between 0 and 6). The first day (index 0) is 'Sunday'.

int get_month (char *month)
 Returns the index of the month (starting at 0, so the returned value is between 0 and 11). The first month (index 0) is 'january'.

char * date2timestamp (char *date, char *timestamp, int nbcar, int shift)
 Calculate the timestamp of a ticket (The number of seconds since the first of January 1970).

char * dater ()
 Return the current date as Apache's standard.

time_t get_utc_timestamp ()
 Return the number of seconds since 00:00:00 UTC, January 1, 1970.

char * get_tsm_date (time_t timestamp, int debug)
 Format a TSM date (ex: "Tue Sep 17 11:48:39 MET 2002") from a given timestamp.


Detailed Description

Header file for all date's utilities.

Definition in file date.h.


Function Documentation

char* date2timestamp char *    date,
char *    timestamp,
int    nbcar,
int    shift
 

Calculate the timestamp of a ticket (The number of seconds since the first of January 1970).

Parameters:
date Pointer to a string of characters that contains the date as it is read from the TSM's log. the date looks something like ' Tue Aug 28 01:02:24 MET DST 2001'.
timestamp Pointer to a string that will receive the timestamp.
nbcar Size of the memory location pointed by 'timestamp'.
shift This value represents the number of seconds between the current date and the UTC date. If the value of shift is AUTOMATIC_TIME_SHIFT_COMPUTATION, then the function will use the time zones configuration file to find out the correct time shift.
Returns:
The function returns a pointer to 'timestamp'. If an error occurs, the function returns NULL. This can mean that the program is running out of memory, or that the date is not well formated (not "MET" "DST" ...).
Warning:
  • The first thing to do when using all this function of this library is to call set_local_TZ_to_GMT(). Otherwise, timestamps will depend on the system's local time zone configuration.
  • You MUST call the function load_timezones() before using this function !!!! If you do not do that you may produce a segmentation fault.
  • The input date 'date' will be modified. If you need to used it after, then make a copy!.

Definition at line 262 of file date.c.

References AUTOMATIC_TIME_SHIFT_COMPUTATION, CLOCK, current_tz, DAY_OF_THE_MONTH, DAY_OF_THE_WEEK, timezones::daylight, DAYLIGHT_SIZE, free_fields(), get_day(), get_month(), HOUR, MINUTES, MONTH, fields::number_of_fields, s_split(), SECONDS, timezones::shift, fields::tabs, TAG1, TAG2, timezones::timezone, TIMEZONE_SIZE, tzfound(), and YEAR.

Referenced by test_tz_conf().

char* dater  
 

Return the current date as Apache's standard.

Returns:
The function returns a pointer to a string of characters that contains the current date.
Warning:
The returned pointer points to a static string of characters. Therefore you do NOT have to free it (do NOT free it!).

Definition at line 500 of file date.c.

References MAX_TIMER_SIZE.

int get_day char *    day
 

Returns the index of the day (starting at 0, so the returned value is between 0 and 6). The first day (index 0) is 'Sunday'.

Parameters:
day Pointer to a string of characters that contains the day of the week.
Returns:
The function returns the index of the day (starting at 0, so the returned value is between 0 and 6). If an error occurs, the function returns -1.

Definition at line 175 of file date.c.

References days.

Referenced by date2timestamp().

int get_month char *    month
 

Returns the index of the month (starting at 0, so the returned value is between 0 and 11). The first month (index 0) is 'january'.

Parameters:
month Pointer to a string of characters that contains the month of the year.
Returns:
The function returns the index of the month (starting at 0, so the returned value is between 0 and 11). If an error occurs, the function returns -1.

Definition at line 192 of file date.c.

References months.

Referenced by date2timestamp().

char* get_tsm_date time_t    timestamp,
int    debug
 

Format a TSM date (ex: "Tue Sep 17 11:48:39 MET 2002") from a given timestamp.

Parameters:
timestamp Number of seconds since 00:00:00 UTC, January 1, 1970 (as returned by the POSIX function time()).
debug Debug flag (0: no debug, otherwize debug output).
Returns:
Upon successful completion, the function returns a pointer to a string of characters that represents the date associated with the given timestamp. This date respects the TSM's format. If an error occured, the function returns the value NULL.
Warning:
The returned pointer points to a static memory area (declared whithin the function). Therefore you do not have to free it!

Definition at line 667 of file date.c.

References current_tz, days, MAX_TSM_DATE_SIZE, months, tzname, and TZSET_MAX_SIZE.

time_t get_utc_timestamp  
 

Return the number of seconds since 00:00:00 UTC, January 1, 1970.

Returns:
The function returns the number of seconds since 00:00:00 UTC, January 1, 1970.

Definition at line 639 of file date.c.

int load_timezones char *    filename
 

Load time zones definitions.

Parameters:
filename Pointer to a NULL terminated string of characters that contains the name on the file that contains the time zones definitions. If 'filename' is NULL, then the function looks for the environmanr variable "TIMEZONES_DEFINITION".
Returns:
If the operation succed, the function returns TIME_ZONES_LOAD_OK. Otherwise, the function may return:
  • TIME_ZONES_NO_FILE: No file name specified (ie; 'filename' is NULL, and TIMEZONES_DEFINITION is not set).
  • TIME_ZONES_CAN_NOT_OPEN_FILE: Can not open definition file.
  • TIME_ZONES_NO_DEF_FOUND: Definition file is empty.
  • TIME_ZONES_DEF_OVERFLOW: Too many timezones definitions.
  • TIME_ZONES_NO_MEM: Running out of memory.
  • TIME_ZONES_TIMEZONE_OVERFLOW: the timezone flag is too long.
  • TIME_ZONES_DAYLIGHT_OVERFLOW: the daylight flag is too long.
  • TIME_ZONES_PARSE_ERROR: parser error - check config file.

Definition at line 84 of file date.c.

References dateyyin, dateyylex(), tz_tab::entry_number, TIME_ZONES_CAN_NOT_OPEN_FILE, TIME_ZONES_LOAD_OK, TIME_ZONES_NO_DEF_FOUND, TIME_ZONES_NO_FILE, and tzs.

char* print_tz_conf  
 

Returns a zero terminated string of characters that represents the time zones configuration.

Returns:
If the function succed, it returns a non NULL pointer. Otherwise, it returns NULL.
Warning:
The returned pointer has been allocated within the function, make sure to free it (using free()).

Definition at line 207 of file date.c.

References DAYLIGHT_SIZE, tz_tab::entry_number, TIMEZONE_SIZE, TTREF_MAX_TIMESTAMP_SIZE, tz_tab::tz, and tzs.

int set_local_TZ_to_GMT  
 

Set the local time zone to GTM (which is equivalent to UTC).

Returns:
The function returns 0 if success, 1 otherwise.

Definition at line 54 of file date.c.

References current_tz, and TZSET_MAX_SIZE.

int test_tz_conf char *    config_file,
int    auto_conf
 

Check the time zone configuration data against well known couple (date, timestamps).

Parameters:
config_file Pointer to a zero terminated string of characters that represents the name of the timestamps reference configuration file. This file is a list of couple (date, timestamps).
auto_conf Timezone autoconfiguration flag. This value can be:
  • TZ_AUTOCONF_ON: Auto configuration mode requested.
  • TZ_AUTOCONF_OFF: Auto configuration mode not requested.
Returns:
If the time zone configuration is OK, then the function returns TTREF_OK. Otherwise the function may return one of the following codes:
  • TTREF_TOO_MANY_REF; Too many references in the timestamps reference config file.
  • TTREF_NO_MEM: Not enough memory.
  • TTREF_SYNTAX_ERROR: Syntax error found in the timestamps reference config file.
  • TTREF_DATE_TOO_LONG: Date too long in the timestamps reference config file.
  • TTREF_REF_TOO_LONG: timestamp too long in the timestamps reference config file.
  • TTREF_CAN_NOT_OPEN_CONF_FILE Can not open the timestamps reference config file.
  • TTREF_INVALID_DATE: Invalid date format in the timestamps reference config file.
  • TTREF_KO: Invalid time zone configuration - check the time zone configuration file!
Warning:
You must call load_timezones() before you can call this function!.

Definition at line 556 of file date.c.

References AUTOMATIC_TIME_SHIFT_COMPUTATION, current_tz, date2timestamp(), timezones::daylight, ttref_tab::entry_number, timezones::shift, string2time_t(), timezones::timezone, ttref_tab::ttref, TTREF_CAN_NOT_OPEN_CONF_FILE, TTREF_INVALID_DATE, TTREF_KO, TTREF_MAX_DATE_SIZE, TTREF_MAX_TIMESTAMP_SIZE, TTREF_OK, ttrefin, ttreflex(), ttrefs, and TZ_AUTOCONF_OFF.

int tzcmp struct timezones   tz1,
struct timezones   tz2
 

Compare 2 timezone structures.

Parameters:
tz1 Pointer to the first timezone to compare.
tz2 Pointer to the second timezone to compare.
Returns:
The function returns 1 if the two structure are identical, otherwise the function returns 0.

Definition at line 120 of file date.c.

References timezones::daylight, and timezones::timezone.

Referenced by tzfound().

int tzfound struct timezones   tzz
 

Find a time zone data structure in the time zone configuration file.

Parameters:
tzz Pointer to a time zone data structure. This structure must have the fields 'timezone' and 'daylight' correctly initialized (NULL terminated string of characters).
Returns:
If the function found a configuration that matches the time zone defined by 'tzz', it returns 1. Otherwise, the function returns 0. Please note that the structure 'tzz' will contain the correct value for the field 'shift'.

Definition at line 136 of file date.c.

References current_tz, tz_tab::entry_number, timezones::shift, tz_tab::tz, tzcmp(), and tzs.

Referenced by date2timestamp().


Generated on Thu Apr 3 16:23:45 2003 for Common_C_libraries by doxygen1.3-rc1