Просмотр исходного кода

libc: time: use the right length for a 400-year cycle in mktime

_time_mktime_tzi() splits tm_year into whole 400-year blocks and a
remainder, then multiplies the blocks by their length in days.  A
Gregorian 400-year cycle is 146097 days; the constant said 146073, so
every complete block lost 24 days.

The first complete block is reached at tm_year 400, which is why nothing
before the year 2300 could see it:

  mktime(2299-12-31) = 10413705600   correct
  mktime(2300-01-01) = 10411718400   24 days short
  mktime(2700-01-01) = 23032425600   48 days short, two blocks

Measured against glibc on i686 (UCLIBC_USE_TIME64) and x86_64; both were
identical, so this is not specific to the time64 layer.  gmtime() and
localtime() were right all along, which makes mktime(gmtime(t)) != t.

Checked at every 400-year block boundary from 1970 to 3000, in both
directions through gmtime().

Signed-off-by: Ramin Moussavi <lordrasmus@gmail.com>
ramin 3 дней назад
Родитель
Сommit
49d3983dda
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      libc/misc/time/time.c

+ 1 - 1
libc/misc/time/time.c

@@ -2513,7 +2513,7 @@ DST_CORRECT:
 		+ tzi[default_dst].gmt_offset
 		+ 60*( p[1]
 			   + 60*(p[2]
-					 + 24*(((146073L * ((long long)(p[6])) + d)
+					 + 24*(((146097L * ((long long)(p[6])) + d)
 							+ p[3]) + p[7])));
 
 DST_CORRECT: