working_hours 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4b1729fae716e9632d6944229a25e12b76c4acd3
4
- data.tar.gz: bf9c3b93eeee75439bbc09b05ecb7db36465ca0b
3
+ metadata.gz: fdc5713f20da1316a29bf18573095ac9e92ccb6c
4
+ data.tar.gz: bf54ee89ba3f855fcdc0d791965cf23fd5c29d3c
5
5
  SHA512:
6
- metadata.gz: c545c3b569235af36415d087c42eb54a9137f0bcc6c27a5a17dcfd85ac5efcd9440b6b671dc69193329c721c66b2b76a53767b0f9c9c92cb1ac68d4d6fc49e5b
7
- data.tar.gz: a1a2b0e842150465f06d7f6c89475f509416b83e86ea41a4dcedac8c55cff11bcac1d7f01fcc828d6c8fd600c0ab8660b9a65326fa75046eda1fdaf5c8aed78a
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
@@ -1,7 +1,8 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
- - 2.1.3
4
+ - 2.1.6
5
+ - 2.2.2
5
6
  - ruby-head
6
7
  - jruby-1.7.19
7
8
  - jruby-head
data/CHANGELOG.md CHANGED
@@ -1,6 +1,11 @@
1
1
  # Unreleased
2
2
 
3
- [Compare master with v1.1.0](https://github.com/intrepidd/working_hours/compare/v1.1.0...master)
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 = return_to_working_time(time, config: config)
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 time, origin
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 time, config: nil
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.round if time_in_day > from and time_in_day <= to
101
- return (time - (time_in_day - to)).round if to <= time_in_day
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
File without changes
@@ -1,3 +1,3 @@
1
1
  module WorkingHours
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.1"
3
3
  end
@@ -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) # Friday
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
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.0
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-04-03 00:00:00.000000000 Z
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.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: