Module: Nextday::DateExtension
Instance Method Summary collapse
- #cut_off_time ⇒ Object
-
#delivery_day ⇒ Date
The next working day after an item has been despatched.
-
#despatch_day ⇒ Date
The day an item or service will be despatched.
-
#next_working_day ⇒ Date
The next working day after the current date.
-
#previous_working_day ⇒ Date
The previous working day before the current date.
-
#public_holiday? ⇒ Boolean
Is the current date a public holiday?.
-
#weekend? ⇒ Boolean
Is the current date on the weekend?.
-
#working_day? ⇒ Boolean
Is the current date a working day?.
Instance Method Details
#cut_off_time ⇒ Object
30 31 32 33 34 |
# File 'lib/nextday/date_extension.rb', line 30 def cut_off_time hour, minute = Config.cut_off_hour, Config.cut_off_minute Time.new(year, month, day, hour, minute) end |
#delivery_day ⇒ Date
The next working day after an item has been despatched.
26 27 28 |
# File 'lib/nextday/date_extension.rb', line 26 def delivery_day despatch_day.next_working_day end |
#despatch_day ⇒ Date
The day an item or service will be despatched. If the warehouse closes at say 4:00pm then this will be taken into account and the despatch day will be the next working day.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nextday/date_extension.rb', line 10 def despatch_day if working_day? if to_time < cut_off_time to_date else next_working_day end else next_working_day end end |
#next_working_day ⇒ Date
The next working day after the current date
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/nextday/date_extension.rb', line 40 def next_working_day next_day = to_date + 1 # keep going until the next day is a working day while !next_day.working_day? next_day = next_day + 1 end next_day end |
#previous_working_day ⇒ Date
The previous working day before the current date
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/nextday/date_extension.rb', line 55 def previous_working_day previous_day = to_date - 1 # keep going until the next day is a working day while !previous_day.working_day? previous_day = previous_day - 1 end previous_day end |
#public_holiday? ⇒ Boolean
Is the current date a public holiday?
78 79 80 |
# File 'lib/nextday/date_extension.rb', line 78 def public_holiday? Holidays.dates.include?(to_date) end |
#weekend? ⇒ Boolean
Is the current date on the weekend?
86 87 88 |
# File 'lib/nextday/date_extension.rb', line 86 def weekend? saturday? or sunday? end |
#working_day? ⇒ Boolean
Is the current date a working day?
70 71 72 |
# File 'lib/nextday/date_extension.rb', line 70 def working_day? !weekend? and !public_holiday? end |