aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-02-10 20:04:14 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-02-10 20:04:14 +0000
commit8831180b152007c52abb2a03bb351ebc7079c4c4 (patch)
treea210782b45b1b4612f1372118dd9ff71cc064b7d /activesupport/lib
parent163a4c6f4545c040c7ea25c298865a401b1b24f2 (diff)
downloadrails-8831180b152007c52abb2a03bb351ebc7079c4c4.tar.gz
rails-8831180b152007c52abb2a03bb351ebc7079c4c4.tar.bz2
rails-8831180b152007c52abb2a03bb351ebc7079c4c4.zip
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
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb23
1 files changed, 22 insertions, 1 deletions
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