Created
March 17, 2014 08:11
-
-
Save dladowitz/9595604 to your computer and use it in GitHub Desktop.
First Pass at Payday class
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
require 'date' | |
require 'active_support/core_ext/integer/inflections' | |
class Payday | |
def self.get_next_payday(date) | |
payday = Payday.get_next_standard_payday(date) | |
payday = Payday.weekend_adjustment(payday) | |
"Payday will be " + payday.strftime("%a %b #{payday.day.ordinalize}") | |
end | |
private | |
def self.get_next_standard_payday(date) | |
day, month, year = Payday.get_date_components(date) | |
if day == 1 | |
payday = date | |
elsif 2 <= day && day <= 15 | |
payday = Date.new(year, month, 15) | |
elsif 16 <= day && day <= 31 | |
month == 12 ? payday = Date.new(year + 1, 1, 1) : payday = Date.new(year, month + 1, 1) | |
end | |
end | |
def self.get_date_components(date) | |
return date.day, date.month, date.year | |
end | |
def self.weekend_adjustment(payday) | |
adjustment = 0 | |
if payday.saturday? | |
adjustment = 1 | |
elsif payday.sunday? | |
adjustment = 2 | |
end | |
payday - adjustment | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment