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

date.h

Go to the documentation of this file.
00001 /*! \file date.h
00002     Header file for all date's utilities.
00003  */
00004 
00005 #ifdef __cplusplus
00006 extern "C" {
00007 #endif
00008 
00009 #ifndef DATE_HPP
00010 
00011 #include <stdio.h>
00012 #include <time.h>
00013 #include <string.h>
00014 #include <stdlib.h>
00015 #include "strings_utils.h"
00016 
00017 /*! \brief Maximum number of bytes for the environment variable &quot;TZ&quot; (ex: &quot;TZ=GMT +0&quot;).
00018  */
00019 
00020 #define TZSET_MAX_SIZE  256
00021 
00022 /*! \brief Maximum number of bytes for the tag that defines the time zone (MET, CEST, ...).
00023  */
00024 
00025 #define TIMEZONE_SIZE   50
00026 
00027 /*! \brief Maximum number of bytes for the tag that defines the time daylight saving mode (DST, ...).
00028  */
00029 
00030 #define DAYLIGHT_SIZE   50
00031 
00032 /*! \brief This defines the maximum number of bytes for a TSM formated date (ex: Thu Aug 30 01:00:48 MET DST
00033            2001).
00034  */
00035 
00036 #define MAX_TSM_DATE_SIZE  256
00037 
00038 /*! \brief This defines the maximum number of lines in the time zones configuration file. One line is a set of 3 vales:
00039            (time zone, daylight saving mode, time shift) - for example (MET DST -3600).
00040  */
00041 
00042 #define MAX_TZ_DEF        300
00043 
00044 /*! \brief Return value for the function load_timezones(). Too many time zones definitions in the time zones configuration
00045            file. This maximum number is represented by the constant MAX_TZ_DEF.
00046  */
00047 
00048 #define TIME_ZONES_DEF_OVERFLOW        -1
00049 
00050 /*! \brief Return value for the function load_timezones(). This means that the program is running out of memory.
00051  */
00052 
00053 #define TIME_ZONES_NO_MEM              -2
00054 
00055 /*! \brief Return value for the function load_timezones() (or via the time zone configuration parser). This means that
00056            the time zone configuration file is not valid. One time zone tag is too long (too many characters).
00057  */
00058 
00059 #define TIME_ZONES_TIMEZONE_OVERFLOW   -3
00060 
00061 /*! \brief Return value for the function load_timezones() (or via the time zone configuration parser). This means that
00062            the time zone configuration file is not valid. One daylight saving tag is too long.
00063  */
00064 
00065 #define TIME_ZONES_DAYLIGHT_OVERFLOW   -4
00066 
00067 /*! \brief Return value for the function load_timezones() (or via the time zone configuration parser). This means that
00068            the time zone configuration file is not valid. The parser found a syntax error.
00069  */
00070 
00071 #define TIME_ZONES_PARSE_ERROR         -5
00072 
00073 /*! \brief Return value for the function load_timezones(). No time zones configuration file specified. Please read the 
00074            documentation for the function load_timezones().
00075  */
00076 
00077 #define TIME_ZONES_NO_FILE             -6
00078 
00079 /*! \brief Return value for the function load_timezones(). This means that the time zones configuration file is empty
00080            (no configuration found).
00081  */
00082 
00083 #define TIME_ZONES_NO_DEF_FOUND        -7
00084 
00085 /*! \brief Return value for the function load_timezones(). Can not open the time zones configuration file.
00086  */
00087 
00088 #define TIME_ZONES_CAN_NOT_OPEN_FILE   -8
00089 
00090 /*! \brief Return value for the function load_timezones(). This means that the function loaded the time zones configuration
00091            file successfully.
00092  */
00093 
00094 #define TIME_ZONES_LOAD_OK             -9
00095 
00096 
00097 /*! \brief If the last argument of the function date2timestamp() is set to AUTOMATIC_TIME_SHIFT_COMPUTATION, then
00098            the function date2timestamp() will use the external timezone configuration file to find out the correct
00099            time shift. please note that AUTOMATIC_TIME_SHIFT_COMPUTATION = 24*3600 (one day shift).
00100  */
00101 
00102 #define AUTOMATIC_TIME_SHIFT_COMPUTATION 86400
00103 
00104 /*! \brief Data structure that defines a time zone (for example "MET DST -3600").
00105  */
00106 
00107 struct timezones {
00108 
00109                    /*! \brief Tag that defines the time zone (ex: MET). */
00110 
00111                    char   timezone[TIMEZONE_SIZE];    /* ex: MET    */
00112 
00113                    /*! \brief Tag that defines the daylight saving mode (ex: DST). */
00114 
00115                    char   daylight[DAYLIGHT_SIZE];    /* ex: DST    */
00116 
00117                    /*! \brief Time shift (ex: -3600). */
00118 
00119                    int    shift;                      /* ex: -3600  */
00120                  };
00121 
00122 /*! \brief Data structure that contains all the time zone configuration extracted from the time zones configuration file.
00123            This structure is set up by the function load_timezones() (calling the time zones configuration file parser).
00124  */
00125 
00126 struct tz_tab {
00127 
00128                 /*! \brief Array of data structures that define time zones. */
00129 
00130                 struct timezones tz[MAX_TZ_DEF];
00131 
00132                 /*! \brief Number of elements in the array 'tz'. */
00133 
00134                 int              entry_number;
00135               };
00136 
00137 
00138 
00139 /*! \brief Maximum size for a reference date (load the timestamps reference parser).
00140  */
00141 #define TTREF_MAX_DATE_SIZE        1020
00142 
00143 /*! \brief Maximum size for a reference timestamp (load the timestamps reference parser).
00144  */
00145 #define TTREF_MAX_TIMESTAMP_SIZE   100
00146 
00147 /*! \brief Maximum number of entries in the reference timestamp configuration file.
00148  */
00149 #define MAX_TTREF_ENTRIES          300
00150 
00151 /*! \brief The data structure defines a couple (date, timestamp) used  as reference.
00152  */
00153 struct tstamp_ref {
00154                     /*! \brief Date used as reference. */
00155 
00156                     char   date[TTREF_MAX_DATE_SIZE];
00157 
00158                     /*! \brief Timestalo used as reference. */
00159 
00160                     char   timestamp[TTREF_MAX_TIMESTAMP_SIZE];
00161                   }; 
00162 
00163 
00164 /*! \brief The data structure defines the list of couples (date, timestamp) loaded from the timestamps reference file).
00165  */ 
00166 struct ttref_tab  {
00167                     /*! \brief List of all couples (date, timestamp) used  as reference. */
00168 
00169                     struct tstamp_ref ttref[MAX_TTREF_ENTRIES];
00170 
00171                     /*! \brief Number of couples (date, timestamp), in the array 'tstamp_ref'. */
00172 
00173                     int               entry_number;
00174                   };
00175 
00176 /*! \brief Return value for the timestamps reference parser. 
00177  */
00178 #define TTREF_TOO_MANY_REF  -1
00179 
00180 /*! \brief Return value for the timestamps reference parser.
00181  */
00182 #define TTREF_NO_MEM        -2
00183 
00184 /*! \brief Return value for the timestamps reference parser.
00185  */
00186 #define TTREF_SYNTAX_ERROR  -3
00187 
00188 /*! \brief Return value for the timestamps reference parser.
00189  */
00190 #define TTREF_DATE_TOO_LONG -4
00191 
00192 /*! \brief Return value for the timestamps reference parser.
00193  */
00194 #define TTREF_REF_TOO_LONG  -5
00195 
00196 /*! \brief Return value for the function test_tz_conf(). This means that this function could not open the configuration
00197            file.
00198  */
00199 #define TTREF_CAN_NOT_OPEN_CONF_FILE -6
00200 
00201 /*! \brief Return value for the function test_tz_conf(). This means that one of the input date was invalid (the input
00202            date comes from the timestamps reference configuration file.
00203  */
00204 #define TTREF_INVALID_DATE  -7
00205 
00206 /*! \brief Return value for the function test_tz_conf(). This means that the timestamps' computation was correct.
00207  */
00208 #define TTREF_OK            0 
00209 
00210 /*! \brief Return value for the function test_tz_conf(). This means that the timestamps' computation was not correct.
00211  */
00212 #define TTREF_KO            1
00213 
00214 /*********************************************************/
00215 
00216 /*! \brief Configuration value for the function test_tz_conf(). This means that we request the time zone auto configuration
00217            mode.
00218  */
00219 #define TZ_AUTOCONF_ON    0
00220 
00221 /*! \brief Configuration value for the function test_tz_conf(). This means that we do NOT request the time zone auto
00222            configuration mode.
00223  */
00224 #define TZ_AUTOCONF_OFF   1
00225 
00226 /*********************************************************/
00227 
00228 /*! \brief This defines fields' indexes. The day of the week is the field number 0 (the first one) in the TSM's date.
00229  */
00230 
00231 #define DAY_OF_THE_WEEK    0
00232 
00233 /*! \brief This defines fields' indexes. The month is the field numbre 1 (the second one) in the TSM's date.
00234  */
00235 
00236 #define MONTH              1
00237 
00238 /*! \brief This defines fields' indexes. The day of the month is the field number 2 (the third one) in the TSM's date.
00239  */
00240 
00241 #define DAY_OF_THE_MONTH   2
00242 
00243 /*! \brief This defines fields' indexes. The clock time is the field number 3 (the fourth one) in the TSM's date.
00244  */
00245 
00246 #define CLOCK              3
00247 
00248 /*! \brief This defines fields' indexes. The hour is the field number 0 (the first one) in the TSM's clock time.
00249  */
00250 
00251 #define HOUR               0
00252 
00253 /*! \brief This defines fields' indexes. The minute is the field number 1 (the second one) in the TSM's clock time.
00254  */
00255 
00256 #define MINUTES            1
00257 
00258 /*! \brief This defines fields' indexes. The second is the field number 2 (the third one) in the TSM's clock time.
00259  */
00260 
00261 #define SECONDS            2
00262 
00263 /*! \brief This defines fields' indexes. The tag "MET" should be the field number 4 (the fifth one) in the TSM's date.
00264  */
00265 
00266 #define TAG1               4
00267 
00268 /*! \brief This defines fields' indexes. The tag "DST" should be the field number 5 (the sixth one) in the TSM's date.
00269  */
00270 
00271 #define TAG2               5 
00272 
00273 /*! \brief This defines fields' indexes. The year should be the field number 6 (the seventh one) in the TSM's date.
00274  */
00275 
00276 #define YEAR               6
00277 
00278 /*! \brief The maximum number of bytes used to save the current date.
00279  */
00280 
00281 #define MAX_TIMER_SIZE     256
00282 
00283 int set_local_TZ_to_GMT();
00284 char* print_tz_conf();
00285 int test_tz_conf (char* config_file, int auto_conf);
00286 int load_timezones (char *filename);
00287 int tzfound (struct timezones *tzz);
00288 int tzcmp (struct timezones *tz1, struct timezones *tz2);
00289 int get_day (char *day);
00290 int get_month (char *month);
00291 char* date2timestamp (char* date, char* timestamp, int nbcar, int shift);
00292 char* dater();
00293 time_t get_utc_timestamp();
00294 char *get_tsm_date (time_t timestamp, int debug);
00295 
00296 #define DATE_HPP
00297 #endif
00298 
00299 
00300 #ifdef __cplusplus
00301 }
00302 #endif
00303 

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