Project

General

Profile

Bug #18293 ยป patch.diff

k0kubun (Takashi Kokubun), 11/10/2021 04:23 AM

View differences:

time.c
return t;
}
enum {
TMOPT_IN,
TMOPT_MAX_
};
static bool
get_tmopt(VALUE opts, VALUE vals[TMOPT_MAX_])
{
ID ids[TMOPT_MAX_];
if (NIL_P(opts)) return false;
CONST_ID(ids[TMOPT_IN], "in");
rb_get_kwargs(opts, ids, 0, TMOPT_MAX_, vals);
return true;
}
static VALUE
time_s_at_c(int argc, VALUE *argv, VALUE klass)
{
VALUE time, t, unit = Qundef, zone = Qundef, opts;
VALUE vals[TMOPT_MAX_];
wideval_t timew;
argc = rb_scan_args(argc, argv, "12:", &time, &t, &unit, &opts);
if (get_tmopt(opts, vals)) {
zone = vals[0];
}
if (argc >= 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);
TZMODE_COPY(tobj2, tobj);
}
else {
timew = rb_time_magnify(v2w(num_exact(time)));
t = time_new_timew(klass, timew);
}
if (zone != Qundef) {
time_zonelocal(t, zone);
}
return t;
}
static const char months[][4] = {
"jan", "feb", "mar", "apr", "may", "jun",
"jul", "aug", "sep", "oct", "nov", "dec",
......
rb_include_module(rb_cTime, rb_mComparable);
rb_define_alloc_func(rb_cTime, time_s_alloc);
rb_define_singleton_method(rb_cTime, "at_c", time_s_at_c, -1);
rb_define_singleton_method(rb_cTime, "utc", time_s_mkutc, -1);
rb_define_singleton_method(rb_cTime, "local", time_s_mktime, -1);
rb_define_alias(rb_singleton_class(rb_cTime), "gm", "utc");
timev.rb
__builtin.time_s_at(time, subsec, unit, __builtin.arg!(:in), nosubsec, nounit)
end
def self.at_1arg(time)
__builtin.time_s_at(time, true, true, nil, true, true)
end
# Returns a new \Time object based the on given arguments.
#
# With no positional arguments, returns the value of Time.now:
    (1-1/1)