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

Commitc62b8ea

Browse files
committed
Fix edge-case behavior of pg_next_dst_boundary().
Due to rather sloppy thinking (on my part, I'm afraid) about theappropriate behavior for boundary conditions, pg_next_dst_boundary() gaveundefined, platform-dependent results when the input time is exactly thelast recorded DST transition time for the specified time zone, as a resultof fetching values one past the end of its data arrays.Change its specification to be that it always finds the next DST boundary*after* the input time, and adjust code to match that. The sole existingcaller, DetermineTimeZoneOffset, doesn't actually care about thisdistinction, since it always uses a probe time earlier than the instantthat it does care about. So it seemed best to me to change the API to makethe result=1 and result=0 cases more consistent, specifically to ensurethat the "before" outputs always describe the state at the given time,rather than hacking the code to obey the previous API comment exactly.Per bug #6605 from Sergey Burladyan. Back-patch to all supported versions.
1 parentca1e1a8 commitc62b8ea

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

‎src/timezone/localtime.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,20 +1292,21 @@ increment_overflow(int *number, int delta)
12921292
}
12931293

12941294
/*
1295-
* Find the next DST transition timeat orafter the given time
1295+
* Find the next DST transition time after the given time
12961296
*
12971297
* *timep is the input value, the other parameters are output values.
12981298
*
12991299
* When the function result is 1, *boundary is set to the time_t
1300-
* representation of the next DST transition timeat orafter *timep,
1300+
* representation of the next DST transition time after *timep,
13011301
* *before_gmtoff and *before_isdst are set to the GMT offset and isdst
1302-
* state prevailing just before that boundary, and *after_gmtoff and
1303-
* *after_isdst are set to the state prevailing just after that boundary.
1302+
* state prevailing just before that boundary (in particular, the state
1303+
* prevailing at *timep), and *after_gmtoff and *after_isdst are set to
1304+
* the state prevailing just after that boundary.
13041305
*
1305-
* When the function result is 0, there is no known DST transition at or
1306+
* When the function result is 0, there is no known DST transition
13061307
* after *timep, but *before_gmtoff and *before_isdst indicate the GMT
13071308
* offset and isdst state prevailing at *timep. (This would occur in
1308-
* DST-less time zones,for example.)
1309+
* DST-less time zones,or if a zone has permanently ceased using DST.)
13091310
*
13101311
* A function result of -1 indicates failure (this case does not actually
13111312
* occur in our current implementation).
@@ -1385,16 +1386,16 @@ pg_next_dst_boundary(const pg_time_t *timep,
13851386
returnresult;
13861387
}
13871388

1388-
if (t>sp->ats[sp->timecnt-1])
1389+
if (t >=sp->ats[sp->timecnt-1])
13891390
{
1390-
/* No known transition >= t, so use last known segment's type */
1391+
/* No known transition > t, so use last known segment's type */
13911392
i=sp->types[sp->timecnt-1];
13921393
ttisp=&sp->ttis[i];
13931394
*before_gmtoff=ttisp->tt_gmtoff;
13941395
*before_isdst=ttisp->tt_isdst;
13951396
return0;
13961397
}
1397-
if (t <=sp->ats[0])
1398+
if (t<sp->ats[0])
13981399
{
13991400
/* For "before", use lowest-numbered standard type */
14001401
i=0;
@@ -1415,10 +1416,10 @@ pg_next_dst_boundary(const pg_time_t *timep,
14151416
*after_isdst=ttisp->tt_isdst;
14161417
return1;
14171418
}
1418-
/* Else search to find thecontaining segment */
1419+
/* Else search to find theboundary following t */
14191420
{
14201421
intlo=1;
1421-
inthi=sp->timecnt;
1422+
inthi=sp->timecnt-1;
14221423

14231424
while (lo<hi)
14241425
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp