Created
November 5, 2010 20:01
-
-
Save adambair/664689 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
| def self.defaults | |
| defaults = OpenStruct.new | |
| defaults.from_date = default_from_date | |
| defaults.to_date = default_to_date | |
| defaults | |
| end | |
| def self.default_from_date | |
| default_date - 1.year | |
| end | |
| def self.default_to_date | |
| default_date - 1.day | |
| end | |
| # Billing starts on the 1st, 5th, 10th, 15th, 20th, and 25th of each month | |
| # Round today's date into one of those dates. | |
| def self.default_date(date=Date.today) | |
| possible_starts = [1..4, 5..9, 10..14, 15..19, 20..24, 25..31] | |
| start_range = possible_starts.select {|x| x.include? date.day}.first | |
| Date.parse [date.month, start_range, date.year].join('/') | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment