summaryrefslogtreecommitdiff
path: root/ext/date
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-08-08 22:43:56 +0900
committergit <svn-admin@ruby-lang.org>2022-08-08 23:50:17 +0900
commite07d450deae500422b7693a30c75c5b1567601a2 (patch)
tree856b46413ab3f44a41612f13127e4758b1219602 /ext/date
parent43239b23b48a6c3fde6bdc4b9cc568bedac161b2 (diff)
downloadruby-e07d450deae500422b7693a30c75c5b1567601a2.tar.gz
[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')
-rw-r--r--ext/date/date_core.c13
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,