diff options
author | Jon Pascoe <jon.pascoe@me.com> | 2015-11-10 09:26:48 +0000 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2015-11-11 07:08:49 +0100 |
commit | 2f4f4d2cf1e4c5a442459fc250daf66186d110fa (patch) | |
tree | cc5410d285ed5d3de6257ba681fce53d7f31299e /activesupport/lib/active_support | |
parent | 9ccb341fbf1ae1bb46a0f638bf35a4bcffe06297 (diff) | |
download | rails-2f4f4d2cf1e4c5a442459fc250daf66186d110fa.tar.gz rails-2f4f4d2cf1e4c5a442459fc250daf66186d110fa.tar.bz2 rails-2f4f4d2cf1e4c5a442459fc250daf66186d110fa.zip |
Add days_in_year method
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 82e003fc3b..675db8a36b 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -26,6 +26,12 @@ class Time end end + # Returns the number of days in the given year. + # If no year is specified, it will use the current year. + def days_in_year(year = current.year) + days_in_month(2, year) + 337 + end + # Returns <tt>Time.zone.now</tt> when <tt>Time.zone</tt> or <tt>config.time_zone</tt> are set, otherwise just returns <tt>Time.now</tt>. def current ::Time.zone ? ::Time.zone.now : ::Time.now |