diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/time.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/time.c b/src/time.c index 8f9e6dd0c..c988d0fd0 100644 --- a/src/time.c +++ b/src/time.c @@ -167,10 +167,14 @@ mrb_time_alloc(mrb_state *mrb, mrb_float sec, mrb_float usec, enum mrb_timezone tm = mrb_malloc(mrb, sizeof(struct mrb_time)); tm->sec = (time_t)sec; tm->usec = (sec - tm->sec) * 1.0e6 + usec; - if (tm->usec < 0) { + while (tm->usec < 0) { tm->sec--; tm->usec += 1.0e6; } + while (tm->usec > 1.0e6) { + tm->sec++; + tm->usec -= 1.0e6; + } tm->timezone = timezone; mrb_time_update_datetime(tm); |
