diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2010-06-08 21:35:39 -0500 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2010-06-12 00:19:12 +0200 |
commit | 4146a443b6ffc3d250a280a3b5218c0e5d1a54dd (patch) | |
tree | b7375f69cf6806b5eb92374380840102a57ff867 /activesupport/lib/active_support/core_ext/date/conversions.rb | |
parent | 1a5654851e23b081c331bb3a7e0d0ffc2c2d6e51 (diff) | |
download | rails-4146a443b6ffc3d250a280a3b5218c0e5d1a54dd.tar.gz rails-4146a443b6ffc3d250a280a3b5218c0e5d1a54dd.tar.bz2 rails-4146a443b6ffc3d250a280a3b5218c0e5d1a54dd.zip |
Date#since, #ago, #beginning_of_day, #end_of_day, #xmlschema return TimeWithZone when Time.zone_default is set
Signed-off-by: Xavier Noria <fxn@hashref.com>
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date/conversions.rb')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date/conversions.rb | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/conversions.rb b/activesupport/lib/active_support/core_ext/date/conversions.rb index 13ef703f49..ba17b0a06b 100644 --- a/activesupport/lib/active_support/core_ext/date/conversions.rb +++ b/activesupport/lib/active_support/core_ext/date/conversions.rb @@ -81,6 +81,16 @@ class Date def to_time(form = :local) ::Time.send("#{form}_time", year, month, day) end + + # Converts Date to a TimeWithZone in the current zone if Time.zone_default is set, + # otherwise converts Date to a Time via Date#to_time + def to_time_in_current_zone + if ::Time.zone_default + ::Time.zone.local(year, month, day) + else + to_time + end + end # Converts a Date instance to a DateTime, where the time is set to the beginning of the day # and UTC offset is set to 0. @@ -94,6 +104,6 @@ class Date end if RUBY_VERSION < '1.9' def xmlschema - to_time.xmlschema + to_time_in_current_zone.xmlschema end end |