diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-07-18 00:59:27 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-18 00:59:27 +0900 |
commit | 68903df6f6fc548f3bf68fb09ee8b2495dcd28f0 (patch) | |
tree | eb641a38cb3b42b100c300be272c892f4bdca073 /time.c | |
parent | 64cff780051adf95a0f1799baddec98ae23e8add (diff) |
[Bug #18922] Normalize time at 24:00:00 UTC
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6146
Merged-By: nobu <nobu@ruby-lang.org>
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -654,6 +654,7 @@ static uint32_t month_arg(VALUE arg); 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) 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 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); |