-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Behaviour change when comparing Date
and Time
between previous versions and 3.3.0
#86
Comments
I am not sure about the overall topic, but it deserves noting that require 'date'
require 'time'
d = Date.new(2023, 1, 23)
t = Time.utc(2023, 1, 23)
d == t
#=> false
d <=> t
#=> nil ...so, whatever produced Date.parse("1000-01-01") == Time.parse("1000-01-01T00:00:00Z")
#=> true ...was NOT Ruby's core require 'active_support/all'
d == t
#=> true
d <=> t
#=> 0
Date.parse("1000-01-01") == Time.parse("1000-01-01T00:00:00Z")
#=> true for me in Ruby 2.7
#=> false for me in Ruby 3.2 ActiveSupport uses Time.parse("1000-01-01T00:00:00Z").to_datetime
#=> Mon, 01 Jan 1000 00:00:00 +0000 on 2.7
#=> Wed, 27 Dec 0999 00:00:00 +0000 on 3.2 ...which is now consistent with I don't feel qualified or have enough time right now to analyze this behavior. |
...but it seems to be related to this PR: #73 |
|
@zverok Thanks for checking this out. I intentionaly reduced my test case to ruby core/stdlib only, no rails lib in there. Also my issue is a difference even with the same Ruby version, but different @nobu Thanks for your answer, I get the difference but then isn't it an inconsistency between Time and Date that should be sorted out? Let's say I have a db (or json, csv, etc.) with:
How am I supposed to parse them so they are considered to be on the same day? |
If it would be so,
Basically,
Date.parse('1000-01-01') == DateTime.parse('1000-01-01T00:00:00Z')
#=> true |
Indeed, I checked with a clean slate docker ruby: > docker run -it --rm ruby:3.0-slim gem list | grep date
date (default: 3.1.3) docker run -it --rm ruby:3.0-slim irb require "date"
d = Date.new(1000, 1, 1)
# => #<Date: 1000-01-01 ((2086308j,0s,0n),+0s,2299161j)>
t = Time.new(1000, 1, 1, 0, 0, 0)
# => 1000-01-01 00:00:00 +0000
t == d
# => false
d == t
=> false
Ok, for it to work, everything has to use only One last example which is then also confusing: require "date"
d = Date.new(1000, 1, 1)
# => #<Date: 1000-01-01 ((2086308j,0s,0n),+0s,2299161j)>
t = Time.new(1000, 1, 1, 0, 0, 0)
# => 1000-01-01 00:00:00 +0000
dt = t.to_datetime
dt == d
# => true
d == dt
=> true So going from |
Yes,
I am not sure what it demonstrates?.. For me on Ruby 3.2 it is d = Date.new(1000, 1, 1)
# => #<Date: 1000-01-01 ((2086308j,0s,0n),+0s,2299161j)>
t = Time.new(1000, 1, 1, 0, 0, 0)
# => 1000-01-01 00:00:00 +0000
dt = t.to_datetime
# => Wed, 27 Dec 0999 00:00:00 +0202
dt == d
# => false ...which is consistent with Before Ruby 3.2, it was: dt = t.to_datetime
# => #<DateTime: 1000-01-01T00:00:00+02:02 ((2086307j,79076s,0n),+7324s,2299161j)> ...which was a calendar-ignoring bug fixed by #73, the situation is no different for what we discussed about |
Hi there,
I'm not sure this is the right place to put such issue, but I found an issue after updating from
3.0.1
to3.3.3
.I tracked the change in behaviour to start appearing between versions
3.2.2
and3.3.0
, here's and example of the change:with version
3.2.2
with version
3.3.0
As you can see I'm working with date in the
Julian
calendar and comparing them used to work before3.3.0
.Now I'm not sure if and what is the bug there, as this was maybe already an issue:
But in the end, this change of behaviour surfaced and I wanted to be sure it's reported.
The text was updated successfully, but these errors were encountered: