Skip to content

Commit

Permalink
Refactor ActiveRecord::ConnectionAdapters::Column.new_time: leverage …
Browse files Browse the repository at this point in the history
…DateTime failover behavior of Time#time_with_datetime_fallback

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8881 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
gbuesing committed Feb 16, 2008
1 parent 1d5ea18 commit 4e3ecec
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*

* Refactor ConnectionAdapters::Column.new_time: leverage DateTime failover behavior of Time#time_with_datetime_fallback [Geoff Buesing]

* Improve associations performance by using symbol callbacks instead of string callbacks. #11108 [adymo]

* Optimise the BigDecimal conversion code. #11110 [adymo]
Expand Down
Expand Up @@ -172,12 +172,8 @@ def new_date(year, mon, mday)
def new_time(year, mon, mday, hour, min, sec, microsec)
# Treat 0000-00-00 00:00:00 as nil.
return nil if year.nil? || year == 0

Time.send(Base.default_timezone, year, mon, mday, hour, min, sec, microsec)
# Over/underflow to DateTime
rescue ArgumentError, TypeError
zone_offset = Base.default_timezone == :local ? DateTime.local_offset : 0
DateTime.civil(year, mon, mday, hour, min, sec, zone_offset) rescue nil

Time.time_with_datetime_fallback(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil
end

def fast_string_to_date(string)
Expand Down

0 comments on commit 4e3ecec

Please sign in to comment.