aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb5
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb2
-rw-r--r--activesupport/lib/active_support/core_ext/time/conversions.rb5
3 files changed, 12 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/conversions.rb b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
index 48a13e1fde..926a168cec 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -22,6 +22,11 @@ module ActiveSupport #:nodoc:
def to_date
::Date.new(year, month, day)
end
+
+ # To be able to keep Times and DateTimes interchangeable on conversions
+ def to_datetime
+ self
+ end
end
end
end
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 1c2daf0606..1fdfbcdf45 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -91,6 +91,8 @@ module ActiveSupport #:nodoc:
f = seconds.since(self)
final_dst = f.dst? ? 1 : 0
(seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f
+ rescue
+ self.to_datetime.since(seconds)
end
alias :in :since
diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb
index f2ff0e06a8..903dd02031 100644
--- a/activesupport/lib/active_support/core_ext/time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/time/conversions.rb
@@ -28,6 +28,11 @@ module ActiveSupport #:nodoc:
def to_time
self
end
+
+ # converts to a Ruby DateTime instance; preserves utc offset
+ def to_datetime
+ ::DateTime.civil(year, month, day, hour, min, sec, Rational(utc_offset, 86400), 0)
+ end
end
end
end