From e094940c2b5a5163504859efd3a0bcc49c40451e Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Mon, 23 Mar 2009 22:01:51 -0700 Subject: Move Numeric#to_utc_offset_s to TimeZone.seconds_to_utc_offset --- activesupport/lib/active_support/values/time_zone.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/values/time_zone.rb') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 836f469df7..516ef2d8f0 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -170,6 +170,20 @@ module ActiveSupport MAPPING.freeze end + UTC_OFFSET_WITH_COLON = '%+03d:%02d' + UTC_OFFSET_WITHOUT_COLON = UTC_OFFSET_WITH_COLON.sub(':', '') + + # Assumes self represents an offset from UTC in seconds (as returned from Time#utc_offset) + # and turns this into an +HH:MM formatted string. Example: + # + # TimeZone.seconds_to_utc_offset(-21_600) # => "-06:00" + def self.seconds_to_utc_offset(seconds, colon = true) + format = colon ? UTC_OFFSET_WITH_COLON : UTC_OFFSET_WITHOUT_COLON + hours = seconds / 3600 + minutes = (seconds.abs % 3600) / 60 + format % [hours, minutes] + end + include Comparable attr_reader :name @@ -190,7 +204,7 @@ module ActiveSupport # Returns the offset of this time zone as a formatted string, of the # format "+HH:MM". def formatted_offset(colon=true, alternate_utc_string = nil) - utc_offset == 0 && alternate_utc_string || utc_offset.to_utc_offset_s(colon) + utc_offset == 0 && alternate_utc_string || self.class.seconds_to_utc_offset(utc_offset, colon) end # Compare this time zone to the parameter. The two are comapred first on -- cgit v1.2.3 From 47c7177ef555b70204adf9e6c0e6995f6d1d2231 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Thu, 26 Mar 2009 19:10:37 -0700 Subject: Explicit Time/DateTime dependencies --- activesupport/lib/active_support/values/time_zone.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activesupport/lib/active_support/values/time_zone.rb') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 516ef2d8f0..d329804617 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -1,3 +1,10 @@ +require 'active_support/core_ext/time/publicize_conversion_methods' +require 'active_support/core_ext/time/calculations' +require 'active_support/core_ext/time/zones' + +require 'active_support/core_ext/date_time/calculations' +require 'active_support/core_ext/date_time/zones' + # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following: # # * Limit the set of zones provided by TZInfo to a meaningful subset of 142 zones. -- cgit v1.2.3 From 609c1988d2e274b365c5299cc5933fb6855e4175 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sat, 28 Mar 2009 23:43:03 -0700 Subject: Tease out Object#acts_like? behaviors --- activesupport/lib/active_support/values/time_zone.rb | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'activesupport/lib/active_support/values/time_zone.rb') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index d329804617..531fdb9d31 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -1,7 +1,11 @@ require 'active_support/core_ext/time/publicize_conversion_methods' +require 'active_support/core_ext/time/acts_like' require 'active_support/core_ext/time/calculations' require 'active_support/core_ext/time/zones' +require 'active_support/core_ext/date/acts_like' + +require 'active_support/core_ext/date_time/acts_like' require 'active_support/core_ext/date_time/calculations' require 'active_support/core_ext/date_time/zones' -- cgit v1.2.3 From d848b7817fe5ce044709e09fa96464d0d6020c9d Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 31 Mar 2009 10:03:35 -0700 Subject: Encapsulate date/time core extensions and constant autoloads in active_support/core/time --- activesupport/lib/active_support/values/time_zone.rb | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'activesupport/lib/active_support/values/time_zone.rb') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index 531fdb9d31..bfec0711ad 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -1,13 +1,6 @@ -require 'active_support/core_ext/time/publicize_conversion_methods' -require 'active_support/core_ext/time/acts_like' -require 'active_support/core_ext/time/calculations' -require 'active_support/core_ext/time/zones' - -require 'active_support/core_ext/date/acts_like' - -require 'active_support/core_ext/date_time/acts_like' -require 'active_support/core_ext/date_time/calculations' -require 'active_support/core_ext/date_time/zones' +require 'active_support/core_ext/time' +require 'active_support/core_ext/date' +require 'active_support/core_ext/date_time' # The TimeZone class serves as a wrapper around TZInfo::Timezone instances. It allows us to do the following: # -- cgit v1.2.3 From 9cc8a75d84a4a5c52071b5c911f5afe1b577f760 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Tue, 7 Apr 2009 21:03:40 -0700 Subject: Insert in sorted order to avoid TimeZone sort --- activesupport/lib/active_support/values/time_zone.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'activesupport/lib/active_support/values/time_zone.rb') diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb index bfec0711ad..e2d759aa50 100644 --- a/activesupport/lib/active_support/values/time_zone.rb +++ b/activesupport/lib/active_support/values/time_zone.rb @@ -363,14 +363,13 @@ module ActiveSupport "Wellington" ], [ 46_800, "Nuku'alofa" ]]. each do |offset, *places| - places.each do |place| + places.sort.each do |place| place.freeze zone = new(place, offset) ZONES << zone ZONES_MAP[place] = zone end end - ZONES.sort! ZONES.freeze ZONES_MAP.freeze -- cgit v1.2.3