From 55b463f599dafc719da4a395f77482049b00f2d7 Mon Sep 17 00:00:00 2001 From: Jon Pascoe Date: Tue, 10 Nov 2015 09:26:48 +0000 Subject: Add days_in_year method --- activesupport/lib/active_support/core_ext/time/calculations.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/lib') 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 Time.zone.now when Time.zone or config.time_zone are set, otherwise just returns Time.now. def current ::Time.zone ? ::Time.zone.now : ::Time.now -- cgit v1.2.3