From abb24b484fcb306be17dd06a8a2d12ca5a035aeb Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Wed, 23 Jan 2008 02:46:47 +0000 Subject: Adding Time and DateTime #formatted_offset, for outputting +HH:MM utc offset strings with cross-platform consistency git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8698 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/core_ext/time/conversions.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/time/conversions.rb') diff --git a/activesupport/lib/active_support/core_ext/time/conversions.rb b/activesupport/lib/active_support/core_ext/time/conversions.rb index ffc9b05a8c..466a20c3bc 100644 --- a/activesupport/lib/active_support/core_ext/time/conversions.rb +++ b/activesupport/lib/active_support/core_ext/time/conversions.rb @@ -55,6 +55,14 @@ module ActiveSupport #:nodoc: to_default_s end end + + # Returns the utc_offset as an +HH:MM formatted string. Examples: + # + # Time.local(2000).formatted_offset # => "-06:00" + # Time.local(2000).formatted_offset(false) # => "-0600" + def formatted_offset(colon = true, alternate_utc_string = nil) + utc? && alternate_utc_string || utc_offset.to_utc_offset_s(colon) + end # Convert a Time object to a Date, dropping hour, minute, and second precision. # -- cgit v1.2.3