diff options
author | Sean Griffin <sean@thoughtbot.com> | 2015-02-07 14:34:46 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2015-02-07 14:34:46 -0700 |
commit | c4ef73affdc67efb02ca369326aaaaab3fd94d21 (patch) | |
tree | 060ac064cd881b52f9179f7417c7f253779f750f /activerecord/lib/active_record/type/time_value.rb | |
parent | 7e93e33c1980ea3d08cec9708d2737f1c8d0a10a (diff) | |
download | rails-c4ef73affdc67efb02ca369326aaaaab3fd94d21.tar.gz rails-c4ef73affdc67efb02ca369326aaaaab3fd94d21.tar.bz2 rails-c4ef73affdc67efb02ca369326aaaaab3fd94d21.zip |
Move non-type objects into the `Type::Helpers` namespace
The type code is actually quite accessible, and I'm planning to
encourage people to look at the files in the `type` folder to learn more
about how it works. This will help reduce the noise from code that is
less about type casting, and more about random AR nonsense.
Diffstat (limited to 'activerecord/lib/active_record/type/time_value.rb')
-rw-r--r-- | activerecord/lib/active_record/type/time_value.rb | 38 |
1 files changed, 0 insertions, 38 deletions
diff --git a/activerecord/lib/active_record/type/time_value.rb b/activerecord/lib/active_record/type/time_value.rb deleted file mode 100644 index 53188d4d69..0000000000 --- a/activerecord/lib/active_record/type/time_value.rb +++ /dev/null @@ -1,38 +0,0 @@ -module ActiveRecord - module Type - module TimeValue # :nodoc: - def type_cast_for_schema(value) - "'#{value.to_s(:db)}'" - end - - def user_input_in_time_zone(value) - value.in_time_zone - end - - 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 - - # Doesn't handle time zones. - def fast_string_to_time(string) - if string =~ ConnectionAdapters::Column::Format::ISO_DATETIME - microsec = ($7.to_r * 1_000_000).to_i - new_time $1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i, microsec - end - end - end - end -end |