aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-01-23 02:46:47 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-01-23 02:46:47 +0000
commitabb24b484fcb306be17dd06a8a2d12ca5a035aeb (patch)
tree96de38f875c4048b27e6fae61de0d00111a66014 /activesupport/lib/active_support/core_ext/date_time
parent2e7b2f03448e5759113ce0c182ed99897342c7a9 (diff)
downloadrails-abb24b484fcb306be17dd06a8a2d12ca5a035aeb.tar.gz
rails-abb24b484fcb306be17dd06a8a2d12ca5a035aeb.tar.bz2
rails-abb24b484fcb306be17dd06a8a2d12ca5a035aeb.zip
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
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time')
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb9
1 files changed, 9 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 f9645fd3cf..59d742cde3 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -52,6 +52,15 @@ module ActiveSupport #:nodoc:
end
end
+ # Returns the utc_offset as an +HH:MM formatted string. Examples:
+ #
+ # datetime = DateTime.civil(2000, 1, 1, 0, 0, 0, Rational(-6, 24))
+ # datetime.formatted_offset # => "-06:00"
+ # datetime.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
+
# Overrides the default inspect method with a human readable one, e.g., "Mon, 21 Feb 2005 14:30:00 +0000"
def readable_inspect
to_s(:rfc822)