Skip to content

Instantly share code, notes, and snippets.

@rbaulin
Created March 30, 2015 18:47
Show Gist options
  • Save rbaulin/ff38a7a14dfa163ac5c8 to your computer and use it in GitHub Desktop.
Save rbaulin/ff38a7a14dfa163ac5c8 to your computer and use it in GitHub Desktop.
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