treat exceptional usec value

This commit is contained in:
Yukihiro Matsumoto
2012-07-23 23:25:00 +09:00
parent fcc64c9f93
commit 328353b287
+5 -1
View File
@@ -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);