Navigation Menu

Skip to content

Commit

Permalink
When comparing a TimeOrDateTime with another TimeOrDateTime with <=>,…
Browse files Browse the repository at this point in the history
… make sure any conversions performed on the passed in TimeOrDateTime are cached. Previously the TimeOrDateTime passed in would be converted to its original form and then <=> would be called recursively. This could create a temporary TimeOrDateTime to be converted that would subsequently be discarded.
  • Loading branch information
philr committed Apr 14, 2006
1 parent b56b969 commit 1e0cda0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions tzinfo/CHANGES
@@ -1,3 +1,13 @@
Version ?.?.? (tzdata v?????) - ??????????
------------------------------------------

* When comparing a TimeOrDateTime with another TimeOrDateTime with <=>, make
sure any conversions performed on the passed in TimeOrDateTime are cached.
Previously the TimeOrDateTime passed in would be converted to its original
form and then <=> would be called recursively. This could create a
temporary TimeOrDateTime to be converted that would subsequently be
discarded.

Version 0.2.0 (tzdata v2006c) - 3-Apr-2006
------------------------------------------

Expand Down
14 changes: 12 additions & 2 deletions tzinfo/lib/tzinfo/time_or_datetime.rb
Expand Up @@ -171,8 +171,18 @@ def sec
#
# Milliseconds and smaller units are ignored in the comparison.
def <=>(timeOrDateTime)
if timeOrDateTime.is_a?(TimeOrDateTime)
self <=> timeOrDateTime.orig
if timeOrDateTime.is_a?(TimeOrDateTime)
orig = timeOrDateTime.to_orig

if @orig.is_a?(DateTime) || orig.is_a?(DateTime)
# If either is a DateTime, assume it is there for a reason
# (i.e. for range).
to_datetime <=> timeOrDateTime.to_datetime
elsif orig.is_a?(Time)
to_time <=> timeOrDateTime.to_time
else
to_i <=> timeOrDateTime.to_i
end
elsif @orig.is_a?(DateTime) || timeOrDateTime.is_a?(DateTime)
# If either is a DateTime, assume it is there for a reason
# (i.e. for range).
Expand Down

0 comments on commit 1e0cda0

Please sign in to comment.