diff options
author | NARUSE, Yui <naruse@airemix.jp> | 2023-01-17 11:21:00 +0900 |
---|---|---|
committer | NARUSE, Yui <naruse@airemix.jp> | 2023-01-17 11:21:00 +0900 |
commit | 89cd61890fe78e0491708f87a5df678b03fda8a3 (patch) | |
tree | 2152c0a7b73d0508db05496521f3a62537955ed6 | |
parent | 49cf0896a2934547c0764aadaec021fb37a2e96f (diff) |
merge revision(s) 542e984d82fa25098eb15398d716d907acc52b93: [Backport #19292]
[Bug #19292] Re-initialize tm when wday or yday is not set
---
test/ruby/test_time.rb | 3 ++-
time.c | 31 ++++++++++++++++++++++---------
2 files changed, 24 insertions(+), 10 deletions(-)
-rw-r--r-- | test/ruby/test_time.rb | 3 | ||||
-rw-r--r-- | time.c | 31 | ||||
-rw-r--r-- | version.h | 2 |
3 files changed, 25 insertions, 11 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 0977fea55f..8274dbbc83 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -54,7 +54,8 @@ class TestTime < Test::Unit::TestCase assert_raise_with_message(ArgumentError, msg) { Time.new(2021, 1, "+09:99") } assert_raise_with_message(ArgumentError, msg) { Time.new(2021, "+09:99") } - assert_equal([0, 0, 0, 2, 1, 2000], Time.new(2000, 1, 1, 24, 0, 0, "-00:00").to_a[0, 6]) + assert_equal([0, 0, 0, 1, 1, 2000, 6, 1, false, "UTC"], Time.new(2000, 1, 1, 0, 0, 0, "-00:00").to_a) + assert_equal([0, 0, 0, 2, 1, 2000, 0, 2, false, "UTC"], Time.new(2000, 1, 1, 24, 0, 0, "-00:00").to_a) end def test_new_from_string @@ -1790,6 +1790,7 @@ PACKED_STRUCT_UNALIGNED(struct time_object { (tobj1)->vtm.utc_offset = (tobj2)->vtm.utc_offset, \ (tobj1)->vtm.zone = (tobj2)->vtm.zone) +static int zone_localtime(VALUE zone, VALUE time); static VALUE time_get_tm(VALUE, struct time_object *); #define MAKE_TM(time, tobj) \ do { \ @@ -1801,11 +1802,21 @@ static VALUE time_get_tm(VALUE, struct time_object *); do { \ MAKE_TM(time, tobj); \ if (!(cond)) { \ - VALUE zone = (tobj)->vtm.zone; \ - if (!NIL_P(zone)) zone_localtime(zone, (time)); \ + force_make_tm(time, tobj); \ } \ } while (0) +static inline void +force_make_tm(VALUE time, struct time_object *tobj) +{ + VALUE zone = tobj->vtm.zone; + if (!NIL_P(zone) && zone != str_empty && zone != str_utc) { + if (zone_localtime(zone, time)) return; + } + tobj->tm_got = 0; + time_get_tm(time, tobj); +} + static void time_mark(void *ptr) { @@ -2070,19 +2081,20 @@ vtm_add_day(struct vtm *vtm, int day) vtm->mday = 31; vtm->mon = 12; /* December */ vtm->year = subv(vtm->year, INT2FIX(1)); - vtm->yday = leap_year_v_p(vtm->year) ? 366 : 365; + if (vtm->yday != 0) + vtm->yday = leap_year_v_p(vtm->year) ? 366 : 365; } else if (vtm->mday == 1) { const int8_t *days_in_month = days_in_month_in_v(vtm->year); vtm->mon--; vtm->mday = days_in_month[vtm->mon-1]; - vtm->yday--; + if (vtm->yday != 0) vtm->yday--; } else { vtm->mday--; - vtm->yday--; + if (vtm->yday != 0) vtm->yday--; } - vtm->wday = (vtm->wday + 6) % 7; + if (vtm->wday != VTM_WDAY_INITVAL) vtm->wday = (vtm->wday + 6) % 7; } else { int leap = leap_year_v_p(vtm->year); @@ -2095,13 +2107,13 @@ vtm_add_day(struct vtm *vtm, int day) else if (vtm->mday == days_in_month_of(leap)[vtm->mon-1]) { vtm->mon++; vtm->mday = 1; - vtm->yday++; + if (vtm->yday != 0) vtm->yday++; } else { vtm->mday++; - vtm->yday++; + if (vtm->yday != 0) vtm->yday++; } - vtm->wday = (vtm->wday + 1) % 7; + if (vtm->wday != VTM_WDAY_INITVAL) vtm->wday = (vtm->wday + 1) % 7; } } } @@ -2449,6 +2461,7 @@ time_init_vtm(VALUE time, struct vtm vtm, VALUE zone) if (utc == UTC_ZONE) { tobj->timew = timegmw(&vtm); + vtm.isdst = 0; /* No DST in UTC */ vtm_day_wraparound(&vtm); tobj->vtm = vtm; tobj->tm_got = 1; @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 3 +#define RUBY_PATCHLEVEL 4 #include "ruby/version.h" #include "ruby/internal/abi.h" |