unstick r67836

Revision 67836

Date:
2019/12/18 13:41:48
Author:
nagachika
Revision Log:
merge revision(s) d6a2bce64a7fa1099e507e1d36b5f1533f42f60f,c687be4bc01c9ce52ea990945d9304d6fe59fe9b: [Backport #16159]

time.c (find_time_t): fix round-to-zero bug

`find_time_t` did not work correctly for year older than the Epoch
because it used C's integer division (which rounds negative to zero).

For example, `TIme.new(1933)` returned a wrong time whose year is 1922
in Asia/Kuala_Lumpur because there is no 00:00:00 1st Jan. 1933 in the
time zone.

```
$ TZ=Asia/Kuala_Lumpur ruby -e 'p Time.new(1933)'
1932-12-31 00:00:00 +0700
```

This change fixes the issue by using `DIV` macro instead of `/`.
Now `Time.new(1933)` returns a time in 1933.

```
$ TZ=Asia/Kuala_Lumpur ruby -e 'p Time.new(1933)'
1933-01-01 00:20:00 +0720
```

[Bug #16159]

Added a test for [Bug #16159]
Files:

Legend:

 
Added
 
Removed
 
Modified
  • branches/ruby_2_6/test/ruby/test_time_tz.rb

     
    156 156 }
    157 157 end
    158 158
    159 def test_asia_kuala_lumpur
    160 with_tz(tz="Asia/Kuala_Lumpur") {
    161 assert_time_constructor(tz, "1933-01-01 00:20:00 +0720", :local, [1933])
    162 }
    163 end
    164
    159 165 def test_canada_newfoundland
    160 166 with_tz(tz="America/St_Johns") {
    161 167 assert_time_constructor(tz, "2007-11-03 23:00:59 -0230", :new, [2007,11,3,23,0,59,:dst])
  • branches/ruby_2_6/time.c

     
    3273 3273
    3274 3274 *tp = guess_lo +
    3275 3275 ((tptr->tm_year - tm_lo.tm_year) * 365 +
    3276 ((tptr->tm_year-69)/4) -
    3277 ((tptr->tm_year-1)/100) +
    3278 ((tptr->tm_year+299)/400) -
    3279 ((tm_lo.tm_year-69)/4) +
    3280 ((tm_lo.tm_year-1)/100) -
    3281 ((tm_lo.tm_year+299)/400) +
    3276 DIV((tptr->tm_year-69), 4) -
    3277 DIV((tptr->tm_year-1), 100) +
    3278 DIV((tptr->tm_year+299), 400) -
    3279 DIV((tm_lo.tm_year-69), 4) +
    3280 DIV((tm_lo.tm_year-1), 100) -
    3281 DIV((tm_lo.tm_year+299), 400) +
    3282 3282 tptr_tm_yday -
    3283 3283 tm_lo.tm_yday) * 86400 +
    3284 3284 (tptr->tm_hour - tm_lo.tm_hour) * 3600 +
  • branches/ruby_2_6/version.h

     
    1 1 #define RUBY_VERSION "2.6.6"
    2 2 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
    3 #define RUBY_PATCHLEVEL 123
    3 #define RUBY_PATCHLEVEL 124
    4 4
    5 5 #define RUBY_RELEASE_YEAR 2019
    6 6 #define RUBY_RELEASE_MONTH 12
    7 #define RUBY_RELEASE_DAY 15
    7 #define RUBY_RELEASE_DAY 18
    8 8
    9 9 #include "ruby/version.h"
    10 10