diff options
author | nagachika <nagachika@ruby-lang.org> | 2023-03-21 11:54:37 +0900 |
---|---|---|
committer | nagachika <nagachika@ruby-lang.org> | 2023-03-21 11:54:37 +0900 |
commit | 3efc43aace4e051f618b10e82bd82e93076dc757 (patch) | |
tree | 3a000067d79bdd69e07d48100b1469271bef4340 | |
parent | 0602df301cd76a3f1b444c4742b288bc6aed80ac (diff) | |
download | ruby-3efc43aace4e051f618b10e82bd82e93076dc757.tar.gz |
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 | 6 |
3 files changed, 27 insertions, 13 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 4a6ecea380..36c79273db 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_time_add() @@ -1765,6 +1765,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 { \ @@ -1776,11 +1777,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) { @@ -2038,19 +2049,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); @@ -2063,13 +2075,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; } } } @@ -2407,6 +2419,7 @@ time_init_args(rb_execution_context_t *ec, VALUE time, VALUE year, VALUE mon, VA 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,11 +11,11 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 4 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 193 +#define RUBY_PATCHLEVEL 194 #define RUBY_RELEASE_YEAR 2023 -#define RUBY_RELEASE_MONTH 2 -#define RUBY_RELEASE_DAY 23 +#define RUBY_RELEASE_MONTH 3 +#define RUBY_RELEASE_DAY 21 #include "ruby/version.h" |