Get the named 'season' for a Time / Date / DateTime in ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module DateTimeUtils | |
def season | |
case self.month | |
when 3, 4, 5 | |
'Spring' | |
when 6, 7, 8 | |
'Summer' | |
when 9, 10, 11 | |
'Fall' | |
when 12, 1, 2 | |
'Winter' | |
end | |
end | |
end | |
class Time | |
include DateTimeUtils | |
end | |
class Date | |
include DateTimeUtils | |
end | |
class DateTime | |
include DateTimeUtils | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment