From f285b6119b9ca7f598e31c0c8518dce3e1b13386 Mon Sep 17 00:00:00 2001 From: gbuesing Date: Sat, 12 Apr 2008 17:37:50 -0500 Subject: Add #getutc alias for DateTime#utc --- activesupport/lib/active_support/core_ext/date_time/calculations.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 5c351c21c6..fa444f71b1 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -86,6 +86,7 @@ module ActiveSupport #:nodoc: def utc new_offset(0) end + alias_method :getutc, :utc # Returns true if offset == 0 def utc? -- cgit v1.2.3 From 9620372a6dc7eeebdb04f1fdb7f150d29e60fc00 Mon Sep 17 00:00:00 2001 From: gbuesing Date: Sat, 12 Apr 2008 19:35:47 -0500 Subject: Time#since behaves correctly when passed a Duration. Closes #11527 [kemiller] --- .../lib/active_support/core_ext/time/calculations.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 0bc83af709..ffbdf37789 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -88,18 +88,21 @@ module ActiveSupport #:nodoc: end # Returns a new Time representing the time a number of seconds ago, this is basically a wrapper around the Numeric extension - # Do not use this method in combination with x.months, use months_ago instead! def ago(seconds) self.since(-seconds) end # Returns a new Time representing the time a number of seconds since the instance time, this is basically a wrapper around - # the Numeric extension. Do not use this method in combination with x.months, use months_since instead! + # the Numeric extension. def since(seconds) - initial_dst = self.dst? ? 1 : 0 f = seconds.since(self) - final_dst = f.dst? ? 1 : 0 - (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f + if ActiveSupport::Duration === seconds + f + else + initial_dst = self.dst? ? 1 : 0 + final_dst = f.dst? ? 1 : 0 + (seconds.abs >= 86400 && initial_dst != final_dst) ? f + (initial_dst - final_dst).hours : f + end rescue self.to_datetime.since(seconds) end -- cgit v1.2.3