diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-25 17:15:49 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-25 17:15:49 +0100 |
commit | e959c0fe4c887154bbe28c31324fef2975cbe467 (patch) | |
tree | 3088c7a1f389944d613e57b551b452f7ec83181d /lib/mauve/mauve_time.rb | |
parent | 5fff12fc11cb8b02a44fd40ed78fa9d196f269d7 (diff) |
Big update.
* Max acknowledgement time is now specified in the config
* Calendar interface improved.
* holiday_url no longer used -- replaced by notify_when_on_holiday!
* added notify_when_off_sick!
* Added ability for the calendar to be queried for a list of bank holdays.
* Added ability for Time to be given a list of bank holidays to check against.
* PeopleLists can now be a Proc, allowing downloading of lists
* Person is no longer a struct
* Moved the method_missing bit into ObjectBuilder from various sub classes.
* Added tests for the calendar interface
* Updated tests in other bits.
Diffstat (limited to 'lib/mauve/mauve_time.rb')
-rw-r--r-- | lib/mauve/mauve_time.rb | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/lib/mauve/mauve_time.rb b/lib/mauve/mauve_time.rb index f564fdb..dfbf99b 100644 --- a/lib/mauve/mauve_time.rb +++ b/lib/mauve/mauve_time.rb @@ -98,12 +98,37 @@ class Time t end + # Returns the bank_holidays array, or an empty array if bank_holidays hasn't + # been set. + # + # + def bank_holidays + @bank_holidays ||= [] + end + + # This sets the bank holiday dates for the bank_holiday? check. + # + # @param [Array] arg An array of Date of bank holidays + # @returns [Array] + # + def bank_holidays=(arg) + raise ArgumentError unless arg.is_a?(Array) and arg.all?{|a| a.is_a?(Date)} + @bank_holidays = arg + end + + # This relies on bank_holidays being set. + # + def bank_holiday? + today = Date.new(self.year, self.month, self.day) + self.bank_holidays.any?{|bh| bh == today} + end + # Test to see if we're in working hours. The working day is from 8.30am until # 17:00 # # @return [Boolean] def working_hours? - (1..5).include?(self.wday) and ((9..16).include?(self.hour) or (self.hour == 8 && self.min >= 30)) + !bank_holiday? and (1..5).include?(self.wday) and ((9..16).include?(self.hour) or (self.hour == 8 && self.min >= 30)) end # Test to see if it is currently daytime. The daytime day is 14 hours long @@ -113,7 +138,6 @@ class Time (8..21).include?(self.hour) end - # We're always in wallclock hours # # @return [true] |