diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2008-01-16 20:07:10 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2008-01-16 20:07:10 +0000 |
commit | 47ff3aa91ff23ae8676717519fe0aecd1f6a7d82 (patch) | |
tree | bb952c8585df25501500fdf59ebcc6fe35044c08 /activesupport/lib/active_support | |
parent | 61e550ade937f812546b6fe561bc5ceb4460b9fb (diff) | |
download | rails-47ff3aa91ff23ae8676717519fe0aecd1f6a7d82.tar.gz rails-47ff3aa91ff23ae8676717519fe0aecd1f6a7d82.tar.bz2 rails-47ff3aa91ff23ae8676717519fe0aecd1f6a7d82.zip |
Introducing DateTime #utc, #utc? and #utc_offset, for duck-typing compatibility with Time. Closes #10002
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8649 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_time/calculations.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb index 2e85d14579..d93c1148c4 100644 --- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb @@ -71,6 +71,26 @@ module ActiveSupport #:nodoc: def end_of_day change(:hour => 23, :min => 59, :sec => 59) end + + # Adjusts DateTime to UTC by adding its offset value; offset is set to 0 + # + # Example: + # + # DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)) # => Mon, 21 Feb 2005 10:11:12 -0600 + # DateTime.civil(2005, 2, 21, 10, 11, 12, Rational(-6, 24)).utc # => Mon, 21 Feb 2005 16:11:12 +0000 + def utc + new_offset(0) + end + + # Returns true if offset == 0 + def utc? + offset == 0 + end + + # Returns the offset value in seconds + def utc_offset + (offset * 86400).to_i + end end end end |