ruby-changes:72584
From: Nobuyoshi <ko1@a...>
Date: Mon, 18 Jul 2022 00:59:51 +0900 (JST)
Subject: [ruby-changes:72584] 68903df6f6 (master): [Bug #18922] Normalize time at 24:00:00 UTC
https://git.ruby-lang.org/ruby.git/commit/?id=68903df6f6 From 68903df6f6fc548f3bf68fb09ee8b2495dcd28f0 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Mon, 18 Jul 2022 00:59:27 +0900 Subject: [Bug #18922] Normalize time at 24:00:00 UTC --- test/ruby/test_time.rb | 2 ++ time.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 8300681fe5..4af4cf5474 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -53,6 +53,8 @@ class TestTime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_time.rb#L53 assert_raise_with_message(ArgumentError, msg) { Time.new(2021, 1, 1, "+09:99") } 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]) end def test_time_add() diff --git a/time.c b/time.c index 56dfb5d8a3..b03baa2c22 100644 --- a/time.c +++ b/time.c @@ -654,6 +654,7 @@ static uint32_t month_arg(VALUE arg); https://github.com/ruby/ruby/blob/trunk/time.c#L654 static VALUE validate_utc_offset(VALUE utc_offset); static VALUE validate_zone_name(VALUE zone_name); static void validate_vtm(struct vtm *vtm); +static void vtm_add_day(struct vtm *vtm, int day); static uint32_t obj2subsecx(VALUE obj, VALUE *subsecx); static VALUE time_gmtime(VALUE); @@ -2032,6 +2033,12 @@ vtm_add_offset(struct vtm *vtm, VALUE off, int sign) https://github.com/ruby/ruby/blob/trunk/time.c#L2033 vtm->hour = hour; } + vtm_add_day(vtm, day); +} + +static void +vtm_add_day(struct vtm *vtm, int day) +{ if (day) { if (day < 0) { if (vtm->mon == 1 && vtm->mday == 1) { @@ -2393,6 +2400,13 @@ time_init_args(rb_execution_context_t *ec, VALUE time, VALUE year, VALUE mon, VA https://github.com/ruby/ruby/blob/trunk/time.c#L2400 if (utc == UTC_ZONE) { tobj->timew = timegmw(&vtm); + if (vtm.hour == 24) { /* special case: 24:00:00 only */ + /* Since no need to take care of DST in UTC, just reset + * hour and advance date, not to discard the validated + * vtm. */ + vtm.hour = 0; + vtm_add_day(&vtm, 1); + } tobj->vtm = vtm; tobj->tm_got = 1; TZMODE_SET_UTC(tobj); -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/