1 #include "ruby.h"
2
3 static VALUE
bug_time_s_nano_new(VALUE klass,VALUE sec,VALUE nsec)4 bug_time_s_nano_new(VALUE klass, VALUE sec, VALUE nsec)
5 {
6 return rb_time_nano_new(NUM2TIMET(sec), NUM2LONG(nsec));
7 }
8
9 static VALUE
bug_time_s_timespec_new(VALUE klass,VALUE sec,VALUE nsec,VALUE gmtoff)10 bug_time_s_timespec_new(VALUE klass, VALUE sec, VALUE nsec, VALUE gmtoff)
11 {
12 struct timespec ts;
13 ts.tv_sec = NUM2TIMET(sec);
14 ts.tv_nsec = NUM2LONG(nsec);
15 return rb_time_timespec_new(&ts, NUM2INT(gmtoff));
16 }
17
18 static VALUE
bug_time_s_timespec_now(VALUE klass)19 bug_time_s_timespec_now(VALUE klass)
20 {
21 struct timespec ts;
22 VALUE v;
23 rb_timespec_now(&ts);
24 v = rb_Rational(LONG2NUM(ts.tv_nsec), LONG2NUM(1000000000L));
25 return rb_num_coerce_bin(TIMET2NUM(ts.tv_sec), v, '+');
26 }
27
28 void
Init_time_new(VALUE klass)29 Init_time_new(VALUE klass)
30 {
31 rb_define_singleton_method(klass, "nano_new", bug_time_s_nano_new, 2);
32 rb_define_singleton_method(klass, "timespec_new", bug_time_s_timespec_new, 3);
33 rb_define_singleton_method(klass, "timespec_now", bug_time_s_timespec_now, 0);
34 }
35