working_hours 0.9.0

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.
@@ -0,0 +1,181 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorkingHours::CoreExt::DateAndTime do
4
+ let(:duration) { 5.working.days }
5
+
6
+ describe 'operator +' do
7
+ it 'works with Time objects' do
8
+ time = Time.now
9
+ expect(duration).to receive(:add_days).with(time, 5)
10
+ time + duration
11
+ end
12
+
13
+ it 'works with Date objects' do
14
+ date = Date.today
15
+ expect(duration).to receive(:add_days).with(date, 5)
16
+ date + duration
17
+ end
18
+
19
+ it 'works with DateTime objects' do
20
+ date_time = DateTime.now
21
+ expect(duration).to receive(:add_days).with(date_time, 5)
22
+ date_time + duration
23
+ end
24
+
25
+ it 'works with ActiveSupport::TimeWithZone' do
26
+ time = Time.now.in_time_zone('Tokyo')
27
+ expect(duration).to receive(:add_days).with(time, 5)
28
+ time + duration
29
+ end
30
+
31
+ it "doesn't break original operator" do
32
+ time = Time.now
33
+ expect(duration).not_to receive(:add_days)
34
+ expect(time + 3600).to eq(time + 1.hour)
35
+ end
36
+ end
37
+
38
+ describe 'operator -' do
39
+ it 'works with Time objects' do
40
+ time = Time.now
41
+ expect(duration).to receive(:add_days).with(time, -5)
42
+ time - duration
43
+ end
44
+
45
+ it 'works with Date objects' do
46
+ date = Date.today
47
+ expect(duration).to receive(:add_days).with(date, -5)
48
+ date - duration
49
+ end
50
+
51
+ it 'works with DateTime objects' do
52
+ date_time = DateTime.now
53
+ expect(duration).to receive(:add_days).with(date_time, -5)
54
+ date_time - duration
55
+ end
56
+
57
+ it 'works with ActiveSupport::TimeWithZone' do
58
+ time = Time.now.in_time_zone('Tokyo')
59
+ expect(duration).to receive(:add_days).with(time, -5)
60
+ time - duration
61
+ end
62
+
63
+ it "doesn't break original operator" do
64
+ time = Time.now
65
+ expect(duration).not_to receive(:add_days)
66
+ expect(time - 3600).to eq(time - 1.hour)
67
+ end
68
+ end
69
+
70
+ describe '#working_days_until' do
71
+ it 'works with Time objects' do
72
+ from = Time.new(1991, 11, 15)
73
+ to = Time.new(1991, 11, 22)
74
+ expect(WorkingHours).to receive(:working_days_between).with(from, to)
75
+ from.working_days_until(to)
76
+ end
77
+
78
+ it 'works with Date objects' do
79
+ from = Date.new(1991, 11, 15)
80
+ to = Date.new(1991, 11, 22)
81
+ expect(WorkingHours).to receive(:working_days_between).with(from, to)
82
+ from.working_days_until(to)
83
+ end
84
+
85
+ it 'works with DateTime objects' do
86
+ from = DateTime.new(1991, 11, 15)
87
+ to = DateTime.new(1991, 11, 22)
88
+ expect(WorkingHours).to receive(:working_days_between).with(from, to)
89
+ from.working_days_until(to)
90
+ end
91
+
92
+ it 'works with ActiveSupport::TimeWithZone' do
93
+ from = Time.new(1991, 11, 15).in_time_zone('Tokyo')
94
+ to = Time.new(1991, 11, 22).in_time_zone('Tokyo')
95
+ expect(WorkingHours).to receive(:working_days_between).with(from, to)
96
+ from.working_days_until(to)
97
+ end
98
+ end
99
+
100
+ describe '#working_time_until' do
101
+ it 'works with Time objects' do
102
+ from = Time.new(1991, 11, 15)
103
+ to = Time.new(1991, 11, 22)
104
+ expect(WorkingHours).to receive(:working_time_between).with(from, to)
105
+ from.working_time_until(to)
106
+ end
107
+
108
+ it 'works with Date objects' do
109
+ from = Date.new(1991, 11, 15)
110
+ to = Date.new(1991, 11, 22)
111
+ expect(WorkingHours).to receive(:working_time_between).with(from, to)
112
+ from.working_time_until(to)
113
+ end
114
+
115
+ it 'works with DateTime objects' do
116
+ from = DateTime.new(1991, 11, 15)
117
+ to = DateTime.new(1991, 11, 22)
118
+ expect(WorkingHours).to receive(:working_time_between).with(from, to)
119
+ from.working_time_until(to)
120
+ end
121
+
122
+ it 'works with ActiveSupport::TimeWithZone' do
123
+ from = Time.new(1991, 11, 15).in_time_zone('Tokyo')
124
+ to = Time.new(1991, 11, 22).in_time_zone('Tokyo')
125
+ expect(WorkingHours).to receive(:working_time_between).with(from, to)
126
+ from.working_time_until(to)
127
+ end
128
+ end
129
+
130
+ describe '#working_day?' do
131
+ it 'works with Time objects' do
132
+ time = Time.new(1991, 11, 15)
133
+ expect(WorkingHours).to receive(:working_day?).with(time)
134
+ time.working_day?
135
+ end
136
+
137
+ it 'works with Date objects' do
138
+ time = Date.new(1991, 11, 15)
139
+ expect(WorkingHours).to receive(:working_day?).with(time)
140
+ time.working_day?
141
+ end
142
+
143
+ it 'works with DateTime objects' do
144
+ time = DateTime.new(1991, 11, 15)
145
+ expect(WorkingHours).to receive(:working_day?).with(time)
146
+ time.working_day?
147
+ end
148
+
149
+ it 'works with ActiveSupport::TimeWithZone' do
150
+ time = Time.new(1991, 11, 15).in_time_zone('Tokyo')
151
+ expect(WorkingHours).to receive(:working_day?).with(time)
152
+ time.working_day?
153
+ end
154
+ end
155
+
156
+ describe '#in_working_hours?' do
157
+ it 'works with Time objects' do
158
+ time = Time.new(1991, 11, 15)
159
+ expect(WorkingHours).to receive(:in_working_hours?).with(time)
160
+ time.in_working_hours?
161
+ end
162
+
163
+ it 'works with Date objects' do
164
+ time = Date.new(1991, 11, 15)
165
+ expect(WorkingHours).to receive(:in_working_hours?).with(time)
166
+ time.in_working_hours?
167
+ end
168
+
169
+ it 'works with DateTime objects' do
170
+ time = DateTime.new(1991, 11, 15)
171
+ expect(WorkingHours).to receive(:in_working_hours?).with(time)
172
+ time.in_working_hours?
173
+ end
174
+
175
+ it 'works with ActiveSupport::TimeWithZone' do
176
+ time = Time.new(1991, 11, 15).in_time_zone('Tokyo')
177
+ expect(WorkingHours).to receive(:in_working_hours?).with(time)
178
+ time.in_working_hours?
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorkingHours::CoreExt::Fixnum do
4
+
5
+ describe '#working' do
6
+ it 'returns a DurationProxy' do
7
+ proxy = 42.working
8
+ expect(proxy).to be_kind_of(WorkingHours::DurationProxy)
9
+ expect(proxy.value).to eq(42)
10
+ end
11
+ end
12
+
13
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorkingHours::DurationProxy do
4
+ describe '#initialize' do
5
+ it 'is constructed with a value' do
6
+ proxy = WorkingHours::DurationProxy.new(42)
7
+ expect(proxy.value).to eq(42)
8
+ end
9
+ end
10
+
11
+ context 'proxy methods' do
12
+
13
+ let(:proxy) { WorkingHours::DurationProxy.new(42) }
14
+
15
+ WorkingHours::Duration::SUPPORTED_KINDS.each do |kind|
16
+ singular = kind[0..-2]
17
+
18
+ it "##{kind} returns a duration object" do
19
+ duration = proxy.send(kind)
20
+ expect(duration.value).to eq(42)
21
+ expect(duration.kind).to eq(kind)
22
+ end
23
+
24
+ it "##{singular} returns a duration object" do
25
+ duration = proxy.send(singular)
26
+ expect(duration.value).to eq(42)
27
+ expect(duration.kind).to eq(kind)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,78 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorkingHours::Duration do
4
+
5
+ describe '#initialize' do
6
+ it 'is initialized with a number and a type' do
7
+ duration = WorkingHours::Duration.new(5, :days)
8
+ expect(duration.value).to eq(5)
9
+ expect(duration.kind).to eq(:days)
10
+ end
11
+
12
+ it 'should work with days' do
13
+ duration = WorkingHours::Duration.new(42, :days)
14
+ expect(duration.kind).to eq(:days)
15
+ end
16
+
17
+ it 'should work with hours' do
18
+ duration = WorkingHours::Duration.new(42, :hours)
19
+ expect(duration.kind).to eq(:hours)
20
+ end
21
+
22
+ it 'should work with minutes' do
23
+ duration = WorkingHours::Duration.new(42, :minutes)
24
+ expect(duration.kind).to eq(:minutes)
25
+ end
26
+
27
+ it 'should work with seconds' do
28
+ duration = WorkingHours::Duration.new(42, :seconds)
29
+ expect(duration.kind).to eq(:seconds)
30
+ end
31
+
32
+ it 'should not work with anything else' do
33
+ expect {
34
+ duration = WorkingHours::Duration.new(42, :foo)
35
+ }.to raise_error ArgumentError, "Invalid working time unit: foo"
36
+ end
37
+ end
38
+
39
+ describe '#-@' do
40
+ it 'inverses value' do
41
+ expect(-2.working.days).to eq(WorkingHours::Duration.new(-2, :days))
42
+ expect(-(-1.working.hour)).to eq(WorkingHours::Duration.new(1, :hours))
43
+ end
44
+ end
45
+
46
+ describe '#since' do
47
+ it "performs addition with Time.now" do
48
+ Timecop.freeze(Time.utc(1991, 11, 15, 21)) # we are Friday 21 pm UTC
49
+ expect(1.working.day.since).to eq(Time.utc(1991, 11, 18, 21))
50
+ end
51
+
52
+ it "is aliased to from_now" do
53
+ Timecop.freeze(Time.utc(1991, 11, 15, 21)) # we are Friday 21 pm UTC
54
+ expect(1.working.day.from_now).to eq(Time.utc(1991, 11, 18, 21))
55
+ end
56
+
57
+ it "accepts reference time as argument" do
58
+ expect(1.working.day.since(Time.utc(1991, 11, 15, 21))).to eq(Time.utc(1991, 11, 18, 21))
59
+ end
60
+ end
61
+
62
+ describe '#until' do
63
+ it "performs substraction with Time.now" do
64
+ Timecop.freeze(Time.utc(1991, 11, 15, 21)) # we are Friday 21 pm UTC
65
+ expect(7.working.day.until).to eq(Time.utc(1991, 11, 6, 21))
66
+ end
67
+
68
+ it "is aliased to ago" do
69
+ Timecop.freeze(Time.utc(1991, 11, 15, 21)) # we are Friday 21 pm UTC
70
+ expect(7.working.day.ago).to eq(Time.utc(1991, 11, 6, 21))
71
+ end
72
+
73
+ it "accepts reference time as argument" do
74
+ expect(7.working.day.until(Time.utc(1991, 11, 15, 21))).to eq(Time.utc(1991, 11, 6, 21))
75
+ end
76
+ end
77
+
78
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe WorkingHours do
4
+
5
+ it 'can be used to call computation methods' do
6
+ [ :advance_to_working_time, :return_to_working_time,
7
+ :working_day?, :in_working_hours?,
8
+ :working_days_between, :working_time_between
9
+ ].each do |method|
10
+ expect(WorkingHours).to respond_to(method)
11
+ end
12
+ end
13
+
14
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'working_hours/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "working_hours"
8
+ spec.version = WorkingHours::VERSION
9
+ spec.authors = ["Adrien Jarthon", "Intrepidd"]
10
+ spec.email = ["me@adrienjarthon.com", "adrien@siami.fr"]
11
+ spec.summary = %q{time calculation with working hours}
12
+ spec.description = %q{A modern ruby gem allowing to do time calculation with working hours.}
13
+ spec.homepage = "https://github.com/intrepidd/working_hours"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'activesupport', '>= 3.2'
22
+ spec.add_dependency 'tzinfo'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'timecop'
28
+ end
metadata ADDED
@@ -0,0 +1,168 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: working_hours
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrien Jarthon
8
+ - Intrepidd
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-08-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: activesupport
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '3.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: tzinfo
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '1.5'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '1.5'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: timecop
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - ">="
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ description: A modern ruby gem allowing to do time calculation with working hours.
99
+ email:
100
+ - me@adrienjarthon.com
101
+ - adrien@siami.fr
102
+ executables: []
103
+ extensions: []
104
+ extra_rdoc_files: []
105
+ files:
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - gemfiles/Gemfile.activesupport-3.2.x
114
+ - gemfiles/Gemfile.activesupport-4.0.x
115
+ - gemfiles/Gemfile.activesupport-4.1.x
116
+ - gemfiles/Gemfile.activesupport-head
117
+ - lib/working_hours.rb
118
+ - lib/working_hours/computation.rb
119
+ - lib/working_hours/config.rb
120
+ - lib/working_hours/core_ext/date_and_time.rb
121
+ - lib/working_hours/core_ext/fixnum.rb
122
+ - lib/working_hours/deep_freeze.rb
123
+ - lib/working_hours/duration.rb
124
+ - lib/working_hours/duration_proxy.rb
125
+ - lib/working_hours/module.rb
126
+ - lib/working_hours/version.rb
127
+ - spec/spec_helper.rb
128
+ - spec/working_hours/computation_spec.rb
129
+ - spec/working_hours/config_spec.rb
130
+ - spec/working_hours/core_ext/date_and_time_spec.rb
131
+ - spec/working_hours/core_ext/fixnum_spec.rb
132
+ - spec/working_hours/duration_proxy_spec.rb
133
+ - spec/working_hours/duration_spec.rb
134
+ - spec/working_hours_spec.rb
135
+ - working_hours.gemspec
136
+ homepage: https://github.com/intrepidd/working_hours
137
+ licenses:
138
+ - MIT
139
+ metadata: {}
140
+ post_install_message:
141
+ rdoc_options: []
142
+ require_paths:
143
+ - lib
144
+ required_ruby_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - ">="
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ required_rubygems_version: !ruby/object:Gem::Requirement
150
+ requirements:
151
+ - - ">="
152
+ - !ruby/object:Gem::Version
153
+ version: '0'
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 2.2.2
157
+ signing_key:
158
+ specification_version: 4
159
+ summary: time calculation with working hours
160
+ test_files:
161
+ - spec/spec_helper.rb
162
+ - spec/working_hours/computation_spec.rb
163
+ - spec/working_hours/config_spec.rb
164
+ - spec/working_hours/core_ext/date_and_time_spec.rb
165
+ - spec/working_hours/core_ext/fixnum_spec.rb
166
+ - spec/working_hours/duration_proxy_spec.rb
167
+ - spec/working_hours/duration_spec.rb
168
+ - spec/working_hours_spec.rb