13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/extended_date.rb', line 13
def first_day_of_month(day)
req_wday = case
when ["sunday", "0"].include?(day.to_s.downcase) then 0
when ["monday", "1"].include?(day.to_s.downcase) then 1
when ["tuesday", "2"].include?(day.to_s.downcase) then 2
when ["wednesday", "3"].include?(day.to_s.downcase) then 3
when ["thursday", "4"].include?(day.to_s.downcase) then 4
when ["friday", "5"].include?(day.to_s.downcase) then 5
when ["saturday", "6"].include?(day.to_s.downcase) then 6
else "Unknown"
end
if req_wday == "Unknown"
result = "Invalid Input"
else
req_days = (req_wday - beginning_of_month.wday)
req_days = ((req_days>=0) ? req_days : (7+req_days))
result = beginning_of_month + req_days
end
end
|