time_distribution 2.1.2 → 2.1.3

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: 5b9aff57e043eeec93dc76993c9242035a9388f3
4
- data.tar.gz: 5a9dcff82cb40cbbc5c55a3721e43a1556898be8
3
+ metadata.gz: ca61f02b3f75d9e133ad3d1b67f0772608d3b632
4
+ data.tar.gz: de0caf7ebe59a0f171d6e320cde5a6ec2e9fd823
5
5
  SHA512:
6
- metadata.gz: 0cf34b6ff59a5badb478fa88812e582fcf098817bf6f2451bd1ea748c6429ba79c9ffb956e9b9cf0eac270719afb36f8ba7730320fc5ca536297824c0d2c399d
7
- data.tar.gz: 5134c0979595a6f6838800482e3f10e1ce7b366a42a29aca0d4d6a07e2ca9659af3a0fec117982bc7e4af6b1565849be4e958f714d276c51cd96162190421bec
6
+ metadata.gz: ea6124b5235f268aa59db971b0562129d0a330f0e481af4f5fda3f1683ade077dc03ba8da9bb118c8fe0ed8457ecdbe27da9e62c1fd7d9102a8bb641c70d2297
7
+ data.tar.gz: 0c1a08594abed6da6335186e0279a806eb2b186c50b4ab2a926af4dcfb1b762ff808704d9cbc6216f0b22895052e823d7993bb4c3384b2a4c978e2355df418df
@@ -10,12 +10,15 @@ module TimeDistribution
10
10
  def self.parse(time_period)
11
11
  # If the time period has is something like 1:00pm to 1:30pm or 1-2, interpret it as a range
12
12
  time_of_day_pattern = '\d+:?\d*[ap]?m?'
13
+ date_to_avoid_dsl_problems = '1/01/0001'
13
14
 
14
15
  Duration.new(
15
16
  if time_period.to_s.downcase.match(
16
17
  /(#{time_of_day_pattern})\s*(to|-)\s*(#{time_of_day_pattern})/
17
18
  )
18
- Chronic.parse($1).count_forward_to(Chronic.parse($3))
19
+ Chronic.parse("#{date_to_avoid_dsl_problems} #{$1}").count_forward_to(
20
+ Chronic.parse("#{date_to_avoid_dsl_problems} #{$3}")
21
+ )
19
22
  else
20
23
  ChronicDuration.parse(time_period)
21
24
  end
@@ -1,13 +1,14 @@
1
1
  require 'chronic'
2
+ require 'ruby-duration'
2
3
 
3
4
  module TimeDistribution
4
5
  module TimeRefinement
5
6
  refine Time do
6
7
  def count_forward_to(time)
7
- if self > time
8
- (Chronic.parse('11:59:59pm') - self) + (time - Chronic.parse('12:00:00am')) + 1
8
+ (time - self) + if self > time
9
+ 24 * 60 * 60
9
10
  else
10
- time - self
11
+ 0
11
12
  end
12
13
  end
13
14
  end
@@ -1,3 +1,3 @@
1
1
  module TimeDistribution
2
- VERSION = "2.1.2"
2
+ VERSION = "2.1.3"
3
3
  end
@@ -2,19 +2,27 @@ require_relative 'support/spec_helper'
2
2
 
3
3
  require 'time_distribution/smart_duration'
4
4
 
5
+ def hours_in_seconds(hours)
6
+ return hours * 60 * 60
7
+ end
8
+
9
+ def minutes_in_seconds(minutes)
10
+ return minutes * 60
11
+ end
12
+
5
13
  include TimeDistribution
6
14
  describe SmartDuration do
7
15
  describe '::parse' do
8
16
  describe 'can interpret a range of times' do
9
17
  it 'written with "to"' do
10
- SmartDuration.parse('10am to 11:30am').total.must_equal 1.5.hours
18
+ SmartDuration.parse('10am to 11:30am').total.must_equal hours_in_seconds(1.5)
11
19
  end
12
20
  it 'written with "-"' do
13
- SmartDuration.parse('10am-11:11am').total.must_equal 1.hours + 11.minutes
21
+ SmartDuration.parse('10am-11:11am').total.must_equal hours_in_seconds(1) + minutes_in_seconds(11)
14
22
  end
15
23
  end
16
24
  it 'can interpret an explicit range' do
17
- SmartDuration.parse('1 hour 30 minutes').total.must_equal 1.5.hours
25
+ SmartDuration.parse('1 hour 30 minutes').total.must_equal hours_in_seconds(1.5)
18
26
  end
19
27
  end
20
28
  end
@@ -5,19 +5,25 @@ require 'chronic'
5
5
  include TimeDistribution
6
6
  using TimeRefinement
7
7
 
8
+ def hours_in_seconds(hours)
9
+ return hours * 60 * 60
10
+ end
11
+
12
+ DATE_TO_AVOID_DSL_PROBLEMS = '1/01/0001'
13
+
8
14
  describe Time do
9
15
  describe '#count_forward_to' do
10
16
  it 'counts duration properly when both times are in AM' do
11
- Chronic.parse('10am').count_forward_to(Chronic.parse('11:30am')).must_equal 1.5.hours
17
+ Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 10am").count_forward_to(Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 11:30am")).must_equal hours_in_seconds(1.5)
12
18
  end
13
19
  it 'counts duration properly when both times are in PM' do
14
- Chronic.parse('10pm').count_forward_to(Chronic.parse('11:30pm')).must_equal 1.5.hours
20
+ Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 10pm").count_forward_to(Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 11:30pm")).must_equal hours_in_seconds(1.5)
15
21
  end
16
22
  it 'counts duration properly when it crosses from AM to PM' do
17
- Chronic.parse('11am').count_forward_to(Chronic.parse('12:30pm')).must_equal 1.5.hours
23
+ Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 11am").count_forward_to(Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 12:30pm")).must_equal hours_in_seconds(1.5)
18
24
  end
19
25
  it 'counts duration properly when it crosses from PM to AM' do
20
- Chronic.parse('11pm').count_forward_to(Chronic.parse('12:30am')).must_equal 1.5.hours
26
+ Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 11pm").count_forward_to(Chronic.parse("#{DATE_TO_AVOID_DSL_PROBLEMS} 12:30am")).must_equal hours_in_seconds(1.5)
21
27
  end
22
28
  end
23
29
  end
metadata CHANGED
@@ -1,125 +1,125 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_distribution
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.2
4
+ version: 2.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-16 00:00:00.000000000 Z
11
+ date: 2016-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.10'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.10'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: chronic_duration
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.10'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.10'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-duration
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ~>
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
47
  version: '3.2'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ~>
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.2'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rake
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ~>
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
61
  version: '10.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ~>
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '10.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: awesome_print
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ~>
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '1.6'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ~>
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '1.6'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: minitest
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ~>
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: '5.5'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ~>
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.5'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: pry-rescue
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ~>
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
103
  version: '1.4'
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ~>
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
110
  version: '1.4'
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ~>
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0.9'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ~>
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0.9'
125
125
  description: Gem for creating time distribution management systems
@@ -129,7 +129,7 @@ executables: []
129
129
  extensions: []
130
130
  extra_rdoc_files: []
131
131
  files:
132
- - .gitignore
132
+ - ".gitignore"
133
133
  - Gemfile
134
134
  - LICENSE.md
135
135
  - README.md
@@ -159,17 +159,17 @@ require_paths:
159
159
  - lib
160
160
  required_ruby_version: !ruby/object:Gem::Requirement
161
161
  requirements:
162
- - - '>='
162
+ - - ">="
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  required_rubygems_version: !ruby/object:Gem::Requirement
166
166
  requirements:
167
- - - '>='
167
+ - - ">="
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
171
  rubyforge_project:
172
- rubygems_version: 2.0.3
172
+ rubygems_version: 2.2.2
173
173
  signing_key:
174
174
  specification_version: 4
175
175
  summary: Gem for creating time distribution management systems