working_hours 1.1.0 → 1.1.1
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/.gitignore +0 -0
- data/.rspec +0 -0
- data/.travis.yml +2 -1
- data/CHANGELOG.md +6 -1
- data/Gemfile +0 -0
- data/LICENSE.txt +0 -0
- data/README.md +1 -1
- data/Rakefile +0 -0
- data/gemfiles/Gemfile.activesupport-3.2.x +0 -0
- data/gemfiles/Gemfile.activesupport-4.0.x +0 -0
- data/gemfiles/Gemfile.activesupport-4.1.x +0 -0
- data/gemfiles/Gemfile.activesupport-head +0 -0
- data/lib/working_hours.rb +0 -0
- data/lib/working_hours/computation.rb +12 -5
- data/lib/working_hours/core_ext/fixnum.rb +0 -0
- data/lib/working_hours/duration_proxy.rb +0 -0
- data/lib/working_hours/module.rb +0 -0
- data/lib/working_hours/version.rb +1 -1
- data/spec/working_hours/computation_spec.rb +8 -2
- data/spec/working_hours/core_ext/fixnum_spec.rb +0 -0
- data/spec/working_hours/duration_proxy_spec.rb +0 -0
- data/spec/working_hours_spec.rb +0 -0
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdc5713f20da1316a29bf18573095ac9e92ccb6c
|
4
|
+
data.tar.gz: bf54ee89ba3f855fcdc0d791965cf23fd5c29d3c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99cd033ae02a2c9c25fbced88e1c265a891210c7a232e12bb32191fd3c9bcea652cf3f35bd6c50c3215277b190d3af56e73fbde20cff1bb6cdfb24e2a205e08f
|
7
|
+
data.tar.gz: 50f2ca92979404a58af287abd33dd7af125ad9366a43160804bbbf09ce2b7648d474c5bf598e583fef4c7394e28965c31a91cc26a3ebba35d71e12cba0cdff95
|
data/.gitignore
CHANGED
File without changes
|
data/.rspec
CHANGED
File without changes
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Unreleased
|
2
2
|
|
3
|
-
[Compare master with v1.1.
|
3
|
+
[Compare master with v1.1.1](https://github.com/intrepidd/working_hours/compare/v1.1.1...master)
|
4
|
+
|
5
|
+
# v1.1.1
|
6
|
+
* Fix infinite loop happening when rewinding seconds and crossing through midgnight
|
7
|
+
|
8
|
+
_18/08/2015_
|
4
9
|
|
5
10
|
# v1.1.0
|
6
11
|
* Config set globally is now properly inherited in new threads. This fixes the issue when setting the config once in an initializer won't work in threaded web servers.
|
data/Gemfile
CHANGED
File without changes
|
data/LICENSE.txt
CHANGED
File without changes
|
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`, JRuby `1.7`
|
8
|
+
- Ruby `2.0`, `2.1`, JRuby `1.7` ( with ruby 2 syntax support enabled )
|
9
9
|
- ActiveSupport `3.2.x`, `4.0.x` and `4.1.x`
|
10
10
|
|
11
11
|
## Installation
|
data/Rakefile
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/working_hours.rb
CHANGED
File without changes
|
@@ -49,7 +49,7 @@ module WorkingHours
|
|
49
49
|
end
|
50
50
|
while seconds < 0
|
51
51
|
# roll to previous business period
|
52
|
-
time =
|
52
|
+
time = return_to_exact_working_time(time, config: config)
|
53
53
|
# look at working ranges
|
54
54
|
time_in_day = time.seconds_since_midnight
|
55
55
|
config[:working_hours][time.wday].reverse_each do |from, to|
|
@@ -63,7 +63,7 @@ module WorkingHours
|
|
63
63
|
end
|
64
64
|
end
|
65
65
|
end
|
66
|
-
convert_to_original_format
|
66
|
+
convert_to_original_format(time.round, origin)
|
67
67
|
end
|
68
68
|
|
69
69
|
def advance_to_working_time time, config: nil
|
@@ -85,7 +85,14 @@ module WorkingHours
|
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
88
|
-
def return_to_working_time
|
88
|
+
def return_to_working_time(time, config: nil)
|
89
|
+
# return_to_exact_working_time may return values with a high number of milliseconds,
|
90
|
+
# this is necessary for the end of day hack, here we return a rounded value for the
|
91
|
+
# public API
|
92
|
+
return_to_exact_working_time(time, config: config).round
|
93
|
+
end
|
94
|
+
|
95
|
+
def return_to_exact_working_time time, config: nil
|
89
96
|
config ||= wh_config
|
90
97
|
time = in_config_zone(time, config: config).round
|
91
98
|
loop do
|
@@ -97,8 +104,8 @@ module WorkingHours
|
|
97
104
|
time_in_day = time.seconds_since_midnight
|
98
105
|
(config[:working_hours][time.wday] || {}).reverse_each do |from, to|
|
99
106
|
# round is used to suppress miliseconds hack from `end_of_day`
|
100
|
-
return time
|
101
|
-
return (time - (time_in_day - to))
|
107
|
+
return time if time_in_day > from and time_in_day <= to
|
108
|
+
return (time - (time_in_day - to)) if to <= time_in_day
|
102
109
|
end
|
103
110
|
# if none is found, go to previous day and loop
|
104
111
|
time = (time - 1.day).end_of_day
|
File without changes
|
File without changes
|
data/lib/working_hours/module.rb
CHANGED
File without changes
|
@@ -98,11 +98,17 @@ describe WorkingHours::Computation do
|
|
98
98
|
add_seconds(time, 120)
|
99
99
|
end
|
100
100
|
|
101
|
-
it 'supports midnight' do
|
101
|
+
it 'supports midnight when advancing time' do
|
102
102
|
WorkingHours::Config.working_hours = {:mon => {'00:00' => '24:00'}}
|
103
|
-
time = Time.utc(2014, 4, 7, 23, 59, 30) #
|
103
|
+
time = Time.utc(2014, 4, 7, 23, 59, 30) # Monday
|
104
104
|
expect(add_seconds(time, 60)).to eq(Time.utc(2014, 4, 14, 0, 0, 30))
|
105
105
|
end
|
106
|
+
|
107
|
+
it 'supports midnight when rewinding time' do
|
108
|
+
WorkingHours::Config.working_hours = {:mon => {'00:00' => '24:00'}, :tue => {'08:00' => '18:00'}}
|
109
|
+
time = Time.utc(2014, 4, 8, 0, 0, 30) # Tuesday
|
110
|
+
expect(add_seconds(time, -60)).to eq(Time.utc(2014, 4, 7, 23, 59, 00))
|
111
|
+
end
|
106
112
|
end
|
107
113
|
|
108
114
|
describe '#advance_to_working_time' do
|
File without changes
|
File without changes
|
data/spec/working_hours_spec.rb
CHANGED
File without changes
|
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.1.
|
4
|
+
version: 1.1.1
|
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: 2015-
|
12
|
+
date: 2015-08-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
version: '0'
|
155
155
|
requirements: []
|
156
156
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.2.
|
157
|
+
rubygems_version: 2.2.3
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: time calculation with working hours
|
@@ -167,4 +167,3 @@ test_files:
|
|
167
167
|
- spec/working_hours/duration_proxy_spec.rb
|
168
168
|
- spec/working_hours/duration_spec.rb
|
169
169
|
- spec/working_hours_spec.rb
|
170
|
-
has_rdoc:
|