summaryrefslogtreecommitdiffhomepage
path: root/src/time.c
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-07-23 23:25:00 +0900
committerYukihiro Matsumoto <[email protected]>2012-07-23 23:25:00 +0900
commit328353b287bcacf29108766f8f89891bb1cf3281 (patch)
tree3404338527f1e07af99fdb8d14dbd50827c41ce0 /src/time.c
parentfcc64c9f93c2ea78763887772a79edf7c05fb5b5 (diff)
downloadmruby-328353b287bcacf29108766f8f89891bb1cf3281.tar.gz
mruby-328353b287bcacf29108766f8f89891bb1cf3281.zip
treat exceptional usec value
Diffstat (limited to 'src/time.c')
-rw-r--r--src/time.c6
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);