diff options
author | Nobuyoshi Nakada <[email protected]> | 2022-08-08 22:43:56 +0900 |
---|---|---|
committer | git <[email protected]> | 2022-08-08 23:50:17 +0900 |
commit | e07d450deae500422b7693a30c75c5b1567601a2 (patch) | |
tree | 856b46413ab3f44a41612f13127e4758b1219602 /ext/date/date_core.c | |
parent | 43239b23b48a6c3fde6bdc4b9cc568bedac161b2 (diff) |
[ruby/date] Fix Time#to_datetime before calendar reform
Time is always in the proleptic Gregorian calendar.
Also DateTime#to_time should convert to the Gregorian calendar first,
before extracting its components.
https://bugs.ruby-lang.org/issues/18946#change-98527
https://github.com/ruby/date/commit/b2aee75248
Diffstat (limited to 'ext/date/date_core.c')
-rw-r--r-- | ext/date/date_core.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 1c0d1c4920..c68f70e5f8 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -8811,7 +8811,7 @@ time_to_datetime(VALUE self) ret = d_complex_new_internal(cDateTime, nth, 0, 0, sf, - of, DEFAULT_SG, + of, GREGORIAN, ry, m, d, h, min, s, HAVE_CIVIL | HAVE_TIME); @@ -8915,12 +8915,17 @@ date_to_datetime(VALUE self) static VALUE datetime_to_time(VALUE self) { - volatile VALUE dup = dup_obj(self); + get_d1(self); + + if (m_julian_p(dat)) { + self = d_lite_gregorian(self); + get_d1a(self); + dat = adat; + } + { VALUE t; - get_d1(dup); - t = rb_funcall(rb_cTime, rb_intern("new"), 7, |