|
59 | 59 | expect(add_hours(time, 2)).to eq(Time.utc(1991, 11, 15, 16, 00, 42))
|
60 | 60 | end
|
61 | 61 |
|
| 62 | + it 'can substract working hours' do |
| 63 | + time = Time.utc(1991, 11, 18, 14, 00, 42) # Monday |
| 64 | + expect(add_hours(time, -7)).to eq(Time.utc(1991, 11, 15, 15, 00, 42)) # Friday |
| 65 | + end |
| 66 | + |
62 | 67 | it 'accepts time given from any time zone' do
|
63 | 68 | time = Time.utc(1991, 11, 15, 7, 0, 0) # Friday 7 am UTC
|
64 | 69 | WorkingHours::Config.time_zone = 'Tokyo' # But we are at tokyo, so it's already 4 pm
|
|
119 | 124 | end
|
120 | 125 | end
|
121 | 126 |
|
| 127 | + describe '.return_to_working_time' do |
| 128 | + it 'jumps non-working day' do |
| 129 | + WorkingHours::Config.holidays = [Date.new(2014, 5, 1)] |
| 130 | + expect(return_to_working_time(Time.utc(2014, 5, 1, 12, 0))).to eq(Time.utc(2014, 4, 30, 17)) |
| 131 | + expect(return_to_working_time(Time.utc(2014, 6, 1, 12, 0))).to eq(Time.utc(2014, 5, 30, 17)) |
| 132 | + end |
| 133 | + |
| 134 | + it 'returns self during working hours' do |
| 135 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 9, 1))).to eq(Time.utc(2014, 4, 7, 9, 1)) |
| 136 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 17, 0))).to eq(Time.utc(2014, 4, 7, 17, 0)) |
| 137 | + end |
| 138 | + |
| 139 | + it 'jumps outside working hours' do |
| 140 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 17, 1))).to eq(Time.utc(2014, 4, 7, 17, 0)) |
| 141 | + expect(return_to_working_time(Time.utc(2014, 4, 8, 9, 0))).to eq(Time.utc(2014, 4, 7, 17, 0)) |
| 142 | + end |
| 143 | + |
| 144 | + it 'move between timespans' do |
| 145 | + WorkingHours::Config.working_hours = {mon: {'07:00' => '12:00', '13:00' => '18:00'}} |
| 146 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 13, 1))).to eq(Time.utc(2014, 4, 7, 13, 1)) |
| 147 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 13, 0))).to eq(Time.utc(2014, 4, 7, 12, 0)) |
| 148 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 12, 1))).to eq(Time.utc(2014, 4, 7, 12, 0)) |
| 149 | + expect(return_to_working_time(Time.utc(2014, 4, 7, 12, 0))).to eq(Time.utc(2014, 4, 7, 12, 0)) |
| 150 | + end |
| 151 | + |
| 152 | + it 'works with any input timezone (converts to config)' do |
| 153 | + # Monday 1 am (-09:00) is 10am in UTC time, working time! |
| 154 | + expect(return_to_working_time(Time.new(2014, 4, 7, 1, 0, 0 , "-09:00"))).to eq(Time.utc(2014, 4, 7, 10)) |
| 155 | + expect(return_to_working_time(Time.new(2014, 4, 7, 22, 0, 0 , "+02:00"))).to eq(Time.utc(2014, 4, 7, 17)) |
| 156 | + end |
| 157 | + end |
| 158 | + |
122 | 159 | describe '.working_day?' do
|
123 | 160 | it 'returns true on working day' do
|
124 | 161 | expect(working_day?(Date.new(2014, 4, 7))).to be(true)
|
|
0 commit comments