method
at
ruby latest stable - Class:
Time
at(p1, p2 = v2, p3 = v3)public
Creates a new Time object with the value given by time, the given number of seconds_with_frac, or seconds and microseconds_with_frac since the Epoch. seconds_with_frac and microseconds_with_frac can be an Integer, Float, Rational, or other Numeric. non-portable feature allows the offset to be negative on some systems.
If a numeric argument is given, the result is in local time.
Time .at (0) #=> 1969年12月31日 18:00:00 -0600 Time .at (Time .at (0)) #=> 1969年12月31日 18:00:00 -0600 Time .at (946702800) #=> 1999年12月31日 23:00:00 -0600 Time .at (-284061600) #=> 1960年12月31日 00:00:00 -0600 Time .at (946684800.2).usec #=> 200000 Time .at (946684800, 123456.789).nsec #=> 123456789 Time .at (946684800, 123456789, :nsec).nsec #=> 123456789
static VALUE
time_s_at(int argc, VALUE *argv, VALUE klass)
{
VALUE time, t, unit = Qundef;
wideval_t timew;
if (rb_scan_args(argc, argv, "12", &time, &t, &unit) >= 2) {
int scale = argc == 3 ? get_scale(unit) : 1000000;
time = num_exact(time);
t = num_exact(t);
timew = wadd(rb_time_magnify(v2w(time)), wmulquoll(v2w(t), TIME_SCALE, scale));
t = time_new_timew(klass, timew);
}
else if (IsTimeval(time)) {
struct time_object *tobj, *tobj2;
GetTimeval(time, tobj);
t = time_new_timew(klass, tobj->timew);
GetTimeval(t, tobj2);
TIME_COPY_GMT(tobj2, tobj);
}
else {
timew = rb_time_magnify(v2w(num_exact(time)));
t = time_new_timew(klass, timew);
}
return t;
}