-
Notifications
You must be signed in to change notification settings - Fork 49
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
String comparison of two DateTime objects too accurate? #30
Comments
From [email protected] (@autarch) on 2010-05-22 03:44:20: On Fri, 21 May 2010, Michael G Schwern via RT wrote:
I'm not sure I have much to add. These are all possibilities. I'm not sure Have I mentioned that I really, really, really hate Perl's overloading -dave /============================================================ |
From [email protected] on 2010-06-29 17:20:14: I think must people expect stringify then equate for the "eq" overload print "$foo" eq "$bar" ? "Equal" : "Not equal"; However, the "==" overload should be down to the nanosec. Thanks, mrdvt |
From [email protected] (@autarch) on 2012-11-16 17:36:30: On Tue Jun 29 13:20:14 2010, MRDVT wrote:
I'm looking at this again (I'm slow). It breaks a test to change this, which means it breaks backwards compat. I think I should've done it your way to start with, but it might be too |
From [email protected] (@schwern) on 2012-11-21 22:09:38: On Fri Nov 16 12:36:30 2012, DROLSKY wrote:
Test or no, I agree this is a clear change to existing, documented
That's ok, we're comparing them as strings, it should compare the compare() exists for exact date equality. Leave == unimplemented. One thing which the current implementation of eq does well is it allows One flaw is this only works if all the DateTime objects have a formatter
If $a and $b are DateTime objects, it acts like compare(). If neither |
Migrated from rt.cpan.org #57743 (status was 'open')
Requestors:
From [email protected] (@schwern) on 2010-05-22 00:31:33:
DateTime currently uses (after a lot of scaffolding) utc_rd_values() to
perform a string comparison between two DateTime objects. This takes
into account nanoseconds. Since the default string form does not show
nanoseconds it leads to the strange case where two apparently equal
strings are not equal.
For example:
use DateTime;
my $foo = DateTime->new(year => 2010, nanosecond => 123);
my $bar = DateTime->new(year => 2010, nanosecond => 456);
print $foo eq $bar ? "Equal" : "Not equal";
print $foo;
print $bar;'
END
Not equal
2010-01-01T00:00:00
2010-01-01T00:00:00
I'm not sure what's to be done with this, but it is difficult to debug.
One choice is to leave "eq" as a string comparison operator and just
compare DateTime objects as strings rather than as dates. This removes
the surprise, but it also removes a possibly valuable increased accuracy
and its probably backwards compatible.
Another is to compare using lower accuracy, one more in line with what's
displayed, such as utc_rd_as_seconds. This will bring the results in
line with the level of accuracy shown in the default string
representation while retaining cross time zone equality. OTOH people
may change the string format to one that includes nanoseconds, and its
probably backwards incompatible.
Another is to throw a warning when a string comparison fails because of
a nanosecond difference. OTOH this may get noisy.
The text was updated successfully, but these errors were encountered: