Back to index

php5  5.3.10
timelib_structs.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2010 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Derick Rethans <derick@derickrethans.nl>                    |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: timelib_structs.h 307038 2011-01-03 19:24:04Z scottmac $ */
00020 
00021 #ifndef __TIMELIB_STRUCTS_H__
00022 #define __TIMELIB_STRUCTS_H__
00023 
00024 #include "timelib_config.h"
00025 
00026 #ifdef HAVE_SYS_TYPES_H
00027 #include <sys/types.h>
00028 #endif
00029 
00030 #if defined(HAVE_INTTYPES_H)
00031 #include <inttypes.h>
00032 #elif defined(HAVE_STDINT_H)
00033 #include <stdint.h>
00034 #endif
00035 
00036 #ifdef PHP_WIN32
00037 /* TODO: Remove these hacks/defs once we have the int definitions in main/ 
00038         rathen than in each 2nd extension and win32/ */
00039 # include "win32/php_stdint.h"
00040 #else
00041 # ifndef HAVE_INT32_T
00042 #  if SIZEOF_INT == 4
00043 typedef int int32_t;
00044 #  elif SIZEOF_LONG == 4
00045 typedef long int int32_t;
00046 #  endif
00047 # endif
00048 
00049 # ifndef HAVE_UINT32_T
00050 #  if SIZEOF_INT == 4
00051 typedef unsigned int uint32_t;
00052 #  elif SIZEOF_LONG == 4
00053 typedef unsigned long int uint32_t;
00054 #  endif
00055 # endif
00056 #endif
00057 
00058 #include <stdio.h>
00059 
00060 #ifdef HAVE_STDLIB_H
00061 #include <stdlib.h>
00062 #endif
00063 
00064 #ifdef HAVE_STRING_H
00065 #include <string.h>
00066 #else
00067 #include <strings.h>
00068 #endif
00069 
00070 #if defined(_MSC_VER)
00071 typedef uint64_t timelib_ull;
00072 typedef int64_t timelib_sll;
00073 # define TIMELIB_LL_CONST(n) n ## i64
00074 #else
00075 typedef unsigned long long timelib_ull;
00076 typedef signed long long timelib_sll;
00077 # define TIMELIB_LL_CONST(n) n ## ll
00078 #endif
00079 
00080 typedef struct ttinfo
00081 {
00082        int32_t      offset;
00083        int          isdst;
00084        unsigned int abbr_idx;
00085 
00086        unsigned int isstdcnt;
00087        unsigned int isgmtcnt;
00088 } ttinfo;
00089 
00090 typedef struct tlinfo
00091 {
00092        int32_t  trans;
00093        int32_t  offset;
00094 } tlinfo;
00095 
00096 typedef struct tlocinfo
00097 {
00098        char country_code[3];
00099        double latitude;
00100        double longitude;
00101        char *comments;
00102 } tlocinfo;
00103 
00104 typedef struct timelib_tzinfo
00105 {
00106        char    *name;
00107        uint32_t ttisgmtcnt;
00108        uint32_t ttisstdcnt;
00109        uint32_t leapcnt;
00110        uint32_t timecnt;
00111        uint32_t typecnt;
00112        uint32_t charcnt;
00113 
00114        int32_t *trans;
00115        unsigned char *trans_idx;
00116 
00117        ttinfo  *type;
00118        char    *timezone_abbr;
00119 
00120        tlinfo  *leap_times;
00121        unsigned char bc;
00122        tlocinfo location;
00123 } timelib_tzinfo;
00124 
00125 typedef struct timelib_special {
00126        unsigned int type;
00127        timelib_sll amount;
00128 } timelib_special;
00129 
00130 typedef struct timelib_rel_time {
00131        timelib_sll y, m, d; /* Years, Months and Days */
00132        timelib_sll h, i, s; /* Hours, mInutes and Seconds */
00133 
00134        int weekday; /* Stores the day in 'next monday' */
00135        int weekday_behavior; /* 0: the current day should *not* be counted when advancing forwards; 1: the current day *should* be counted */
00136 
00137        int first_last_day_of;
00138        int invert; /* Whether the difference should be inverted */
00139        timelib_sll days; /* Contains the number of *days*, instead of Y-M-D differences */
00140 
00141        timelib_special  special;
00142        unsigned int   have_weekday_relative, have_special_relative;
00143 } timelib_rel_time;
00144 
00145 typedef struct timelib_time_offset {
00146        int32_t      offset;
00147        unsigned int leap_secs;
00148        unsigned int is_dst;
00149        char        *abbr;
00150        timelib_sll  transistion_time;
00151 } timelib_time_offset;
00152 
00153 typedef struct timelib_time {
00154        timelib_sll      y, m, d;     /* Year, Month, Day */
00155        timelib_sll      h, i, s;     /* Hour, mInute, Second */
00156        double           f;           /* Fraction */
00157        int              z;           /* GMT offset in minutes */
00158        char            *tz_abbr;     /* Timezone abbreviation (display only) */
00159        timelib_tzinfo  *tz_info;     /* Timezone structure */
00160        signed int       dst;         /* Flag if we were parsing a DST zone */
00161        timelib_rel_time relative;
00162 
00163        timelib_sll      sse;         /* Seconds since epoch */
00164 
00165        unsigned int   have_time, have_date, have_zone, have_relative, have_weeknr_day;
00166 
00167        unsigned int   sse_uptodate; /* !0 if the sse member is up to date with the date/time members */
00168        unsigned int   tim_uptodate; /* !0 if the date/time members are up to date with the sse member */
00169        unsigned int   is_localtime; /*  1 if the current struct represents localtime, 0 if it is in GMT */
00170        unsigned int   zone_type;    /*  1 time offset,
00171                                      *  3 TimeZone identifier,
00172                                      *  2 TimeZone abbreviation */
00173 } timelib_time;
00174 
00175 typedef struct timelib_error_message {
00176        int         position;
00177        char        character;
00178        char       *message;
00179 } timelib_error_message;
00180 
00181 typedef struct timelib_error_container {
00182        int                           warning_count;
00183        struct timelib_error_message *warning_messages;
00184        int                           error_count;
00185        struct timelib_error_message *error_messages;
00186 } timelib_error_container;
00187 
00188 typedef struct _timelib_tz_lookup_table {
00189        char       *name;
00190        int         type;
00191        float       gmtoffset;
00192        char       *full_tz_name;
00193 } timelib_tz_lookup_table;
00194 
00195 typedef struct _timelib_tzdb_index_entry {
00196        char *id;
00197        unsigned int pos;
00198 } timelib_tzdb_index_entry;
00199 
00200 typedef struct _timelib_tzdb {
00201        char                           *version;
00202        int                             index_size;
00203        const timelib_tzdb_index_entry *index;
00204        const unsigned char            *data;
00205 } timelib_tzdb;
00206 
00207 #define TIMELIB_ZONETYPE_OFFSET 1
00208 #define TIMELIB_ZONETYPE_ABBR   2
00209 #define TIMELIB_ZONETYPE_ID     3
00210 
00211 #define SECS_PER_ERA   TIMELIB_LL_CONST(12622780800)
00212 #define SECS_PER_DAY   86400
00213 #define DAYS_PER_YEAR    365
00214 #define DAYS_PER_LYEAR   366
00215 /* 400*365 days + 97 leap days */
00216 #define DAYS_PER_LYEAR_PERIOD 146097
00217 #define YEARS_PER_LYEAR_PERIOD 400
00218 
00219 #define timelib_is_leap(y) ((y) % 4 == 0 && ((y) % 100 != 0 || (y) % 400 == 0))
00220 
00221 #define TIMELIB_DEBUG(s)  if (0) { s }
00222 
00223 #endif