Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include the invalid UTC offset in the error message #4864

Merged
merged 2 commits into from
Sep 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 17 additions & 15 deletions time.c
Original file line number Diff line number Diff line change
Expand Up @@ -2071,14 +2071,13 @@ maybe_tzobj_p(VALUE obj)
return TRUE;
}

NORETURN(static void invalid_utc_offset(void));
NORETURN(static void invalid_utc_offset(VALUE));
static void
invalid_utc_offset(void)
invalid_utc_offset(VALUE zone)
{
static const char message[] = "\"+HH:MM\", \"-HH:MM\", \"UTC\" "
"or \"A\"..\"I\",\"K\"..\"Z\" expected for utc_offset";
VALUE str = rb_usascii_str_new_static(message, sizeof(message)-1);
rb_exc_raise(rb_exc_new_str(rb_eArgError, str));
rb_raise(rb_eArgError, "\"+HH:MM\", \"-HH:MM\", \"UTC\" or "
"\"A\"..\"I\",\"K\"..\"Z\" expected for utc_offset: %"PRIsVALUE,
zone);
}

static VALUE
Expand Down Expand Up @@ -2346,7 +2345,7 @@ time_init_args(rb_execution_context_t *ec, VALUE time, VALUE year, VALUE mon, VA

vtm.isdst = VTM_ISDST_INITVAL;
vtm.utc_offset = Qnil;
VALUE arg = zone;
const VALUE arg = zone;
if (!NIL_P(arg)) {
zone = Qnil;
if (arg == ID2SYM(rb_intern("dst")))
Expand All @@ -2358,7 +2357,7 @@ time_init_args(rb_execution_context_t *ec, VALUE time, VALUE year, VALUE mon, VA
else if (!NIL_P(utc = utc_offset_arg(arg)))
vtm.utc_offset = utc == UTC_ZONE ? INT2FIX(0) : utc;
else if (NIL_P(zone = find_timezone(time, arg)))
invalid_utc_offset();
invalid_utc_offset(arg);
}

validate_vtm(&vtm);
Expand All @@ -2376,7 +2375,7 @@ time_init_args(rb_execution_context_t *ec, VALUE time, VALUE year, VALUE mon, VA
}
else if (NIL_P(vtm.utc_offset = utc_offset_arg(zone))) {
if (NIL_P(zone = find_timezone(time, zone)) || !zone_timelocal(zone, time))
invalid_utc_offset();
invalid_utc_offset(arg);
}
}

Expand Down Expand Up @@ -2509,9 +2508,10 @@ rb_time_num_new(VALUE timev, VALUE off)
if (zone_timelocal(zone, time)) return time;
}
if (NIL_P(off = utc_offset_arg(off))) {
if (NIL_P(zone = find_timezone(time, zone))) invalid_utc_offset();
off = zone;
if (NIL_P(zone = find_timezone(time, off))) invalid_utc_offset(off);
time_gmtime(time);
if (!zone_timelocal(zone, time)) invalid_utc_offset();
if (!zone_timelocal(zone, time)) invalid_utc_offset(off);
return time;
}
else if (off == UTC_ZONE) {
Expand Down Expand Up @@ -3751,8 +3751,9 @@ time_zonelocal(VALUE time, VALUE off)
if (zone_localtime(zone, time)) return time;

if (NIL_P(off = utc_offset_arg(off))) {
if (NIL_P(zone = find_timezone(time, zone))) invalid_utc_offset();
if (!zone_localtime(zone, time)) invalid_utc_offset();
off = zone;
if (NIL_P(zone = find_timezone(time, off))) invalid_utc_offset(off);
if (!zone_localtime(zone, time)) invalid_utc_offset(off);
return time;
}
else if (off == UTC_ZONE) {
Expand Down Expand Up @@ -3916,9 +3917,10 @@ time_getlocaltime(int argc, VALUE *argv, VALUE time)
}

if (NIL_P(off = utc_offset_arg(off))) {
if (NIL_P(zone = find_timezone(time, zone))) invalid_utc_offset();
off = zone;
if (NIL_P(zone = find_timezone(time, off))) invalid_utc_offset(off);
time = time_dup(time);
if (!zone_localtime(zone, time)) invalid_utc_offset();
if (!zone_localtime(zone, time)) invalid_utc_offset(off);
return time;
}
else if (off == UTC_ZONE) {
Expand Down