53static const char gmt[] =
"GMT";
61#define TZDEFRULESTRING ",M3.2.0,M11.1.0"
123 int32 halfmaxval = one << (32 - 2);
124 int32 maxval = halfmaxval - 1 + halfmaxval;
125 int32 minval = -1 - maxval;
127 result = codep[0] & 0x7f;
128 for (
i = 1;
i < 4; ++
i)
129 result = (result << 8) | (codep[
i] & 0xff);
149 int64 halfmaxval = one << (64 - 2);
150 int64 maxval = halfmaxval - 1 + halfmaxval;
153 result = codep[0] & 0x7f;
154 for (
i = 1;
i < 8; ++
i)
155 result = (result << 8) | (codep[
i] & 0xff);
219 int tzheadsize =
sizeof(
struct tzhead);
238 if (nread < tzheadsize)
240 int err = nread < 0 ? errno : EINVAL;
247 for (stored = 4; stored <= 8; stored *= 2)
257 char const *p = up->
buf + tzheadsize;
268 && (ttisstdcnt ==
typecnt || ttisstdcnt == 0)
269 && (ttisutcnt ==
typecnt || ttisutcnt == 0)))
306 if (attime < sp->ats[
timecnt - 1])
319 unsigned char typ = *p++;
333 ttisp = &sp->
ttis[
i];
369 || (
corr != prevcorr - 1 &&
corr != prevcorr + 1))
382 ttisp = &sp->
ttis[
i];
387 if (*p !=
true && *p !=
false)
396 ttisp = &sp->
ttis[
i];
401 if (*p !=
true && *p !=
false)
412 nread -= p - up->
buf;
413 memmove(up->
buf, p, nread);
415 if (doextend && nread > 2 &&
416 up->
buf[0] ==
'\n' && up->
buf[nread - 1] ==
'\n' &&
421 up->
buf[nread - 1] =
'\0';
441 if (strcmp(sp->
chars +
j, tsabbr) == 0)
449 int tsabbrlen = strlen(tsabbr);
453 strcpy(sp->
chars +
j, tsabbr);
627 {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
628 {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
646 while ((
c = *strp) !=
'\0' && !
is_digit(
c) &&
c !=
',' &&
c !=
'-' &&
667 while ((
c = *strp) !=
'\0' &&
c != delim)
680getnum(
const char *strp,
int *
const nump,
const int min,
const int max)
685 if (strp == NULL || !
is_digit(
c = *strp))
690 num = num * 10 + (
c -
'0');
760 else if (*strp ==
'+')
766 *offsetp = -*offsetp;
789 else if (*strp ==
'M')
866 if (leapyear && rulep->
r_day >= 60)
889 m1 = (rulep->
r_mon + 9) % 12 + 1;
890 yy0 = (rulep->
r_mon <= 2) ? (year - 1) : year;
893 dow = ((26 * m1 - 2) / 10 +
894 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7;
902 d = rulep->
r_day - dow;
917 for (
i = 0;
i < rulep->
r_mon - 1; ++
i)
939 const char *dstname = NULL;
952 stdlen = strlen(
name);
965 stdlen =
name - stdname;
971 stdlen =
name - stdname;
1004 dstlen =
name - dstname;
1011 dstlen =
name - dstname;
1026 if (*
name ==
'\0' && !load_ok)
1036 int32 janoffset = 0;
1068 janoffset = -yearsecs;
1074 for (year = yearbeg; year < yearlim; year++)
1078 endtime =
transtime(year, &end, dstoffset);
1082 bool reversed = endtime < starttime;
1086 int32 swap = starttime;
1088 starttime = endtime;
1092 || (starttime < endtime
1093 && (endtime - starttime
1095 + (stdoffset - dstoffset)))))
1102 janoffset + starttime))
1107 janoffset + endtime))
1114 (&janfirst, janoffset + yearsecs))
1129 int32 theirstdoffset;
1130 int32 theirdstoffset;
1169 theiroffset = theirstdoffset;
1198 sp->
ats[
i] += dstoffset -
1203 sp->
ats[
i] += stdoffset -
1209 theirdstoffset = theiroffset;
1211 theirstdoffset = theiroffset;
1233 memcpy(cp, stdname, stdlen);
1238 memcpy(cp, dstname, dstlen);
1239 *(cp + dstlen) =
'\0';
1258static struct pg_tm *
1260 struct pg_tm *
const tmp)
1262 const struct ttinfo *ttisp;
1264 struct pg_tm *result;
1268 return gmtsub(timep, 0, tmp);
1269 if ((sp->
goback && t < sp->ats[0]) ||
1277 seconds = sp->
ats[0] - t;
1287 if (newt < sp->ats[0] ||
1300 if (!(INT_MIN <= newy && newy <= INT_MAX))
1306 if (sp->
timecnt == 0 || t < sp->ats[0])
1317 int mid = (lo + hi) >> 1;
1319 if (t < sp->ats[mid])
1324 i = (int) sp->
types[lo - 1];
1326 ttisp = &sp->
ttis[
i];
1356static struct pg_tm *
1360 struct pg_tm *result;
1363 static struct state *gmtptr = NULL;
1374 result =
timesub(timep, offset, gmtptr,
tmp);
1402 return y / 4 -
y / 100 +
y / 400;
1413static struct pg_tm *
1429 i = (sp == NULL) ? 0 : sp->
leapcnt;
1453 && tdelta <= INT_MAX))
1457 idelta = (tdays < 0) ? -1 : 1;
1472 rem += offset -
corr;
1523 idays -= ip[tmp->
tm_mon];
1524 tmp->
tm_mday = (int) (idays + 1);
1550 if ((
i >= 0) ? (
j > INT_MAX -
i) : (
j < INT_MIN -
i))
1611 long int *before_gmtoff,
1614 long int *after_gmtoff,
1618 const struct state *sp;
1619 const struct ttinfo *ttisp;
1635 ttisp = &sp->
ttis[
i];
1640 if ((sp->
goback && t < sp->ats[0]) ||
1651 seconds = sp->
ats[0] - t;
1658 if (tcycles - icycles >= 1 || icycles - tcycles >= 1)
1667 if (newt < sp->ats[0] ||
1678 *boundary -= seconds;
1680 *boundary += seconds;
1688 ttisp = &sp->
ttis[
i];
1703 ttisp = &sp->
ttis[
i];
1706 *boundary = sp->
ats[0];
1709 ttisp = &sp->
ttis[
i];
1721 int mid = (lo + hi) >> 1;
1723 if (t < sp->ats[mid])
1731 ttisp = &sp->
ttis[
j];
1734 *boundary = sp->
ats[
i];
1736 ttisp = &sp->
ttis[
j];
1763 const struct state *sp;
1765 const struct ttinfo *ttisp;
1781 if (strcmp(abbrev, abbrs + abbrind) == 0)
1783 while (abbrs[abbrind] !=
'\0')
1804 int mid = (lo + hi) >> 1;
1806 if (t < sp->ats[mid])
1818 for (
i = cutoff - 1;
i >= 0;
i--)
1858 const struct state *sp;
1902 if (!tt || tt->
tm_sec != 0)
#define unconstify(underlying_type, expr)
#define POSTGRES_EPOCH_JDATE
void err(int eval, const char *fmt,...)
int pg_open_tzfile(const char *name, char *canonname)
if(TABLE==NULL||TABLE_index==NULL)
static const char * getqzname(const char *strp, const int delim)
static struct pg_tm * localsub(struct state const *sp, pg_time_t const *timep, struct pg_tm *const tmp)
bool pg_tz_acceptable(pg_tz *tz)
static int leaps_thru_end_of(const int y)
int tzload(const char *name, char *canonname, struct state *sp, bool doextend)
static int tzloadbody(char const *name, char *canonname, struct state *sp, bool doextend, union local_storage *lsp)
int pg_next_dst_boundary(const pg_time_t *timep, long int *before_gmtoff, int *before_isdst, pg_time_t *boundary, long int *after_gmtoff, int *after_isdst, const pg_tz *tz)
const char * pg_get_timezone_name(pg_tz *tz)
static struct pg_tm * gmtsub(pg_time_t const *timep, int32 offset, struct pg_tm *tmp)
static int32 transtime(const int year, const struct rule *const rulep, const int32 offset)
static void gmtload(struct state *const sp)
static int leaps_thru_end_of_nonneg(int y)
static int64 leapcorr(struct state const *sp, pg_time_t t)
static struct pg_tm * timesub(pg_time_t const *timep, int32 offset, struct state const *sp, struct pg_tm *tmp)
bool pg_get_timezone_offset(const pg_tz *tz, long int *gmtoff)
static bool increment_overflow_time(pg_time_t *tp, int32 j)
static void init_ttinfo(struct ttinfo *s, int32 utoff, bool isdst, int desigidx)
static const char * getsecs(const char *strp, int32 *const secsp)
static const char * getnum(const char *strp, int *const nump, const int min, const int max)
static int32 detzcode(const char *const codep)
static bool differ_by_repeat(const pg_time_t t1, const pg_time_t t0)
static bool increment_overflow(int *ip, int j)
static int64 detzcode64(const char *const codep)
static const char * getzname(const char *strp)
static const char * getoffset(const char *strp, int32 *const offsetp)
static const char wildabbr[]
struct pg_tm * pg_localtime(const pg_time_t *timep, const pg_tz *tz)
static const int year_lengths[2]
static const int mon_lengths[2][MONSPERYEAR]
struct pg_tm * pg_gmtime(const pg_time_t *timep)
bool pg_interpret_timezone_abbrev(const char *abbrev, const pg_time_t *timep, long int *gmtoff, int *isdst, const pg_tz *tz)
static bool typesequiv(struct state const *sp, int a, int b)
bool tzparse(const char *name, struct state *sp, bool lastditch)
static const char * getrule(const char *strp, struct rule *const rulep)
#define TWOS_COMPLEMENT(t)
#define SECSPERREPEAT_BITS
#define TYPE_SIGNED(type)
char TZname[TZ_STRLEN_MAX+1]
struct ttinfo ttis[TZ_MAX_TYPES]
char chars[BIGGEST(BIGGEST(TZ_MAX_CHARS+1, 4),(2 *(TZ_STRLEN_MAX+1)))]
pg_time_t ats[TZ_MAX_TIMES]
struct lsinfo lsis[TZ_MAX_LEAPS]
unsigned char types[TZ_MAX_TIMES]
struct local_storage::file_analysis u
static unsigned char desigidx[TZ_MAX_TYPES]
static zic_t corr[TZ_MAX_LEAPS]