3
3
* 1996-06-05 by Arthur David Olson.
6
* $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.20 2008/02/16 21:16:04 tgl Exp $
6
* $PostgreSQL: pgsql/src/timezone/localtime.c,v 1.21 2009/06/11 14:49:15 momjian Exp $
78
78
static long detzcode(const char *codep);
79
79
static pg_time_t detzcode64(const char *codep);
80
static int differ_by_repeat(pg_time_t t1, pg_time_t t0);
80
static int differ_by_repeat(pg_time_t t1, pg_time_t t0);
81
81
static const char *getzname(const char *strp);
82
82
static const char *getqzname(const char *strp, int delim);
83
83
static const char *getnum(const char *strp, int *nump, int min, int max);
85
85
static const char *getoffset(const char *strp, long *offsetp);
86
86
static const char *getrule(const char *strp, struct rule * rulep);
87
87
static void gmtload(struct state * sp);
88
static struct pg_tm *gmtsub(const pg_time_t *timep, long offset,
90
static struct pg_tm *localsub(const pg_time_t *timep, long offset,
91
struct pg_tm *tmp, const pg_tz *tz);
92
static int increment_overflow(int *number, int delta);
88
static struct pg_tm *gmtsub(const pg_time_t *timep, long offset,
90
static struct pg_tm *localsub(const pg_time_t *timep, long offset,
91
struct pg_tm * tmp, const pg_tz *tz);
92
static int increment_overflow(int *number, int delta);
93
93
static pg_time_t transtime(pg_time_t janfirst, int year,
94
const struct rule *rulep, long offset);
95
static int typesequiv(const struct state *sp, int a, int b);
94
const struct rule * rulep, long offset);
95
static int typesequiv(const struct state * sp, int a, int b);
96
96
static struct pg_tm *timesub(const pg_time_t *timep, long offset,
97
const struct state *sp, struct pg_tm *tmp);
97
const struct state * sp, struct pg_tm * tmp);
100
100
static struct state gmtmem;
143
143
differ_by_repeat(pg_time_t t1, pg_time_t t0)
145
145
if (TYPE_INTEGRAL(pg_time_t) &&
146
TYPE_BIT(pg_time_t) - TYPE_SIGNED(pg_time_t) < SECSPERREPEAT_BITS)
146
TYPE_BIT(pg_time_t) -TYPE_SIGNED(pg_time_t) <SECSPERREPEAT_BITS)
148
148
return t1 - t0 == SECSPERREPEAT;
194
194
(ttisgmtcnt != sp->typecnt && ttisgmtcnt != 0))
196
196
if (nread - (p - u.buf) <
197
sp->timecnt * stored + /* ats */
197
sp->timecnt * stored + /* ats */
198
198
sp->timecnt + /* types */
199
sp->typecnt * 6 + /* ttinfos */
199
sp->typecnt * 6 + /* ttinfos */
200
200
sp->charcnt + /* chars */
201
201
sp->leapcnt * (stored + 4) + /* lsinfos */
202
202
ttisstdcnt + /* ttisstds */
275
* Out-of-sort ats should mean we're running on a
276
* signed time_t system but using a data file with
277
* unsigned values (or vice versa).
276
* Out-of-sort ats should mean we're running on a signed time_t system
277
* but using a data file with unsigned values (or vice versa).
279
279
for (i = 0; i < sp->timecnt - 2; ++i)
280
280
if (sp->ats[i] > sp->ats[i + 1])
321
323
u.buf[0] == '\n' && u.buf[nread - 1] == '\n' &&
322
324
sp->typecnt + 2 <= TZ_MAX_TYPES)
327
329
u.buf[nread - 1] = '\0';
328
330
result = tzparse(&u.buf[1], &ts, FALSE);
329
331
if (result == 0 && ts.typecnt == 2 &&
372
typesequiv(const struct state *sp, int a, int b)
374
typesequiv(const struct state * sp, int a, int b)
376
378
if (sp == NULL ||
377
379
a < 0 || a >= sp->typecnt ||
987
989
static struct pg_tm *
988
990
localsub(const pg_time_t *timep, long offset,
989
struct pg_tm *tmp, const pg_tz *tz)
991
struct pg_tm * tmp, const pg_tz *tz)
991
993
const struct state *sp;
992
994
const struct ttinfo *ttisp;
1017
1020
seconds *= AVGSECSPERYEAR;
1018
1021
if (t < sp->ats[0])
1019
1022
newt += seconds;
1020
else newt -= seconds;
1021
1025
if (newt < sp->ats[0] ||
1022
1026
newt > sp->ats[sp->timecnt - 1])
1023
return NULL; /* "cannot happen" */
1027
return NULL; /* "cannot happen" */
1024
1028
result = localsub(&newt, offset, tmp, tz);
1025
1029
if (result == tmp)
1029
1033
newy = tmp->tm_year;
1030
1034
if (t < sp->ats[0])
1031
1035
newy -= icycles * YEARSPERREPEAT;
1032
else newy += icycles * YEARSPERREPEAT;
1037
newy += icycles * YEARSPERREPEAT;
1033
1038
tmp->tm_year = newy;
1034
1039
if (tmp->tm_year != newy)
1081
1087
* gmtsub is to gmtime as localsub is to localtime.
1083
1089
static struct pg_tm *
1084
gmtsub(const pg_time_t *timep, long offset, struct pg_tm *tmp)
1090
gmtsub(const pg_time_t *timep, long offset, struct pg_tm * tmp)
1086
1092
struct pg_tm *result;
1126
1132
static struct pg_tm *
1127
1133
timesub(const pg_time_t *timep, long offset,
1128
const struct state *sp, struct pg_tm *tmp)
1134
const struct state * sp, struct pg_tm * tmp)
1130
1136
const struct lsinfo *lp;
1131
1137
pg_time_t tdays;
1132
int idays; /* unsigned would be so 2003 */
1138
int idays; /* unsigned would be so 2003 */
1195
1201
seconds = tdays * SECSPERDAY + 0.5;
1196
1202
tdays = seconds / SECSPERDAY;
1197
1203
rem += seconds - tdays * SECSPERDAY;
1200
1207
* Given the range, we can now fearlessly cast...
1345
1354
seconds *= AVGSECSPERYEAR;
1346
1355
if (t < sp->ats[0])
1347
1356
newt += seconds;
1348
else newt -= seconds;
1349
1359
if (newt < sp->ats[0] ||
1350
1360
newt > sp->ats[sp->timecnt - 1])
1351
return -1; /* "cannot happen" */
1361
return -1; /* "cannot happen" */
1353
1363
result = pg_next_dst_boundary(&newt, before_gmtoff,