diff options
Diffstat (limited to 'src/include/utils')
-rw-r--r-- | src/include/utils/datetime.h | 48 | ||||
-rw-r--r-- | src/include/utils/tzparser.h | 10 |
2 files changed, 40 insertions, 18 deletions
diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h index 2e69503f96d..9b53ee38ccf 100644 --- a/src/include/utils/datetime.h +++ b/src/include/utils/datetime.h @@ -77,7 +77,7 @@ struct tzEntry; #define BC 1 /* - * Fields for time decoding. + * Field types for time decoding. * * Can't have more of these than there are bits in an unsigned int * since these are turned into bit masks during parsing and decoding. @@ -93,9 +93,9 @@ struct tzEntry; #define YEAR 2 #define DAY 3 #define JULIAN 4 -#define TZ 5 -#define DTZ 6 -#define DTZMOD 7 +#define TZ 5 /* fixed-offset timezone abbreviation */ +#define DTZ 6 /* fixed-offset timezone abbrev, DST */ +#define DYNTZ 7 /* dynamic timezone abbreviation */ #define IGNORE_DTF 8 #define AMPM 9 #define HOUR 10 @@ -119,18 +119,24 @@ struct tzEntry; #define DECADE 25 #define CENTURY 26 #define MILLENNIUM 27 +/* hack for parsing two-word timezone specs "MET DST" etc */ +#define DTZMOD 28 /* "DST" as a separate word */ /* reserved for unrecognized string values */ #define UNKNOWN_FIELD 31 /* * Token field definitions for time parsing and decoding. - * These need to fit into the datetkn table type. - * At the moment, that means keep them within [-127,127]. - * These are also used for bit masks in DecodeDateDelta() + * + * Some field type codes (see above) use these as the "value" in datetktbl[]. + * These are also used for bit masks in DecodeDateTime and friends * so actually restrict them to within [0,31] for now. * - thomas 97/06/19 - * Not all of these fields are used for masks in DecodeDateDelta + * Not all of these fields are used for masks in DecodeDateTime * so allow some larger than 31. - thomas 1997-11-17 + * + * Caution: there are undocumented assumptions in the code that most of these + * values are not equal to IGNORE_DTF nor RESERV. Be very careful when + * renumbering values in either of these apparently-independent lists :-( */ #define DTK_NUMBER 0 @@ -203,18 +209,27 @@ struct tzEntry; /* keep this struct small; it gets used a lot */ typedef struct { - char token[TOKMAXLEN]; - char type; - char value; /* this may be unsigned, alas */ + char token[TOKMAXLEN + 1]; /* always NUL-terminated */ + char type; /* see field type codes above */ + int32 value; /* meaning depends on type */ } datetkn; /* one of its uses is in tables of time zone abbreviations */ typedef struct TimeZoneAbbrevTable { - int numabbrevs; + Size tblsize; /* size in bytes of TimeZoneAbbrevTable */ + int numabbrevs; /* number of entries in abbrevs[] array */ datetkn abbrevs[1]; /* VARIABLE LENGTH ARRAY */ + /* DynamicZoneAbbrev(s) may follow the abbrevs[] array */ } TimeZoneAbbrevTable; +/* auxiliary data for a dynamic time zone abbreviation (non-fixed-offset) */ +typedef struct DynamicZoneAbbrev +{ + pg_tz *tz; /* NULL if not yet looked up */ + char zone[1]; /* zone name (var length, NUL-terminated) */ +} DynamicZoneAbbrev; + /* FMODULO() * Macro to replace modf(), which is broken on some platforms. @@ -296,6 +311,9 @@ extern void DateTimeParseError(int dterr, const char *str, const char *datatype) __attribute__((noreturn)); extern int DetermineTimeZoneOffset(struct pg_tm * tm, pg_tz *tzp); +extern int DetermineTimeZoneAbbrevOffset(struct pg_tm * tm, const char *abbr, pg_tz *tzp); +extern int DetermineTimeZoneAbbrevOffsetTS(TimestampTz ts, const char *abbr, + pg_tz *tzp, int *isdst); extern void EncodeDateOnly(struct pg_tm * tm, int style, char *str); extern void EncodeTimeOnly(struct pg_tm * tm, fsec_t fsec, bool print_tz, int tz, int style, char *str); @@ -305,6 +323,8 @@ extern void EncodeInterval(struct pg_tm * tm, fsec_t fsec, int style, char *str) extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, struct pg_tm * tm); +extern int DecodeTimezoneAbbrev(int field, char *lowtoken, + int *offset, pg_tz **tz); extern int DecodeSpecial(int field, char *lowtoken, int *val); extern int DecodeUnits(int field, char *lowtoken, int *val); @@ -314,8 +334,8 @@ extern Node *TemporalTransform(int32 max_precis, Node *node); extern bool CheckDateTokenTables(void); -extern void ConvertTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl, - struct tzEntry *abbrevs, int n); +extern TimeZoneAbbrevTable *ConvertTimeZoneAbbrevs(struct tzEntry *abbrevs, + int n); extern void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl); extern Datum pg_timezone_abbrevs(PG_FUNCTION_ARGS); diff --git a/src/include/utils/tzparser.h b/src/include/utils/tzparser.h index 82728a67dd0..637f449e36c 100644 --- a/src/include/utils/tzparser.h +++ b/src/include/utils/tzparser.h @@ -22,10 +22,12 @@ */ typedef struct tzEntry { - /* the actual data: TZ abbrev (downcased), offset, DST flag */ - char *abbrev; - int offset; /* in seconds from UTC */ - bool is_dst; + /* the actual data */ + char *abbrev; /* TZ abbreviation (downcased) */ + char *zone; /* zone name if dynamic abbrev, else NULL */ + /* for a dynamic abbreviation, offset/is_dst are not used */ + int offset; /* offset in seconds from UTC */ + bool is_dst; /* true if a DST abbreviation */ /* source information (for error messages) */ int lineno; const char *filename; |