aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/values/time_zone.rb
diff options
context:
space:
mode:
authorColin Bartlett <colin@colinabartlett.com>2013-11-09 09:23:15 -0500
committerColin Bartlett <colin@colinabartlett.com>2013-12-03 10:37:01 -0500
commit029f24ede99e99b3c988f84b4709add754459fc6 (patch)
treed3c2beae0308009821e939c21b63da78c90b4702 /activesupport/lib/active_support/values/time_zone.rb
parent59cb9e31fd9a2671697fb8d4b652b7a1b2a02a32 (diff)
downloadrails-029f24ede99e99b3c988f84b4709add754459fc6.tar.gz
rails-029f24ede99e99b3c988f84b4709add754459fc6.tar.bz2
rails-029f24ede99e99b3c988f84b4709add754459fc6.zip
Add support for localized date references
Ruby's Date class automatically gives us #yesterday, #today, and #tomorrow. And ActiveSupport has a handy Time.zone.today for getting a localized version. But there was no localized version of #yesterday or #tomorrow. Until now.
Diffstat (limited to 'activesupport/lib/active_support/values/time_zone.rb')
-rw-r--r--activesupport/lib/active_support/values/time_zone.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/values/time_zone.rb b/activesupport/lib/active_support/values/time_zone.rb
index b6d9257f00..a22e61d286 100644
--- a/activesupport/lib/active_support/values/time_zone.rb
+++ b/activesupport/lib/active_support/values/time_zone.rb
@@ -317,6 +317,16 @@ module ActiveSupport
tzinfo.now.to_date
end
+ # Returns the next date in this time zone.
+ def tomorrow
+ today + 1
+ end
+
+ # Returns the previous date in this time zone.
+ def yesterday
+ today - 1
+ end
+
# Adjust the given time to the simultaneous time in the time zone
# represented by +self+. Returns a Time.utc() instance -- if you want an
# ActiveSupport::TimeWithZone instance, use Time#in_time_zone() instead.