Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite25f440

Browse files
committed
Sync our copy of the timezone library with IANA tzcode master.
This patch absorbs a few unreleased fixes in the IANA code.It corresponds to commit 2d8b944c1cec0808ac4f7a9ee1a463c28f9cd00ainhttps://github.com/eggert/tz. Non-cosmetic changes include:TZDEFRULESTRING is updated to match current US DST practice,rather than what it was over ten years ago. This only mattersfor interpretation of POSIX-style zone names (e.g., "EST5EDT"),and only if the timezone database doesn't include either an exactmatch for the zone name or a "posixrules" entry. The lattershould not be true in any current Postgres installation, butthis could possibly matter when using --with-system-tzdata.Get rid of a nonportable use of "++var" on a bool var.This is part of a larger fix that eliminates some vestigialsupport for consecutive leap seconds, and adds checks tothe "zic" compiler that the data files do not specify that.Remove a couple of ancient compatibility hacks. The IANAcrew think these are obsolete, and I tend to agree. Butperhaps our buildfarm will think different.Back-patch to all supported branches, in line with our policythat all branches should be using current IANA code. Before v10,this includes application of current pgindent rules, to avoidwhitespace problems in future back-patches.Discussion:https://postgr.es/m/E1dsWhf-0000pT-F9@gemulon.postgresql.org
1 parentea31541 commite25f440

File tree

5 files changed

+236
-204
lines changed

5 files changed

+236
-204
lines changed

‎src/timezone/localtime.c

Lines changed: 66 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@
2626
#ifndefWILDABBR
2727
/*
2828
* Someone might make incorrect use of a time zone abbreviation:
29-
*1.They might reference tzname[0] before calling tzset (explicitly
29+
*1.They might reference tzname[0] before calling tzset (explicitly
3030
*or implicitly).
31-
*2.They might reference tzname[1] before calling tzset (explicitly
31+
*2.They might reference tzname[1] before calling tzset (explicitly
3232
*or implicitly).
33-
*3.They might reference tzname[1] after setting to a time zone
33+
*3.They might reference tzname[1] after setting to a time zone
3434
*in which Daylight Saving Time is never observed.
35-
*4.They might reference tzname[0] after setting to a time zone
35+
*4.They might reference tzname[0] after setting to a time zone
3636
*in which Standard Time is never observed.
37-
*5.They might reference tm.TM_ZONE after calling offtime.
37+
*5.They might reference tm.TM_ZONE after calling offtime.
3838
* What's best to do in the above cases is open to debate;
3939
* for now, we just set things up so that in any of the five cases
4040
* WILDABBR is used. Another possibility: initialize tzname[0] to the
@@ -44,31 +44,27 @@
4444
* that tzname[0] has the "normal" length of three characters).
4545
*/
4646
#defineWILDABBR" "
47-
#endif/* !defined WILDABBR */
47+
#endif/* !defined WILDABBR */
4848

4949
staticconstcharwildabbr[]=WILDABBR;
5050

5151
staticconstchargmt[]="GMT";
5252

53-
/* The minimum and maximum finite time values. This assumes no padding. */
54-
staticconstpg_time_ttime_t_min=MINVAL(pg_time_t,TYPE_BIT(pg_time_t));
55-
staticconstpg_time_ttime_t_max=MAXVAL(pg_time_t,TYPE_BIT(pg_time_t));
56-
5753
/*
58-
* We cache the result of trying to load the TZDEFRULES zone here.
54+
*PG:We cache the result of trying to load the TZDEFRULES zone here.
5955
* tzdefrules_loaded is 0 if not tried yet, +1 if good, -1 if failed.
6056
*/
6157
staticstructstatetzdefrules_s;
6258
staticinttzdefrules_loaded=0;
6359

6460
/*
6561
* The DST rules to use if TZ has no rules and we can't load TZDEFRULES.
66-
*We defaultto US rules as of1999-08-17.
62+
*Defaultto US rules as of2017-05-07.
6763
* POSIX 1003.1 section 8.1.1 says that the default DST rules are
6864
* implementation dependent; for historical reasons, US rules are a
6965
* common default.
7066
*/
71-
#defineTZDEFRULESTRING ",M4.1.0,M10.5.0"
67+
#defineTZDEFRULESTRING ",M3.2.0,M11.1.0"
7268

7369
/* structs ttinfo, lsinfo, state have been moved to pgtz.h */
7470

@@ -112,7 +108,7 @@ static struct pg_tm tm;
112108

113109
/* Initialize *S to a value based on GMTOFF, ISDST, and ABBRIND. */
114110
staticvoid
115-
init_ttinfo(structttinfo*s,int32gmtoff,boolisdst,intabbrind)
111+
init_ttinfo(structttinfo*s,int32gmtoff,boolisdst,intabbrind)
116112
{
117113
s->tt_gmtoff=gmtoff;
118114
s->tt_isdst=isdst;
@@ -189,23 +185,23 @@ union input_buffer
189185

190186
/* The entire buffer. */
191187
charbuf[2*sizeof(structtzhead)+2*sizeof(structstate)
192-
+4*TZ_MAX_TIMES];
188+
+4*TZ_MAX_TIMES];
193189
};
194190

195191
/* Local storage needed for 'tzloadbody'. */
196192
unionlocal_storage
197193
{
198-
/* We don't need the "fullname" member */
199-
200194
/* The results of analyzing the file's contents after it is opened. */
201-
struct
195+
structfile_analysis
202196
{
203197
/* The input buffer. */
204198
unioninput_bufferu;
205199

206200
/* A temporary state used for parsing a TZ string in the file. */
207201
structstatest;
208202
}u;
203+
204+
/* We don't need the "fullname" member */
209205
};
210206

211207
/* Load tz data from the file named NAME into *SP. Read extended
@@ -215,8 +211,8 @@ union local_storage
215211
* given name is stored there (the buffer must be > TZ_STRLEN_MAX bytes!).
216212
*/
217213
staticint
218-
tzloadbody(charconst*name,char*canonname,structstate*sp,booldoextend,
219-
unionlocal_storage*lsp)
214+
tzloadbody(charconst*name,char*canonname,structstate*sp,booldoextend,
215+
unionlocal_storage*lsp)
220216
{
221217
inti;
222218
intfid;
@@ -255,6 +251,8 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
255251
{
256252
int32ttisstdcnt=detzcode(up->tzhead.tzh_ttisstdcnt);
257253
int32ttisgmtcnt=detzcode(up->tzhead.tzh_ttisgmtcnt);
254+
int64prevtr=0;
255+
int32prevcorr=0;
258256
int32leapcnt=detzcode(up->tzhead.tzh_leapcnt);
259257
int32timecnt=detzcode(up->tzhead.tzh_timecnt);
260258
int32typecnt=detzcode(up->tzhead.tzh_typecnt);
@@ -270,7 +268,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
270268
returnEINVAL;
271269
if (nread
272270
< (tzheadsize/* struct tzhead */
273-
+timecnt*stored/* ats */
271+
+timecnt*stored/* ats */
274272
+timecnt/* types */
275273
+typecnt*6/* ttinfos */
276274
+charcnt/* chars */
@@ -285,21 +283,21 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
285283

286284
/*
287285
* Read transitions, discarding those out of pg_time_t range. But
288-
* pretend the last transition beforetime_t_min occurred at
289-
*time_t_min.
286+
* pretend the last transition beforeTIME_T_MIN occurred at
287+
*TIME_T_MIN.
290288
*/
291289
timecnt=0;
292290
for (i=0;i<sp->timecnt;++i)
293291
{
294292
int64at
295293
=stored==4 ?detzcode(p) :detzcode64(p);
296294

297-
sp->types[i]=at <=time_t_max;
295+
sp->types[i]=at <=TIME_T_MAX;
298296
if (sp->types[i])
299297
{
300298
pg_time_tattime
301-
= ((TYPE_SIGNED(pg_time_t) ?at<time_t_min :at<0)
302-
?time_t_min :at);
299+
= ((TYPE_SIGNED(pg_time_t) ?at<TIME_T_MIN :at<0)
300+
?TIME_T_MIN :at);
303301

304302
if (timecnt&&attime <=sp->ats[timecnt-1])
305303
{
@@ -354,20 +352,22 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
354352
int32corr=detzcode(p+stored);
355353

356354
p+=stored+4;
357-
if (tr <=time_t_max)
355+
/* Leap seconds cannot occur before the Epoch. */
356+
if (tr<0)
357+
returnEINVAL;
358+
if (tr <=TIME_T_MAX)
358359
{
359-
pg_time_ttrans
360-
= ((TYPE_SIGNED(pg_time_t) ?tr<time_t_min :tr<0)
361-
?time_t_min :tr);
362-
363-
if (leapcnt&&trans <=sp->lsis[leapcnt-1].ls_trans)
364-
{
365-
if (trans<sp->lsis[leapcnt-1].ls_trans)
366-
returnEINVAL;
367-
leapcnt--;
368-
}
369-
sp->lsis[leapcnt].ls_trans=trans;
370-
sp->lsis[leapcnt].ls_corr=corr;
360+
/*
361+
* Leap seconds cannot occur more than once per UTC month, and
362+
* UTC months are at least 28 days long (minus 1 second for a
363+
* negative leap second). Each leap second's correction must
364+
* differ from the previous one's by 1 second.
365+
*/
366+
if (tr-prevtr<28*SECSPERDAY-1
367+
|| (corr!=prevcorr-1&&corr!=prevcorr+1))
368+
returnEINVAL;
369+
sp->lsis[leapcnt].ls_trans=prevtr=tr;
370+
sp->lsis[leapcnt].ls_corr=prevcorr=corr;
371371
leapcnt++;
372372
}
373373
}
@@ -508,7 +508,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
508508
}
509509

510510
/*
511-
* If type 0 isisunused in transitions, it's the type to use for early
511+
* If type 0 is unused in transitions, it's the type to use for early
512512
* times.
513513
*/
514514
for (i=0;i<sp->timecnt;++i)
@@ -553,7 +553,7 @@ tzloadbody(char const * name, char *canonname, struct state * sp, bool doextend,
553553
* given name is stored there (the buffer must be > TZ_STRLEN_MAX bytes!).
554554
*/
555555
int
556-
tzload(constchar*name,char*canonname,structstate*sp,booldoextend)
556+
tzload(constchar*name,char*canonname,structstate*sp,booldoextend)
557557
{
558558
unionlocal_storage*lsp=malloc(sizeof*lsp);
559559

@@ -569,7 +569,7 @@ tzload(const char *name, char *canonname, struct state * sp, bool doextend)
569569
}
570570

571571
staticbool
572-
typesequiv(conststructstate*sp,inta,intb)
572+
typesequiv(conststructstate*sp,inta,intb)
573573
{
574574
boolresult;
575575

@@ -737,7 +737,7 @@ getoffset(const char *strp, int32 *offsetp)
737737
* Otherwise, return a pointer to the first character not part of the rule.
738738
*/
739739
staticconstchar*
740-
getrule(constchar*strp,structrule*rulep)
740+
getrule(constchar*strp,structrule*rulep)
741741
{
742742
if (*strp=='J')
743743
{
@@ -788,7 +788,7 @@ getrule(const char *strp, struct rule * rulep)
788788
strp=getoffset(strp,&rulep->r_time);
789789
}
790790
else
791-
rulep->r_time=2*SECSPERHOUR;/* default = 2:00:00 */
791+
rulep->r_time=2*SECSPERHOUR;/* default = 2:00:00 */
792792
returnstrp;
793793
}
794794

@@ -797,7 +797,7 @@ getrule(const char *strp, struct rule * rulep)
797797
* effect, calculate the year-relative time that rule takes effect.
798798
*/
799799
staticint32
800-
transtime(intyear,conststructrule*rulep,
800+
transtime(intyear,conststructrule*rulep,
801801
int32offset)
802802
{
803803
boolleapyear;
@@ -894,7 +894,7 @@ transtime(int year, const struct rule * rulep,
894894
* Returns true on success, false on failure.
895895
*/
896896
bool
897-
tzparse(constchar*name,structstate*sp,boollastditch)
897+
tzparse(constchar*name,structstate*sp,boollastditch)
898898
{
899899
constchar*stdname;
900900
constchar*dstname=NULL;
@@ -921,7 +921,7 @@ tzparse(const char *name, struct state * sp, bool lastditch)
921921
stdlen= (sizeofsp->chars)-1;
922922
charcnt=stdlen+1;
923923
stdoffset=0;
924-
sp->goback=sp->goahead= false;/* simulate failed tzload() */
924+
sp->goback=sp->goahead= false;/* simulate failed tzload() */
925925
load_ok= false;
926926
}
927927
else
@@ -1217,7 +1217,7 @@ tzparse(const char *name, struct state * sp, bool lastditch)
12171217
}
12181218

12191219
staticvoid
1220-
gmtload(structstate*sp)
1220+
gmtload(structstate*sp)
12211221
{
12221222
if (tzload(gmt,NULL,sp, true)!=0)
12231223
tzparse(gmt,sp, true);
@@ -1231,8 +1231,8 @@ gmtload(struct state * sp)
12311231
* but it *is* desirable.)
12321232
*/
12331233
staticstructpg_tm*
1234-
localsub(structstateconst*sp,pg_time_tconst*timep,
1235-
structpg_tm*tmp)
1234+
localsub(structstateconst*sp,pg_time_tconst*timep,
1235+
structpg_tm*tmp)
12361236
{
12371237
conststructttinfo*ttisp;
12381238
inti;
@@ -1323,7 +1323,7 @@ pg_localtime(const pg_time_t *timep, const pg_tz *tz)
13231323
* Except we have a private "struct state" for GMT, so no sp is passed in.
13241324
*/
13251325
staticstructpg_tm*
1326-
gmtsub(pg_time_tconst*timep,int32offset,structpg_tm*tmp)
1326+
gmtsub(pg_time_tconst*timep,int32offset,structpg_tm*tmp)
13271327
{
13281328
structpg_tm*result;
13291329

@@ -1361,16 +1361,23 @@ pg_gmtime(const pg_time_t *timep)
13611361
* Return the number of leap years through the end of the given year
13621362
* where, to make the math easy, the answer for year zero is defined as zero.
13631363
*/
1364+
staticint
1365+
leaps_thru_end_of_nonneg(inty)
1366+
{
1367+
returny /4-y /100+y /400;
1368+
}
1369+
13641370
staticint
13651371
leaps_thru_end_of(constinty)
13661372
{
1367-
return (y >=0) ? (y /4-y /100+y /400) :
1368-
-(leaps_thru_end_of(-(y+1))+1);
1373+
return (y<0
1374+
?-1-leaps_thru_end_of_nonneg(-1-y)
1375+
:leaps_thru_end_of_nonneg(y));
13691376
}
13701377

13711378
staticstructpg_tm*
13721379
timesub(constpg_time_t*timep,int32offset,
1373-
conststructstate*sp,structpg_tm*tmp)
1380+
conststructstate*sp,structpg_tm*tmp)
13741381
{
13751382
conststructlsinfo*lp;
13761383
pg_time_ttdays;
@@ -1390,22 +1397,9 @@ timesub(const pg_time_t *timep, int32 offset,
13901397
lp=&sp->lsis[i];
13911398
if (*timep >=lp->ls_trans)
13921399
{
1393-
if (*timep==lp->ls_trans)
1394-
{
1395-
hit= ((i==0&&lp->ls_corr>0)||
1396-
lp->ls_corr>sp->lsis[i-1].ls_corr);
1397-
if (hit)
1398-
while (i>0&&
1399-
sp->lsis[i].ls_trans==
1400-
sp->lsis[i-1].ls_trans+1&&
1401-
sp->lsis[i].ls_corr==
1402-
sp->lsis[i-1].ls_corr+1)
1403-
{
1404-
++hit;
1405-
--i;
1406-
}
1407-
}
14081400
corr=lp->ls_corr;
1401+
hit= (*timep==lp->ls_trans
1402+
&& (i==0 ?0 :lp[-1].ls_corr)<corr);
14091403
break;
14101404
}
14111405
}
@@ -1529,13 +1523,13 @@ increment_overflow_time(pg_time_t *tp, int32 j)
15291523
{
15301524
/*----------
15311525
* This is like
1532-
* 'if (! (time_t_min <= *tp + j && *tp + j <=time_t_max)) ...',
1526+
* 'if (! (TIME_T_MIN <= *tp + j && *tp + j <=TIME_T_MAX)) ...',
15331527
* except that it does the right thing even if *tp + j would overflow.
15341528
*----------
15351529
*/
15361530
if (!(j<0
1537-
? (TYPE_SIGNED(pg_time_t) ?time_t_min-j <=*tp :-1-j<*tp)
1538-
:*tp <=time_t_max-j))
1531+
? (TYPE_SIGNED(pg_time_t) ?TIME_T_MIN-j <=*tp :-1-j<*tp)
1532+
:*tp <=TIME_T_MAX-j))
15391533
return true;
15401534
*tp+=j;
15411535
return false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp