From a5c201dde63c08f6e15efbeab77e7f985d1a7eac Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Fri, 5 Jul 2019 13:55:04 -0700 Subject: [PATCH] Handle Time#{dst?,isdst} for time's with timezone objects by delegation Fixes [Bug #15988] --- time.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/time.c b/time.c index 3ed694fe23..83b3fb1192 100644 --- a/time.c +++ b/time.c @@ -4647,6 +4647,10 @@ time_isdst(VALUE time) GetTimeval(time, tobj); MAKE_TM(time, tobj); + if ((RB_BUILTIN_TYPE(tobj->vtm.zone) != RUBY_T_STRING) && + rb_respond_to(tobj->vtm.zone, rb_intern("dst?"))) { + return RTEST(rb_funcall(tobj->vtm.zone, rb_intern("dst?"), 1, time)) ? Qtrue : Qfalse; + } if (tobj->vtm.isdst == VTM_ISDST_INITVAL) { rb_raise(rb_eRuntimeError, "isdst is not set yet"); } @@ -5684,7 +5688,7 @@ rb_time_zone_abbreviation(VALUE zone, VALUE time) * == Timezone argument * * A timezone argument must have +local_to_utc+ and +utc_to_local+ - * methods, and may have +name+ and +abbr+ methods. + * methods, and may have +name+, +abbr+, and +dst?+ methods. * * The +local_to_utc+ method should convert a Time-like object from * the timezone to UTC, and +utc_to_local+ is the opposite. The @@ -5703,6 +5707,9 @@ rb_time_zone_abbreviation(VALUE zone, VALUE time) * * The +abbr+ method is used by '%Z' in #strftime. * + * The +dst?+ method is called with a +Time+ value and should return whether + * the +Time+ value is in daylight savings time in the zone. + * * === Auto conversion to Timezone * * At loading marshaled data, a timezone name will be converted to a timezone -- 2.21.0