Fix leap day with UTC offset [Bug #18274]

`struct vtm::year` is a Ruby integer instance, but not a C integer
type.
This commit is contained in:
Nobuyoshi Nakada 2021-10-28 12:06:34 +09:00
Родитель 77544caaf4
Коммит 1d666ed50f
2 изменённых файлов: 3 добавлений и 1 удалений

Просмотреть файл

@ -39,6 +39,7 @@ class TestTime < Test::Unit::TestCase
def test_new def test_new
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, 3600*11)) assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, 3600*11))
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,9, 13,0,0, -3600*11)) assert_equal(Time.utc(2000,2,10), Time.new(2000,2,9, 13,0,0, -3600*11))
assert_equal(Time.utc(2000,2,29,23,0,0), Time.new(2000, 3, 1, 0, 0, 0, 3600))
assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, "+11:00")) assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, "+11:00"))
assert_equal(Rational(1,2), Time.new(2000,2,10, 11,0,5.5, "+11:00").subsec) assert_equal(Rational(1,2), Time.new(2000,2,10, 11,0,5.5, "+11:00").subsec)
bug4090 = '[ruby-dev:42631]' bug4090 = '[ruby-dev:42631]'

3
time.c
Просмотреть файл

@ -784,6 +784,7 @@ static const int8_t leap_year_days_in_month[] = {
#define days_in_month_of(leap) ((leap) ? leap_year_days_in_month : common_year_days_in_month) #define days_in_month_of(leap) ((leap) ? leap_year_days_in_month : common_year_days_in_month)
#define days_in_month_in(y) days_in_month_of(leap_year_p(y)) #define days_in_month_in(y) days_in_month_of(leap_year_p(y))
#define days_in_month_in_v(y) days_in_month_of(leap_year_v_p(y))
#define M28(m) \ #define M28(m) \
(m),(m),(m),(m),(m),(m),(m),(m),(m),(m), \ (m),(m),(m),(m),(m),(m),(m),(m),(m),(m), \
@ -2033,7 +2034,7 @@ vtm_add_offset(struct vtm *vtm, VALUE off, int sign)
vtm->yday = leap_year_v_p(vtm->year) ? 366 : 365; vtm->yday = leap_year_v_p(vtm->year) ? 366 : 365;
} }
else if (vtm->mday == 1) { else if (vtm->mday == 1) {
const int8_t *days_in_month = days_in_month_in(vtm->year); const int8_t *days_in_month = days_in_month_in_v(vtm->year);
vtm->mon--; vtm->mon--;
vtm->mday = days_in_month[vtm->mon-1]; vtm->mday = days_in_month[vtm->mon-1];
vtm->yday--; vtm->yday--;