Download pgsql/include/server/utils/datetime.h from codekingpro/portable-devtools: direct link, hf CLI and curl.
- Browser
- Download file 11.6 kB
-
https://huggingface.co/datasets/codekingpro/portable-devtools/resolve/df58e70f9edde36aaca2d2aacc2440dd6c2f807d/pgsql/include/server/utils/datetime.h
- Command line
-
hf download hf://datasets/codekingpro/portable-devtools@df58e70f9edde36aaca2d2aacc2440dd6c2f807d/pgsql/include/server/utils/datetime.h
-
curl -L -o datetime.h https://huggingface.co/datasets/codekingpro/portable-devtools/resolve/df58e70f9edde36aaca2d2aacc2440dd6c2f807d/pgsql/include/server/utils/datetime.h
11.6 kB
| /*------------------------------------------------------------------------- | |
| * | |
| * datetime.h | |
| * Definitions for date/time support code. | |
| * The support code is shared with other date data types, | |
| * including date, and time. | |
| * | |
| * | |
| * Portions Copyright (c) 1996-2023, PostgreSQL Global Development Group | |
| * Portions Copyright (c) 1994, Regents of the University of California | |
| * | |
| * src/include/utils/datetime.h | |
| * | |
| *------------------------------------------------------------------------- | |
| */ | |
| /* this struct is declared in utils/tzparser.h: */ | |
| struct tzEntry; | |
| /* ---------------------------------------------------------------- | |
| * time types + support macros | |
| * | |
| * String definitions for standard time quantities. | |
| * | |
| * These strings are the defaults used to form output time strings. | |
| * Other alternative forms are hardcoded into token tables in datetime.c. | |
| * ---------------------------------------------------------------- | |
| */ | |
| /* | |
| * Fundamental time field definitions for parsing. | |
| * | |
| * Meridian: am, pm, or 24-hour style. | |
| * Millennium: ad, bc | |
| */ | |
| /* | |
| * 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. | |
| * | |
| * Furthermore, the values for YEAR, MONTH, DAY, HOUR, MINUTE, SECOND | |
| * must be in the range 0..14 so that the associated bitmasks can fit | |
| * into the left half of an INTERVAL's typmod value. Since those bits | |
| * are stored in typmods, you can't change them without initdb! | |
| */ | |
| /* these are only for relative dates */ | |
| /* generic fields to help with parsing */ | |
| /* these are only for parsing intervals */ | |
| /* hack for parsing two-word timezone specs "MET DST" etc */ | |
| /* reserved for unrecognized string values */ | |
| /* | |
| * Token field definitions for time parsing and decoding. | |
| * | |
| * 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 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 :-( | |
| */ | |
| /* | |
| * Bit mask definitions for time parsing. | |
| */ | |
| /* Convenience: a second, plus any fractional component */ | |
| /* | |
| * Working buffer size for input and output of interval, timestamp, etc. | |
| * Inputs that need more working space will be rejected early. Longer outputs | |
| * will overrun buffers, so this must suffice for all possible output. As of | |
| * this writing, interval_out() needs the most space at ~90 bytes. | |
| */ | |
| /* maximum possible number of fields in a date string */ | |
| /* only this many chars are stored in datetktbl */ | |
| /* keep this struct small; it gets used a lot */ | |
| typedef struct | |
| { | |
| 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 | |
| { | |
| Size tblsize; /* size in bytes of TimeZoneAbbrevTable */ | |
| int numabbrevs; /* number of entries in abbrevs[] array */ | |
| datetkn abbrevs[FLEXIBLE_ARRAY_MEMBER]; | |
| /* 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[FLEXIBLE_ARRAY_MEMBER]; /* NUL-terminated zone name */ | |
| } DynamicZoneAbbrev; | |
| /* FMODULO() | |
| * Macro to replace modf(), which is broken on some platforms. | |
| * t = input and remainder | |
| * q = integer part | |
| * u = divisor | |
| */ | |
| /* TMODULO() | |
| * Like FMODULO(), but work on the timestamp datatype (now always int64). | |
| * We assume that int64 follows the C99 semantics for division (negative | |
| * quotients truncate towards zero). | |
| */ | |
| /* | |
| * Date/time validation | |
| * Include check for leap year. | |
| */ | |
| extern PGDLLIMPORT const char *const months[]; /* months (3-char | |
| * abbreviations) */ | |
| extern PGDLLIMPORT const char *const days[]; /* days (full names) */ | |
| extern PGDLLIMPORT const int day_tab[2][13]; | |
| /* | |
| * These are the rules for the Gregorian calendar, which was adopted in 1582. | |
| * However, we use this calculation for all prior years as well because the | |
| * SQL standard specifies use of the Gregorian calendar. This prevents the | |
| * date 1500-02-29 from being stored, even though it is valid in the Julian | |
| * calendar. | |
| */ | |
| /* | |
| * Datetime input parsing routines (ParseDateTime, DecodeDateTime, etc) | |
| * return zero or a positive value on success. On failure, they return | |
| * one of these negative code values. DateTimeParseError may be used to | |
| * produce a suitable error report. For some of these codes, | |
| * DateTimeParseError requires additional information, which is carried | |
| * in struct DateTimeErrorExtra. | |
| */ | |
| typedef struct DateTimeErrorExtra | |
| { | |
| /* Needed for DTERR_BAD_TIMEZONE and DTERR_BAD_ZONE_ABBREV: */ | |
| const char *dtee_timezone; /* incorrect time zone name */ | |
| /* Needed for DTERR_BAD_ZONE_ABBREV: */ | |
| const char *dtee_abbrev; /* relevant time zone abbreviation */ | |
| } DateTimeErrorExtra; | |
| /* Result codes for DecodeTimezoneName() */ | |
| extern void GetCurrentDateTime(struct pg_tm *tm); | |
| extern void GetCurrentTimeUsec(struct pg_tm *tm, fsec_t *fsec, int *tzp); | |
| extern void j2date(int jd, int *year, int *month, int *day); | |
| extern int date2j(int year, int month, int day); | |
| extern int ParseDateTime(const char *timestr, char *workbuf, size_t buflen, | |
| char **field, int *ftype, | |
| int maxfields, int *numfields); | |
| extern int DecodeDateTime(char **field, int *ftype, int nf, | |
| int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, | |
| DateTimeErrorExtra *extra); | |
| extern int DecodeTimezone(const char *str, int *tzp); | |
| extern int DecodeTimeOnly(char **field, int *ftype, int nf, | |
| int *dtype, struct pg_tm *tm, fsec_t *fsec, int *tzp, | |
| DateTimeErrorExtra *extra); | |
| extern int DecodeInterval(char **field, int *ftype, int nf, int range, | |
| int *dtype, struct pg_itm_in *itm_in); | |
| extern int DecodeISO8601Interval(char *str, | |
| int *dtype, struct pg_itm_in *itm_in); | |
| extern void DateTimeParseError(int dterr, DateTimeErrorExtra *extra, | |
| const char *str, const char *datatype, | |
| struct Node *escontext); | |
| 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); | |
| extern void EncodeDateTime(struct pg_tm *tm, fsec_t fsec, bool print_tz, int tz, const char *tzn, int style, char *str); | |
| extern void EncodeInterval(struct pg_itm *itm, int style, char *str); | |
| extern void EncodeSpecialTimestamp(Timestamp dt, char *str); | |
| extern int ValidateDate(int fmask, bool isjulian, bool is2digits, bool bc, | |
| struct pg_tm *tm); | |
| extern int DecodeTimezoneAbbrev(int field, const char *lowtoken, | |
| int *ftype, int *offset, pg_tz **tz, | |
| DateTimeErrorExtra *extra); | |
| extern int DecodeSpecial(int field, const char *lowtoken, int *val); | |
| extern int DecodeUnits(int field, const char *lowtoken, int *val); | |
| extern int DecodeTimezoneName(const char *tzname, int *offset, pg_tz **tz); | |
| extern pg_tz *DecodeTimezoneNameToTz(const char *tzname); | |
| extern int j2day(int date); | |
| extern struct Node *TemporalSimplify(int32 max_precis, struct Node *node); | |
| extern bool CheckDateTokenTables(void); | |
| extern TimeZoneAbbrevTable *ConvertTimeZoneAbbrevs(struct tzEntry *abbrevs, | |
| int n); | |
| extern void InstallTimeZoneAbbrevs(TimeZoneAbbrevTable *tbl); | |
| extern bool AdjustTimestampForTypmod(Timestamp *time, int32 typmod, | |
| struct Node *escontext); | |