Created
March 30, 2015 18:47
-
-
Save rbaulin/ff38a7a14dfa163ac5c8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
class Date | |
def quarter | |
case self.month | |
when 1,2,3 | |
return 1 | |
when 4,5,6 | |
return 2 | |
when 7,8,9 | |
return 3 | |
when 10,11,12 | |
return 4 | |
end | |
end | |
end | |
# Usage example: | |
Date.parse("1 jan").quarter # -> 1 | |
Date.parse("1 apr").quarter # -> 2 | |
Date.parse("1 jul").quarter # -> 3 | |
Date.parse("1 oct").quarter # -> 4 | |
Date.parse("31 dec").quarter # -> 4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment