Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Delegate type_cast to injected type object in mysql
- Loading branch information
Showing
6 changed files
with
72 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
activerecord/lib/active_record/connection_adapters/type/time_value.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module ActiveRecord | ||
module ConnectionAdapters | ||
module Type | ||
module TimeValue # :nodoc: | ||
private | ||
|
||
def new_time(year, mon, mday, hour, min, sec, microsec, offset = nil) | ||
# Treat 0000-00-00 00:00:00 as nil. | ||
return if year.nil? || (year == 0 && mon == 0 && mday == 0) | ||
|
||
if offset | ||
time = ::Time.utc(year, mon, mday, hour, min, sec, microsec) rescue nil | ||
return unless time | ||
|
||
time -= offset | ||
Base.default_timezone == :utc ? time : time.getlocal | ||
else | ||
::Time.public_send(Base.default_timezone, year, mon, mday, hour, min, sec, microsec) rescue nil | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |