aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time/conversions.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-12-15 02:27:29 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-12-15 02:27:29 +0000
commitbb152cd8ca2502c4b426a46fa9d86d9cff68d0cb (patch)
treeaf192609bc045e0553c039d4b5e792d7529f210e /activesupport/lib/active_support/core_ext/date_time/conversions.rb
parent3d90733e937d11b6905ff11ce006a591ec11b4f4 (diff)
downloadrails-bb152cd8ca2502c4b426a46fa9d86d9cff68d0cb.tar.gz
rails-bb152cd8ca2502c4b426a46fa9d86d9cff68d0cb.tar.bz2
rails-bb152cd8ca2502c4b426a46fa9d86d9cff68d0cb.zip
Ruby 1.9 compat: normalize date and time xmlschema to match Ruby's formatting [chuyeow]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8398 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/conversions.rb12
1 files changed, 8 insertions, 4 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 45d09f344d..52e6b6bdea 100644
--- a/activesupport/lib/active_support/core_ext/date_time/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/conversions.rb
@@ -9,6 +9,10 @@ module ActiveSupport #:nodoc:
alias_method :to_s, :to_formatted_s
alias_method :default_inspect, :inspect
alias_method :inspect, :readable_inspect
+
+ # Ruby 1.9 has DateTime#to_time which internally relies on Time. We define our own #to_time which allows
+ # DateTimes outside the range of what can be created with Time.
+ remove_method :to_time if base.instance_methods.include?(:to_time)
end
end
@@ -38,16 +42,16 @@ module ActiveSupport #:nodoc:
# If self has an offset other than 0, self will just be returned unaltered, since there's no clean way to map it to a Time
def to_time
self.offset == 0 ? ::Time.utc_time(year, month, day, hour, min, sec) : self
- end
+ end
# To be able to keep Times, Dates and DateTimes interchangeable on conversions
def to_datetime
self
end
-
+
def xmlschema
- strftime("%Y-%m-%dT%H:%M:%S#{offset == 0 ? 'Z' : '%Z'}")
- end
+ strftime("%Y-%m-%dT%H:%M:%S%Z")
+ end if RUBY_VERSION < '1.9'
end
end
end