diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-07-23 11:48:59 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-07-23 11:52:33 +0900 |
commit | caf565f7bf9b279449c893b9e812c466a26e8f4b (patch) | |
tree | 5a464376ba242ca3429e3e2db4d0c25adf7c5098 | |
parent | afacf85e443cc64dd41c248659b65476434b4175 (diff) |
Ensure time object meets a given condition [Bug #17042]
-rw-r--r-- | time.c | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -1765,6 +1765,14 @@ static VALUE time_get_tm(VALUE, struct time_object *); time_get_tm((time), (tobj)); \ } \ } while (0) +#define MAKE_TM_ENSURE(time, tobj, cond) \ + do { \ + MAKE_TM(time, tobj); \ + if (!(cond)) { \ + VALUE zone = (tobj)->vtm.zone; \ + if (!NIL_P(zone)) zone_localtime(zone, (time)); \ + } \ + } while (0) static void time_mark(void *ptr) @@ -4593,11 +4601,7 @@ time_wday(VALUE time) struct time_object *tobj; GetTimeval(time, tobj); - MAKE_TM(time, tobj); - if (tobj->vtm.wday == VTM_WDAY_INITVAL) { - VALUE zone = tobj->vtm.zone; - if (!NIL_P(zone)) zone_localtime(zone, time); - } + MAKE_TM_ENSURE(time, tobj, tobj->vtm.wday != VTM_WDAY_INITVAL); return INT2FIX((int)tobj->vtm.wday); } @@ -4733,11 +4737,7 @@ time_yday(VALUE time) struct time_object *tobj; GetTimeval(time, tobj); - MAKE_TM(time, tobj); - if (tobj->vtm.yday == 0) { - VALUE zone = tobj->vtm.zone; - if (!NIL_P(zone)) zone_localtime(zone, time); - } + MAKE_TM_ENSURE(time, tobj, tobj->vtm.yday != 0); return INT2FIX(tobj->vtm.yday); } @@ -5109,11 +5109,7 @@ time_strftime(VALUE time, VALUE format) VALUE tmp; GetTimeval(time, tobj); - if (tobj->vtm.yday == 0) { - VALUE zone = tobj->vtm.zone; - if (!NIL_P(zone)) zone_localtime(zone, time); - } - MAKE_TM(time, tobj); + MAKE_TM_ENSURE(time, tobj, tobj->vtm.yday != 0); StringValue(format); if (!rb_enc_str_asciicompat_p(format)) { rb_raise(rb_eArgError, "format should have ASCII compatible encoding"); |