Skip to content

Commit

Permalink
time.c: remove duplicated UTC condition check.
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Jan 15, 2022
1 parent 171d32c commit 475b868
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions mrbgems/mruby-time/src/time.c
Expand Up @@ -476,24 +476,21 @@ time_mktime(mrb_state *mrb, mrb_int ayear, mrb_int amonth, mrb_int aday,
nowtime.tm_sec = (int)asec;
nowtime.tm_isdst = -1;

time_t (*mk)(struct tm*);
if (timezone == MRB_TIMEZONE_UTC) {
nowsecs = timegm(&nowtime);
mk = timegm;
}
else {
nowsecs = mktime(&nowtime);
mk = mktime;
}
nowsecs = (*mk)(&nowtime);
if (nowsecs == (time_t)-1) {
nowtime.tm_sec += 1;
if (timezone == MRB_TIMEZONE_UTC) {
nowsecs = timegm(&nowtime);
}
else {
nowsecs = mktime(&nowtime);
}
if (nowsecs != 0) {
nowtime.tm_sec += 1; /* maybe Epoch-1 sec */
nowsecs = (*mk)(&nowtime);
if (nowsecs != 0) { /* check if Epoch */
mrb_raise(mrb, E_ARGUMENT_ERROR, "Not a valid time");
}
nowsecs = (time_t)-1;
nowsecs = (time_t)-1; /* valid Epoch-1 */
}

return time_alloc_time(mrb, nowsecs, ausec, timezone);
Expand Down

0 comments on commit 475b868

Please sign in to comment.