8000 Time.at in: tz · github/ruby@ab73b30 · GitHub
[go: up one dir, main page]

Skip to content

Commit ab73b30

Browse files
committed
Time.at in: tz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66078 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent bdfc701 commit ab73b30

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

test/ruby/test_time_tz.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,11 +547,11 @@ def subtest_plus(time_class, tz, tzarg, tzname, abbr, utc_offset)
547547
def subtest_at(time_class, tz, tzarg, tzname, abbr, utc_offset)
548548
h, m = (utc_offset / 60).divmod(60)
549549
utc = time_class.utc(2018, 9, 1, 12, 0, 0)
550-
t = time_class.at(utc, tzarg)
550+
t = time_class.at(utc, in: tzarg)
551551
assert_equal([2018, 9, 1, 12+h, m, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone])
552552
assert_equal(utc.to_i, t.to_i)
553553
utc = utc.to_i
554-
t = time_class.at(utc, tzarg)
554+
t = time_class.at(utc, in: tzarg)
555555
assert_equal([2018, 9, 1, 12+h, m, 0, tz], [t.year, t.mon, t.mday, t.hour, t.min, t.sec, t.zone])
556556
assert_equal(utc, t.to_i)
557557
end

time.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,7 @@ get_scale(VALUE unit)
26862686
* can be an Integer, Float, Rational, or other Numeric.
26872687
* non-portable feature allows the offset to be negative on some systems.
26882688
*
2689-
* If +tz+ argument is given, the result is in that timezone or UTC offset, or
2689+
* If +in+ argument is given, the result is in that timezone or UTC offset, or
26902690
* if a numeric argument is given, the result is in local time.
26912691
*
26922692
* Time.at(0) #=> 1969-12-31 18:00:00 -0600
@@ -2701,13 +2701,19 @@ get_scale(VALUE unit)
27012701
static VALUE
27022702
time_s_at(int argc, VALUE *argv, VALUE klass)
27032703
{
2704-
VALUE time, t, unit = Qundef, zone = Qnil;
2704+
VALUE time, t, unit = Qundef, zone = Qundef, opts;
27052705
wideval_t timew;
27062706

2707-
if (argc > 1 && rb_obj_respond_to(argv[argc-1], id_utc_to_local, Qfalse)) {
2708-
zone = argv[--argc];
2707+
argc = rb_scan_args(argc, argv, "12:", &time, &t, &unit, &opts);
2708+
if (!NIL_P(opts)) {
2709+
ID ids[1];
2710+
VALUE vals[numberof(ids)];
2711+
2712+
CONST_ID(ids[0], "in");
2713+
rb_get_kwargs(opts, ids, 0, 1, vals);
2714+
zone = vals[0];
27092715
}
2710-
if (rb_scan_args(argc, argv, "12", &time, &t, &unit) >= 2) {
2716+
if (argc >= 2) {
27112717
int scale = argc == 3 ? get_scale(unit) : 1000000;
27122718
time = num_exact(time);
27132 6C09 719
t = num_exact(t);
@@ -2725,7 +2731,7 @@ time_s_at(int argc, VALUE *argv, VALUE klass)
27252731
timew = rb_time_magnify(v2w(num_exact(time)));
27262732
t = time_new_timew(klass, timew);
27272733
}
2728-
if (!NIL_P(zone)) {
2734+
if (zone != Qundef) {
27292735
time_zonelocal(t, zone);
27302736
}
27312737

0 commit comments

Comments
 (0)
0