Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/birthday_integer.rb
Class Method Summary collapse
- .from_leap_yday(n, year = Date.today.year) ⇒ Object
- .from_leap_yday_with_feb_29_birthdays_on_mar_1_in_common_years(n, year = Date.today.year) ⇒ Object
Instance Method Summary collapse
Class Method Details
.from_leap_yday(n, year = Date.today.year) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/birthday_integer.rb', line 10 def from_leap_yday(n,year=Date.today.year) n = n.to_i raise ArgumentError, "Cannot convert yday #{n} since it is not between 1 and 366" unless n >= 1 && n <= 366 if leap?(year) || n > 60 new(year,3,1) - 61 + n elsif 60 == n raise ArgumentError, "There is no February 29th in #{year} since it is not a leap year" else new(year,1,1) - 1 + n end end |
.from_leap_yday_with_feb_29_birthdays_on_mar_1_in_common_years(n, year = Date.today.year) ⇒ Object
23 24 25 26 |
# File 'lib/birthday_integer.rb', line 23 def from_leap_yday_with_feb_29_birthdays_on_mar_1_in_common_years(n, year=Date.today.year) n = n + 1 if 60 == n && !leap?(year) from_leap_yday(n,year) end |
Instance Method Details
#leap_yday ⇒ Object
5 6 7 |
# File 'lib/birthday_integer.rb', line 5 def leap_yday yday + ((!leap? && yday >= 60) ? 1 : 0) end |