diff options
author | Andrew White <pixeltrix@users.noreply.github.com> | 2015-11-10 17:13:01 +0000 |
---|---|---|
committer | Andrew White <pixeltrix@users.noreply.github.com> | 2015-11-10 17:13:01 +0000 |
commit | 6c3db3652faaa54e4e0b052e4042717c73f0d2f8 (patch) | |
tree | 02e92e3ea020bf4b13dfb3f7be2d66ac6dcf5583 /activesupport/lib | |
parent | 320b79f54c9ae543eeb62581611b2d36d5f66d41 (diff) | |
parent | 55b463f599dafc719da4a395f77482049b00f2d7 (diff) | |
download | rails-6c3db3652faaa54e4e0b052e4042717c73f0d2f8.tar.gz rails-6c3db3652faaa54e4e0b052e4042717c73f0d2f8.tar.bz2 rails-6c3db3652faaa54e4e0b052e4042717c73f0d2f8.zip |
Merge pull request #22244 from pacso/time-days-in-year
Add days_in_year method to Time class
Diffstat (limited to 'activesupport/lib')
-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 |