Ensure time object meets a given condition [Bug #17042]
This commit is contained in:
parent
afacf85e44
commit
caf565f7bf
26
time.c
26
time.c
@ -1765,6 +1765,14 @@ static VALUE time_get_tm(VALUE, struct time_object *);
|
|||||||
time_get_tm((time), (tobj)); \
|
time_get_tm((time), (tobj)); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} 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
|
static void
|
||||||
time_mark(void *ptr)
|
time_mark(void *ptr)
|
||||||
@ -4593,11 +4601,7 @@ time_wday(VALUE time)
|
|||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
MAKE_TM(time, tobj);
|
MAKE_TM_ENSURE(time, tobj, tobj->vtm.wday != VTM_WDAY_INITVAL);
|
||||||
if (tobj->vtm.wday == VTM_WDAY_INITVAL) {
|
|
||||||
VALUE zone = tobj->vtm.zone;
|
|
||||||
if (!NIL_P(zone)) zone_localtime(zone, time);
|
|
||||||
}
|
|
||||||
return INT2FIX((int)tobj->vtm.wday);
|
return INT2FIX((int)tobj->vtm.wday);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4733,11 +4737,7 @@ time_yday(VALUE time)
|
|||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
MAKE_TM(time, tobj);
|
MAKE_TM_ENSURE(time, tobj, tobj->vtm.yday != 0);
|
||||||
if (tobj->vtm.yday == 0) {
|
|
||||||
VALUE zone = tobj->vtm.zone;
|
|
||||||
if (!NIL_P(zone)) zone_localtime(zone, time);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.yday);
|
return INT2FIX(tobj->vtm.yday);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -5109,11 +5109,7 @@ time_strftime(VALUE time, VALUE format)
|
|||||||
VALUE tmp;
|
VALUE tmp;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->vtm.yday == 0) {
|
MAKE_TM_ENSURE(time, tobj, tobj->vtm.yday != 0);
|
||||||
VALUE zone = tobj->vtm.zone;
|
|
||||||
if (!NIL_P(zone)) zone_localtime(zone, time);
|
|
||||||
}
|
|
||||||
MAKE_TM(time, tobj);
|
|
||||||
StringValue(format);
|
StringValue(format);
|
||||||
if (!rb_enc_str_asciicompat_p(format)) {
|
if (!rb_enc_str_asciicompat_p(format)) {
|
||||||
rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
|
rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user