diff options
author | Jeremy Evans <code@jeremyevans.net> | 2019-07-17 14:53:55 -0700 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-10-24 18:39:04 +0900 |
commit | 9eb798a3f1de6a9e08e510904d376952d5e94d50 (patch) | |
tree | d000971b8e7f0fa83890453064a87f884eec4d45 /ext/date | |
parent | f1de438380893682257b8648784a0fe7714b1f9f (diff) |
[ruby/date] Make julian dates roundtrip through to_time.to_date
Previously, julian dates would not round trip through to_time.to_date,
because Time is always considered gregorian. This converts the Date
instance from julian to gregorian before converting to Time, ensuring
that an equal date object will be returned if converting that Time
back to Date.
This does result in julian Date objects showing different day values
if converting to Time.
Fixes Ruby Bug 8428.
https://github.com/ruby/date/commit/d8df64555e
Diffstat (limited to 'ext/date')
-rw-r--r-- | ext/date/date_core.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 388b30ba7a..71d0da59f8 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -8555,17 +8555,24 @@ time_to_datetime(VALUE self) * call-seq: * d.to_time -> time * - * Returns a Time object which denotes self. + * Returns a Time object which denotes self. If self is a julian date, + * convert it to a gregorian date before converting it to Time. */ static VALUE date_to_time(VALUE self) { - get_d1(self); + get_d1a(self); + + if (m_julian_p(adat)) { + VALUE tmp = d_lite_gregorian(self); + get_d1b(tmp); + adat = bdat; + } return f_local3(rb_cTime, - m_real_year(dat), - INT2FIX(m_mon(dat)), - INT2FIX(m_mday(dat))); + m_real_year(adat), + INT2FIX(m_mon(adat)), + INT2FIX(m_mday(adat))); } /* |