From 941eee5c8ebb82f97434f93fb233502cbb4f8270 Mon Sep 17 00:00:00 2001 From: yui-knk Date: Sat, 23 Apr 2016 23:51:49 +0900 Subject: Move `DateTime#getlocal` to `/core_ext/date_time/calculations.rb` `DateTime#getlocal` is newly added public API. It's responsible is same as `DateTime#utc`, so `calculations.rb` is a best plase to define this method. For keeping consistency with `DateTime#utc`, defines `#localtime` and defines `getlocal` as an alias method. --- .../lib/active_support/core_ext/date_time/calculations.rb | 12 ++++++++++++ .../lib/active_support/core_ext/date_time/compatibility.rb | 11 ----------- 2 files changed, 12 insertions(+), 11 deletions(-) (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 ac46f5ffe8..e6eaa02a60 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -152,6 +152,18 @@ class DateTime end alias_method :getutc, :utc + # Returns a Time.local() instance of the simultaneous time in your + # system's ENV['TZ'] zone. + def localtime(utc_offset = nil) + utc = getutc + + Time.utc( + utc.year, utc.month, utc.day, + utc.hour, utc.min, utc.sec + utc.sec_fraction + ).getlocal(utc_offset) + end + alias_method :getlocal, :localtime + # Returns +true+ if offset == 0. def utc? offset == 0 diff --git a/activesupport/lib/active_support/core_ext/date_time/compatibility.rb b/activesupport/lib/active_support/core_ext/date_time/compatibility.rb index 63ac4c2f3a..03e4a2adfa 100644 --- a/activesupport/lib/active_support/core_ext/date_time/compatibility.rb +++ b/activesupport/lib/active_support/core_ext/date_time/compatibility.rb @@ -2,15 +2,4 @@ require 'active_support/core_ext/date_and_time/compatibility' class DateTime prepend DateAndTime::Compatibility - - # Returns a Time.local() instance of the simultaneous time in your - # system's ENV['TZ'] zone. - def getlocal(utc_offset = nil) - utc = getutc - - Time.utc( - utc.year, utc.month, utc.day, - utc.hour, utc.min, utc.sec + utc.sec_fraction - ).getlocal(utc_offset) - end end -- cgit v1.2.3