From 8831180b152007c52abb2a03bb351ebc7079c4c4 Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Sun, 10 Feb 2008 20:04:14 +0000 Subject: Adding TimeWithZone #to_a, #to_f, #to_i, #httpdate, #rfc2822 git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8852 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/time_with_zone.rb | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 6b9fed4b8f..517b2bac7f 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -44,7 +44,7 @@ module ActiveSupport # Returns a Time.local() instance of the simultaneous time in your system's ENV['TZ'] zone def localtime - utc.dup.localtime # use #dup because Time#localtime is destructive + utc.getlocal end def dst? @@ -79,6 +79,15 @@ module ActiveSupport def to_json(options = nil) %("#{time.strftime("%Y/%m/%d %H:%M:%S")} #{formatted_offset(false)}") end + + def httpdate + utc.httpdate + end + + def rfc2822 + to_s(:rfc822) + end + alias_method :rfc822, :rfc2822 # :db format outputs time in UTC; all others output time in local. Uses TimeWithZone's strftime, so %Z and %z work correctly def to_s(format = :default) @@ -107,6 +116,18 @@ module ActiveSupport def -(other) other.acts_like?(:time) ? utc - other : method_missing(:-, other) end + + def to_a + time.to_a[0, 8].push(dst?, zone) + end + + def to_f + utc.to_f + end + + def to_i + utc.to_i + end # A TimeProxy acts like a Time, so just return self def to_time -- cgit v1.2.3