* [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date
@ 2022-07-29 6:29 kei-p (Keisuke Ishizawa)
2022-07-29 7:03 ` [ruby-dev:51186] " duerst
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: kei-p (Keisuke Ishizawa) @ 2022-07-29 6:29 UTC (permalink / raw)
To: ruby-dev
Issue #18946 has been reported by kei-p (Keisuke Ishizawa).
----------------------------------------
Bug #18946: Time#to_date returns incorrect date
https://bugs.ruby-lang.org/issues/18946
* Author: kei-p (Keisuke Ishizawa)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Time#to_date returns incorrect date.
Actual Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
Expected Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-27 ...>
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-dev:51186] [Ruby master Bug#18946] Time#to_date returns incorrect date
2022-07-29 6:29 [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date kei-p (Keisuke Ishizawa)
@ 2022-07-29 7:03 ` duerst
2022-07-29 8:26 ` [ruby-dev:51187] " kei-p (Keisuke Ishizawa)
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: duerst @ 2022-07-29 7:03 UTC (permalink / raw)
To: ruby-dev
Issue #18946 has been updated by duerst (Martin Dürst).
This may be due to the Gregorian calendar reform (see https://en.wikipedia.org/wiki/Gregorian_calendar#Gregorian_reform, which says: "Julian Thursday, 4 October 1582, being followed by Gregorian Friday, 15 October").
Time seems to use a proleptic Gregorian calendar (the Gregorian calendar extended to before the Gregorian reform, see https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) while Date seems to be using the Julian calendar before the 'official' reform date. Please note that the reform didn't get applied at that date everywhere; different parts of the globe changed at different times, and some churches still use the old calendar.
```
Time.local(1582,10,14).to_date
=> #<Date: 1582-10-04 ((2299160j,0s,0n),+0s,2299161j)>
Time.local(1582,10,15).to_date
=> #<Date: 1582-10-15 ((2299161j,0s,0n),+0s,2299161j)>
```
Also, please compare:
```
Time.local(1500,3,1).to_date
=> #<Date: 1500-02-20 ((2268983j,0s,0n),+0s,2299161j)>
Time.local(1500,2,29).to_date
=> #<Date: 1500-02-20 ((2268983j,0s,0n),+0s,2299161j)>
```
(in Time, there's no February 29 in 1500, because it's proleptic)
with
```
Time.local(1500,3,9).to_date
=> #<Date: 1500-02-28 ((2268991j,0s,0n),+0s,2299161j)>
Time.local(1500,3,10).to_date
=> #<Date: 1500-02-29 ((2268992j,0s,0n),+0s,2299161j)>
Time.local(1500,3,11).to_date
=> #<Date: 1500-03-01 ((2268993j,0s,0n),+0s,2299161j)>
```
In Date, there is a February 29 in 1500, because it's Julian.
See also `ri Date`. It may be a good idea to add a note to the documentation for Time, to say that it uses the proleptic Gregorian calendar, and this is different from Date.
Please note that dates are *relatively* easy if the date is close to the present, but the farther you move out, the more complicated it may get.
----------------------------------------
Bug #18946: Time#to_date returns incorrect date
https://bugs.ruby-lang.org/issues/18946#change-98504
* Author: kei-p (Keisuke Ishizawa)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Time#to_date returns incorrect date.
Actual Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
Expected Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-27 ...>
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-dev:51187] [Ruby master Bug#18946] Time#to_date returns incorrect date
2022-07-29 6:29 [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date kei-p (Keisuke Ishizawa)
2022-07-29 7:03 ` [ruby-dev:51186] " duerst
@ 2022-07-29 8:26 ` kei-p (Keisuke Ishizawa)
2022-07-29 23:06 ` [ruby-dev:51188] " jeremyevans0 (Jeremy Evans)
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: kei-p (Keisuke Ishizawa) @ 2022-07-29 8:26 UTC (permalink / raw)
To: ruby-dev
Issue #18946 has been updated by kei-p (Keisuke Ishizawa).
> Time seems to use a proleptic Gregorian calendar (the Gregorian calendar extended to before the Gregorian reform, see https://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar) while Date seems to be using the Julian calendar before the 'official' reform date.
Thanks for the detailed explanation.
I understand that this is due to the different calendars that Date and Time uses before the 'official' reform date.
----------------------------------------
Bug #18946: Time#to_date returns incorrect date
https://bugs.ruby-lang.org/issues/18946#change-98505
* Author: kei-p (Keisuke Ishizawa)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Time#to_date returns incorrect date.
Actual Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
Expected Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-27 ...>
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-dev:51188] [Ruby master Bug#18946] Time#to_date returns incorrect date
2022-07-29 6:29 [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date kei-p (Keisuke Ishizawa)
2022-07-29 7:03 ` [ruby-dev:51186] " duerst
2022-07-29 8:26 ` [ruby-dev:51187] " kei-p (Keisuke Ishizawa)
@ 2022-07-29 23:06 ` jeremyevans0 (Jeremy Evans)
2022-08-08 3:02 ` [ruby-dev:51192] " matz (Yukihiro Matsumoto)
2022-08-22 3:48 ` [ruby-dev:51194] " nobu (Nobuyoshi Nakada)
4 siblings, 0 replies; 6+ messages in thread
From: jeremyevans0 (Jeremy Evans) @ 2022-07-29 23:06 UTC (permalink / raw)
To: ruby-dev
Issue #18946 has been updated by jeremyevans0 (Jeremy Evans).
`Time#to_datetime` does not operate the same way, which seems like an undesirable inconsistency:
```ruby
Time.local(1499, 12, 27).to_datetime
=> #<DateTime: 1499-12-27T00:00:00-07:52 ((2268928j,28378s,0n),-28378s,2299161j)>
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
----------------------------------------
Bug #18946: Time#to_date returns incorrect date
https://bugs.ruby-lang.org/issues/18946#change-98527
* Author: kei-p (Keisuke Ishizawa)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Time#to_date returns incorrect date.
Actual Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
Expected Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-27 ...>
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-dev:51192] [Ruby master Bug#18946] Time#to_date returns incorrect date
2022-07-29 6:29 [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date kei-p (Keisuke Ishizawa)
` (2 preceding siblings ...)
2022-07-29 23:06 ` [ruby-dev:51188] " jeremyevans0 (Jeremy Evans)
@ 2022-08-08 3:02 ` matz (Yukihiro Matsumoto)
2022-08-22 3:48 ` [ruby-dev:51194] " nobu (Nobuyoshi Nakada)
4 siblings, 0 replies; 6+ messages in thread
From: matz (Yukihiro Matsumoto) @ 2022-08-08 3:02 UTC (permalink / raw)
To: ruby-dev
Issue #18946 has been updated by matz (Yukihiro Matsumoto).
I checked commit history and found out that to_date has been use GREGORIAN calendar since 2011-05-31 and to_datetime preserved the old DEFAULT_SG (ITALY). I assume this is a mistake and both should use GREGORIAN (ext/date/date_core.c:8647).
Matz.
----------------------------------------
Bug #18946: Time#to_date returns incorrect date
https://bugs.ruby-lang.org/issues/18946#change-98596
* Author: kei-p (Keisuke Ishizawa)
* Status: Open
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Time#to_date returns incorrect date.
Actual Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
Expected Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-27 ...>
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
* [ruby-dev:51194] [Ruby master Bug#18946] Time#to_date returns incorrect date
2022-07-29 6:29 [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date kei-p (Keisuke Ishizawa)
` (3 preceding siblings ...)
2022-08-08 3:02 ` [ruby-dev:51192] " matz (Yukihiro Matsumoto)
@ 2022-08-22 3:48 ` nobu (Nobuyoshi Nakada)
4 siblings, 0 replies; 6+ messages in thread
From: nobu (Nobuyoshi Nakada) @ 2022-08-22 3:48 UTC (permalink / raw)
To: ruby-dev
Issue #18946 has been updated by nobu (Nobuyoshi Nakada).
Fixed this issue itself, but turned out Psych had a related issue.
The YAML spec doesn’t considered the calendar systems.
Although I [reported], as it hasn’t been concluded yet, the failing test is excluded now at commit:git|79fdf9712dea4943a15c4ef34348b1a159b62f4a.
[reported]: https://github.com/yaml/yaml/issues/69
----------------------------------------
Bug #18946: Time#to_date returns incorrect date
https://bugs.ruby-lang.org/issues/18946#change-98807
* Author: kei-p (Keisuke Ishizawa)
* Status: Closed
* Priority: Normal
* ruby -v: 3.1.2
* Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN
----------------------------------------
Time#to_date returns incorrect date.
Actual Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-18 ((2268919j,0s,0n),+0s,2299161j)>
```
Expected Behavior:
```
Time.local(1499, 12, 27).to_date
=> #<Date: 1499-12-27 ...>
```
--
https://bugs.ruby-lang.org/
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-08-22 3:48 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-29 6:29 [ruby-dev:51185] [Ruby master Bug#18946] Time#to_date returns incorrect date kei-p (Keisuke Ishizawa)
2022-07-29 7:03 ` [ruby-dev:51186] " duerst
2022-07-29 8:26 ` [ruby-dev:51187] " kei-p (Keisuke Ishizawa)
2022-07-29 23:06 ` [ruby-dev:51188] " jeremyevans0 (Jeremy Evans)
2022-08-08 3:02 ` [ruby-dev:51192] " matz (Yukihiro Matsumoto)
2022-08-22 3:48 ` [ruby-dev:51194] " nobu (Nobuyoshi Nakada)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).