diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-01 12:11:53 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-07-01 12:11:53 +0000 |
commit | 2f8b6234cd5b5a6b1bd5e2abdd07813e81f6e0c5 (patch) | |
tree | cebf4c2f6f68db02ce863e3c6f7c31de7b3008be /time.c | |
parent | ae9c138e2dc7723ec2c9ba6fc5fc8737f20043e2 (diff) | |
download | ruby-2f8b6234cd5b5a6b1bd5e2abdd07813e81f6e0c5.tar.gz |
* include/ruby/intern.h (rb_time_num_new): declared.
* time.c (nsec2timev): extracted from time_new_internal.
(time_new_internal): change argument to VALUE.
(rb_time_new): follow the argument change.
(rb_time_nano_new): ditto.
(rb_time_num_new): new function.
* ext/socket/ancdata.c (ancillary_timestamp): use rb_time_num_new to
represent struct bintime preciously.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23924 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 36 |
1 files changed, 29 insertions, 7 deletions
@@ -51,6 +51,7 @@ static VALUE time_utc_offset _((VALUE)); static long obj2long(VALUE obj); static VALUE obj2vint(VALUE obj); static int month_arg(VALUE arg); +static void validate_utc_offset(VALUE utc_offset); static void validate_vtm(struct vtm *vtm); static VALUE time_gmtime(VALUE); @@ -1451,18 +1452,24 @@ time_overflow_p(time_t *secp, long *nsecp) *nsecp = nsec; } +static VALUE nsec2timev(time_t sec, long nsec) +{ + struct timespec ts; + time_overflow_p(&sec, &nsec); + ts.tv_sec = sec; + ts.tv_nsec = nsec; + return timespec2timev(&ts); +} + static VALUE -time_new_internal(VALUE klass, time_t sec, long nsec) +time_new_internal(VALUE klass, VALUE timev) { VALUE time = time_s_alloc(klass); struct time_object *tobj; struct timespec ts; GetTimeval(time, tobj); - time_overflow_p(&sec, &nsec); - ts.tv_sec = sec; - ts.tv_nsec = nsec; - tobj->timev = timespec2timev(&ts); + tobj->timev = num_exact(timev); return time; } @@ -1470,13 +1477,28 @@ time_new_internal(VALUE klass, time_t sec, long nsec) VALUE rb_time_new(time_t sec, long usec) { - return time_new_internal(rb_cTime, sec, usec * 1000); + return time_new_internal(rb_cTime, nsec2timev(sec, usec * 1000)); } VALUE rb_time_nano_new(time_t sec, long nsec) { - return time_new_internal(rb_cTime, sec, nsec); + return time_new_internal(rb_cTime, nsec2timev(sec, nsec)); +} + +VALUE +rb_time_num_new(VALUE timev, VALUE off) +{ + VALUE time = time_new_internal(rb_cTime, timev); + + if (!NIL_P(off)) { + off = utc_offset_arg(off); + validate_utc_offset(off); + time_set_utc_offset(time, off); + return time; + } + + return time; } static VALUE |