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

date.c File Reference

Go to the source code of this file.

Functions

int dateyylex ()
 Parser's entry point (created by flex).

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

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

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

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

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 * print_tz_conf ()
 Returns a zero terminated string of characters that represents the time zones configuration.

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.

int ttreflex ()
 Lexical parser build by the flex utility (for parsing the timestamps references configuration file).

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

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.


Variables

int date_line_num
 Current line in the time zones definitions file.

tz_tab tzs
 This structure contains the date 'timezone', 'daylight', 'time shift'.

FILE * dateyyin
 Parser's input stream (used by dateyylex()).

char * tzname [2]
 This array should contain "MET" and "MET DST" for TZ=MET.

time_t timezone
 The external time_t variable altzone contains the difference, in seconds, between Coordinated Universal Time and the alternate time zone.

int daylight
 The external variable daylight indicates whether time should reflect daylight savings time. Both timezone and altzone default to 0 (UTC). The external variable daylight is non-zero if an alternate time zone exists.

timezonescurrent_tz
 The function date2timestamp() lookups the structure 'tzs' to find the correct timezone configuration for the current date actually processed. This variable points to the current time zone configuration that aplies to the currently scaned date.

char * days [7]
 Contains the names of the 7 days of the week.

char * months [12]
 Contains the names of the 12 months of the year.

int ttref_line_num = 0
 Current line number being parsed by the time zones reference parsed.

ttref_tab ttrefs
 Data structure that contains all the couples (date, timestamp) used as reference.

FILE * ttrefin
 Pointer to the stream descriptor used by the timestamps references parser.


Detailed Description

This file contains various functions used to manupulate dates.

Definition in file date.c.


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!.
Examples:
test_date2timestamp.c.

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!
Examples:
test_get_tsm_date.c.

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.
Examples:
test_get_utc_timestamp.c.

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.
Examples:
test_date2timestamp.c, test_load_ttref.c, and test_load_tz.c.

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()).
Examples:
test_load_ttref.c.

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.
Examples:
test_date2timestamp.c, and test_load_ttref.c.

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!.
Examples:
test_load_ttref.c.

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'.
Examples:
test_load_tz.c.

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