mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
time.c: 1969-12-31 23:59:59 is a valid time.
But `mktime(3)` for the date returns `-1` which happen to be the error value.
This commit is contained in:
@@ -483,7 +483,17 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
|
||||
nowsecs = mktime(&nowtime);
|
||||
}
|
||||
if (nowsecs == (time_t)-1) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "Not a valid time");
|
||||
nowtime.tm_sec += 1;
|
||||
if (timezone == MRB_TIMEZONE_UTC) {
|
||||
nowsecs = timegm(&nowtime);
|
||||
}
|
||||
else {
|
||||
nowsecs = mktime(&nowtime);
|
||||
}
|
||||
if (nowsecs != 0) {
|
||||
mrb_raise(mrb, E_ARGUMENT_ERROR, "Not a valid time");
|
||||
}
|
||||
nowsecs = (time_t)-1;
|
||||
}
|
||||
|
||||
return time_alloc_time(mrb, nowsecs, ausec, timezone);
|
||||
|
||||
@@ -267,7 +267,3 @@ assert('2000 times 500us make a second') do
|
||||
end
|
||||
assert_equal(0, t.usec)
|
||||
end
|
||||
|
||||
assert('Time.gm with Dec 31 23:59:59 1969 raise ArgumentError') do
|
||||
assert_raise(ArgumentError) {Time.gm(1969, 12, 31, 23, 59, 59)}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user