working_hours 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +15 -5
- data/lib/working_hours/config.rb +4 -4
- data/lib/working_hours/duration.rb +2 -3
- data/lib/working_hours/version.rb +1 -1
- data/spec/working_hours/config_spec.rb +9 -3
- data/spec/working_hours/core_ext/date_and_time_spec.rb +10 -10
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 44ded3c576ee838fd8e2a6160499e60f2c7e585e
|
4
|
+
data.tar.gz: 2f1bab0453dd93d3b3cd70d72a829ea8eac82ac4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0b37d42c5460735f2b80e2e92e34d74b1fb0355ad87e0c2ff34d1149418d20e92572a3ec867f4513b2cb486bc0918d40fbf242ab2e398b6f8ef7ed5bcfcc6a3
|
7
|
+
data.tar.gz: 512fdd659f82340e7b1d5b88a564032e27a61f739cd2c5b70947947a78b0cab09201e5492c29455ef2bb7501a0fe04c9595003edc67955aeb3cccff18e9c0107
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
-
[Compare master with v1.0.
|
3
|
+
[Compare master with v1.0.3](https://github.com/intrepidd/working_hours/compare/v1.0.3...master)
|
4
|
+
|
5
|
+
# v1.0.3
|
6
|
+
|
7
|
+
* Relax configuration input formats - [#10](https://github.com/Intrepidd/working_hours/pull/10)
|
8
|
+
* Small improvements to the Readme
|
9
|
+
|
10
|
+
_08/11/2014_
|
4
11
|
|
5
12
|
# v1.0.2
|
6
13
|
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
A modern ruby gem allowing to do time calculation with working hours.
|
6
6
|
|
7
7
|
Compatible and tested with:
|
8
|
-
- Ruby `2.0`, `2.1`
|
8
|
+
- Ruby `2.0`, `2.1`, JRuby `1.7`
|
9
9
|
- ActiveSupport `3.2.x`, `4.0.x` and `4.1.x`
|
10
10
|
|
11
11
|
## Installation
|
@@ -36,6 +36,8 @@ Date.new(2014, 12, 31) + 8.working.days # => Mon, 12 Jan 2015
|
|
36
36
|
Time.utc(2014, 8, 4, 8, 32) - 4.working.hours # => 2014-08-01 13:00:00
|
37
37
|
|
38
38
|
# Compute working days between two dates
|
39
|
+
friday = Date.new(2014, 10, 17)
|
40
|
+
monday = Date.new(2014, 10, 20)
|
39
41
|
friday.working_days_until(monday) # => 1
|
40
42
|
# Time is considered at end of day, so:
|
41
43
|
# - friday to saturday = 0 working days
|
@@ -51,6 +53,12 @@ Date.new(2014, 12, 28).working_day? # => false
|
|
51
53
|
|
52
54
|
# Know if a time is worked
|
53
55
|
Time.utc(2014, 8, 4, 7, 16).in_working_hours? # => false
|
56
|
+
|
57
|
+
# Advance to next working time
|
58
|
+
WorkingHours.advance_to_working_time(Time.utc(2014, 8, 4, 7, 16)) # => Mon, 04 Aug 2014 09:00:00 UTC +00:00
|
59
|
+
|
60
|
+
# Return to previous working time
|
61
|
+
WorkingHours.return_to_working_time(Time.utc(2014, 8, 4, 7, 16)) # => Fri, 01 Aug 2014 17:00:00 UTC +00:00
|
54
62
|
```
|
55
63
|
|
56
64
|
## Configuration
|
@@ -96,6 +104,8 @@ WorkingHours::Duration.new(8, :days).since(Date.new(2014, 12, 31)) # => Mon, 12
|
|
96
104
|
WorkingHours::Duration.new(4, :hours).until(Time.utc(2014, 8, 4, 8, 32)) # => 2014-08-01 13:00:00
|
97
105
|
|
98
106
|
# Compute working days between two dates
|
107
|
+
friday = Date.new(2014, 10, 17)
|
108
|
+
monday = Date.new(2014, 10, 20)
|
99
109
|
WorkingHours.working_days_between(friday, monday) # => 1
|
100
110
|
# Time is considered at end of day, so:
|
101
111
|
# - friday to saturday = 0 working days
|
@@ -123,12 +133,12 @@ require 'working_hours/module'
|
|
123
133
|
class Order
|
124
134
|
include WorkingHours
|
125
135
|
|
126
|
-
def
|
127
|
-
Duration.new(2, :days).since(
|
136
|
+
def shipping_date_estibmate
|
137
|
+
Duration.new(2, :days).since(payment_received_at)
|
128
138
|
end
|
129
139
|
|
130
|
-
def
|
131
|
-
working_days_between(created_at,
|
140
|
+
def payment_delay
|
141
|
+
working_days_between(created_at, payment_received_at)
|
132
142
|
end
|
133
143
|
end
|
134
144
|
```
|
data/lib/working_hours/config.rb
CHANGED
@@ -106,7 +106,7 @@ module WorkingHours
|
|
106
106
|
raise InvalidConfiguration.new "No working hours given for day `#{day}`"
|
107
107
|
end
|
108
108
|
last_time = nil
|
109
|
-
hours.each do |start, finish|
|
109
|
+
hours.sort.each do |start, finish|
|
110
110
|
if not start =~ TIME_FORMAT
|
111
111
|
raise InvalidConfiguration.new "Invalid time: #{start} - must be 'HH:MM'"
|
112
112
|
elsif not finish =~ TIME_FORMAT
|
@@ -122,10 +122,10 @@ module WorkingHours
|
|
122
122
|
end
|
123
123
|
|
124
124
|
def validate_holidays! holidays
|
125
|
-
if not holidays.
|
126
|
-
raise InvalidConfiguration.new "Invalid type for holidays: #{holidays.class} - must
|
125
|
+
if not holidays.respond_to?(:to_a)
|
126
|
+
raise InvalidConfiguration.new "Invalid type for holidays: #{holidays.class} - must act like an array"
|
127
127
|
end
|
128
|
-
holidays.each do |day|
|
128
|
+
holidays.to_a.each do |day|
|
129
129
|
if not day.is_a? Date
|
130
130
|
raise InvalidConfiguration.new "Invalid holiday: #{day} - must be Date"
|
131
131
|
end
|
@@ -3,7 +3,6 @@ require 'working_hours/computation'
|
|
3
3
|
|
4
4
|
module WorkingHours
|
5
5
|
class Duration
|
6
|
-
include Computation
|
7
6
|
|
8
7
|
attr_accessor :value, :kind
|
9
8
|
|
@@ -17,12 +16,12 @@ module WorkingHours
|
|
17
16
|
|
18
17
|
# Computation methods
|
19
18
|
def until(time = ::Time.current)
|
20
|
-
send("add_#{@kind}", time, -@value)
|
19
|
+
::WorkingHours.send("add_#{@kind}", time, -@value)
|
21
20
|
end
|
22
21
|
alias :ago :until
|
23
22
|
|
24
23
|
def since(time = ::Time.current)
|
25
|
-
send("add_#{@kind}", time, @value)
|
24
|
+
::WorkingHours.send("add_#{@kind}", time, @value)
|
26
25
|
end
|
27
26
|
alias :from_now :since
|
28
27
|
|
@@ -101,6 +101,12 @@ describe WorkingHours::Config do
|
|
101
101
|
WorkingHours::Config.working_hours = {:mon => {'08:00' => '13:00', '12:00' => '18:00'}}
|
102
102
|
}.to raise_error(WorkingHours::InvalidConfiguration, "Invalid range: 12:00 => 18:00 - overlaps previous range")
|
103
103
|
end
|
104
|
+
|
105
|
+
it 'does not reject out-of-order, non-overlapping ranges' do
|
106
|
+
expect {
|
107
|
+
WorkingHours::Config.working_hours = {:mon => {'10:00' => '11:00', '08:00' => '09:00'}}
|
108
|
+
}.not_to raise_error
|
109
|
+
end
|
104
110
|
end
|
105
111
|
end
|
106
112
|
|
@@ -123,10 +129,10 @@ describe WorkingHours::Config do
|
|
123
129
|
end
|
124
130
|
|
125
131
|
describe 'validation' do
|
126
|
-
it 'rejects
|
132
|
+
it 'rejects types that cannot be converted into an array' do
|
127
133
|
expect {
|
128
|
-
WorkingHours::Config.holidays =
|
129
|
-
}.to raise_error(WorkingHours::InvalidConfiguration, "Invalid type for holidays:
|
134
|
+
WorkingHours::Config.holidays = Object.new
|
135
|
+
}.to raise_error(WorkingHours::InvalidConfiguration, "Invalid type for holidays: Object - must act like an array")
|
130
136
|
end
|
131
137
|
|
132
138
|
it 'rejects invalid day' do
|
@@ -6,31 +6,31 @@ describe WorkingHours::CoreExt::DateAndTime do
|
|
6
6
|
describe 'operator +' do
|
7
7
|
it 'works with Time objects' do
|
8
8
|
time = Time.now
|
9
|
-
expect(
|
9
|
+
expect(WorkingHours).to receive(:add_days).with(time, 5)
|
10
10
|
time + duration
|
11
11
|
end
|
12
12
|
|
13
13
|
it 'works with Date objects' do
|
14
14
|
date = Date.today
|
15
|
-
expect(
|
15
|
+
expect(WorkingHours).to receive(:add_days).with(date, 5)
|
16
16
|
date + duration
|
17
17
|
end
|
18
18
|
|
19
19
|
it 'works with DateTime objects' do
|
20
20
|
date_time = DateTime.now
|
21
|
-
expect(
|
21
|
+
expect(WorkingHours).to receive(:add_days).with(date_time, 5)
|
22
22
|
date_time + duration
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'works with ActiveSupport::TimeWithZone' do
|
26
26
|
time = Time.now.in_time_zone('Tokyo')
|
27
|
-
expect(
|
27
|
+
expect(WorkingHours).to receive(:add_days).with(time, 5)
|
28
28
|
time + duration
|
29
29
|
end
|
30
30
|
|
31
31
|
it "doesn't break original operator" do
|
32
32
|
time = Time.now
|
33
|
-
expect(
|
33
|
+
expect(WorkingHours).not_to receive(:add_days)
|
34
34
|
expect(time + 3600).to eq(time + 1.hour)
|
35
35
|
end
|
36
36
|
end
|
@@ -38,31 +38,31 @@ describe WorkingHours::CoreExt::DateAndTime do
|
|
38
38
|
describe 'operator -' do
|
39
39
|
it 'works with Time objects' do
|
40
40
|
time = Time.now
|
41
|
-
expect(
|
41
|
+
expect(WorkingHours).to receive(:add_days).with(time, -5)
|
42
42
|
time - duration
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'works with Date objects' do
|
46
46
|
date = Date.today
|
47
|
-
expect(
|
47
|
+
expect(WorkingHours).to receive(:add_days).with(date, -5)
|
48
48
|
date - duration
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'works with DateTime objects' do
|
52
52
|
date_time = DateTime.now
|
53
|
-
expect(
|
53
|
+
expect(WorkingHours).to receive(:add_days).with(date_time, -5)
|
54
54
|
date_time - duration
|
55
55
|
end
|
56
56
|
|
57
57
|
it 'works with ActiveSupport::TimeWithZone' do
|
58
58
|
time = Time.now.in_time_zone('Tokyo')
|
59
|
-
expect(
|
59
|
+
expect(WorkingHours).to receive(:add_days).with(time, -5)
|
60
60
|
time - duration
|
61
61
|
end
|
62
62
|
|
63
63
|
it "doesn't break original operator" do
|
64
64
|
time = Time.now
|
65
|
-
expect(
|
65
|
+
expect(WorkingHours).not_to receive(:add_days)
|
66
66
|
expect(time - 3600).to eq(time - 1.hour)
|
67
67
|
end
|
68
68
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: working_hours
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adrien Jarthon
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-11-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|