Module: Nextday::DateExtension

Included in:
Date, Time
Defined in:
lib/nextday/date_extension.rb

Instance Method Summary collapse

Instance Method Details

#cut_off_timeObject



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_dayDate

The next working day after an item has been despatched.

Returns:



26
27
28
# File 'lib/nextday/date_extension.rb', line 26

def delivery_day
  despatch_day.next_working_day
end

#despatch_dayDate

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.

Returns:



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_dayDate

The next working day after the current date

Returns:

  • (Date)

    Next Working Day



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_dayDate

The previous working day before the current date

Returns:

  • (Date)

    Previous Working Day



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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


70
71
72
# File 'lib/nextday/date_extension.rb', line 70

def working_day?
  !weekend? and !public_holiday?
end