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:
Yukihiro "Matz" Matsumoto
2022-01-14 11:40:51 +09:00
parent 8f09d8feb4
commit 171d32c007
2 changed files with 11 additions and 5 deletions
+11 -1
View File
@@ -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);
-4
View File
@@ -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