tod 3.0.0 → 3.1.0

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
  SHA256:
3
- metadata.gz: 8986b140f4dcc736d253b188cd5f9a46a72110f38887cd6e8ff93ecee823c438
4
- data.tar.gz: 95d31c83abc1264946bf2ce6aa6ba6fac45dcaeca1362b76a22d54eab27f402f
3
+ metadata.gz: fd0d2d6c4e128195e0162e4516a89be2ceb08d42787e114e9a03a094e2d24f35
4
+ data.tar.gz: 1a879241486d84fb99744a23688e48b3d9cd1da0d42019d221ab332c145aaea6
5
5
  SHA512:
6
- metadata.gz: 2d1c3b50deb1df502928666b38e113fb7d58b4a25c140119bac8155ad3ff3add0689cffba810b7bdd6ab1461493838873a839ac259895630210e47679ae9ef89
7
- data.tar.gz: 98a76ddcb2b8c866f602efe1def27c236b88ffcc6bbb12812580794113dc964d5b6df1bd95b0f055a48e9e95ca4b69ccf3dea93b20f866ca72be7932596e1aaf
6
+ metadata.gz: df47cc6c284da3c00d8faa6b6fa064cd2d0e69fd696e2ef3be7e4a8a88823d82713de5e70407aea76d71f12dded69e8fb3f1fad45dfd2ccda2f223c48f76d7b1
7
+ data.tar.gz: a9e9cd0823b2870e8ec4d2dd687b3ec963132a5c795a50d4bb16fbcc0f7117212bc188885f951acdf61806c2e6bb1fc6caf3937d91747857e9e184682b4157ed
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 3.1.0 (December 20, 2021)
2
+
3
+ * Allow / ignore parsing milliseconds (Eli Fatsi)
4
+ * Improve TimeOfDate#inspect and Shift#inspect (zverok)
5
+ * Fix Shift#contains? with exclusive ending (nazamoresco)
6
+
1
7
  # 3.0.0 (March 6, 2021)
2
8
 
3
9
  * Support and require Rails 6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tod (3.0.0)
4
+ tod (3.1.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -49,4 +49,4 @@ DEPENDENCIES
49
49
  tzinfo
50
50
 
51
51
  BUNDLED WITH
52
- 2.0.2
52
+ 2.2.15
data/README.markdown CHANGED
@@ -182,7 +182,7 @@ Include?
182
182
  Tod::Shift.new(Tod::TimeOfDay.new(5), Tod::TimeOfDay.new(9), true).include?(Tod::TimeOfDay.new(9)) # => false
183
183
 
184
184
 
185
- Overlap?
185
+ Overlaps?
186
186
  --------------------
187
187
 
188
188
  breakfast = Tod::Shift.new(Tod::TimeOfDay.new(8), Tod::TimeOfDay.new(11))
@@ -234,6 +234,9 @@ in a column of the time type.
234
234
  Example:
235
235
 
236
236
  ```ruby
237
+ ActiveModel::Type.register(:time_only, Tod::TimeOfDayType)
238
+ ActiveRecord::Type.register(:time_only, Tod::TimeOfDayType)
239
+
237
240
  class Order < ActiveRecord::Base
238
241
  attribute :time, :time_only
239
242
  end
data/lib/tod/shift.rb CHANGED
@@ -24,6 +24,10 @@ module Tod
24
24
  freeze # Shift instances are value objects
25
25
  end
26
26
 
27
+ def inspect
28
+ "#<#{self.class} #{beginning}#{exclude_end? ? '...' : '..'}#{ending}>"
29
+ end
30
+
27
31
  # Returns true if the time of day is inside the shift, false otherwise.
28
32
  def include?(tod)
29
33
  second = tod.to_i
@@ -70,7 +74,7 @@ module Tod
70
74
  end
71
75
 
72
76
  def contains?(shift)
73
- self.include?(shift.beginning) && self.include?(shift.ending)
77
+ self.include?(shift.beginning) && self.include?(shift.inclusive_ending)
74
78
  end
75
79
 
76
80
  # Return shift duration in seconds.
@@ -99,5 +103,12 @@ module Tod
99
103
  def slide(seconds)
100
104
  self.class.new(beginning + seconds, ending + seconds, exclude_end?)
101
105
  end
106
+
107
+ protected
108
+
109
+ # If exclusive ending returns equivalent ending but inclusive
110
+ def inclusive_ending
111
+ self.exclude_end? ? ending - 1 : ending
112
+ end
102
113
  end
103
114
  end
@@ -14,6 +14,7 @@ module Tod
14
14
  ([0-5]\d)?
15
15
  :?
16
16
  ([0-5]\d)?
17
+ (?:\.\d{3})?
17
18
  \z
18
19
  /x
19
20
 
@@ -24,6 +25,7 @@ module Tod
24
25
  ([0-5]\d)?
25
26
  :?
26
27
  ([0-5]\d)?
28
+ (?:\.\d{3})?
27
29
  \s*
28
30
  ([ap])
29
31
  \.?
@@ -110,6 +112,10 @@ module Tod
110
112
  to_s
111
113
  end
112
114
 
115
+ def inspect
116
+ "#<#{self.class} #{self}>"
117
+ end
118
+
113
119
  # Return a new TimeOfDay num_seconds greater than self. It will wrap around
114
120
  # at midnight.
115
121
  def +(num_seconds)
data/lib/tod/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tod
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.0"
3
3
  end
@@ -88,4 +88,18 @@ describe "TimeOfDay()" do
88
88
 
89
89
  assert_equal(tod, Tod::TimeOfDay.new(24, 00, 00))
90
90
  end
91
+
92
+ it "parses 24:00:00.000" do
93
+ t = "24:00:00.000"
94
+ tod = Tod::TimeOfDay(t)
95
+
96
+ assert_equal(tod, Tod::TimeOfDay.new(24, 00, 00))
97
+ end
98
+
99
+ it "parses 04:00:00.000 pm" do
100
+ t = "04:00:00.000 pm"
101
+ tod = Tod::TimeOfDay(t)
102
+
103
+ assert_equal(tod, Tod::TimeOfDay.new(16, 00, 00))
104
+ end
91
105
  end
@@ -11,6 +11,16 @@ describe "Shift" do
11
11
  end
12
12
  end
13
13
 
14
+ describe "inspect" do
15
+ it "provides friendly description" do
16
+ shift = Tod::Shift.new Tod::TimeOfDay.new(8), Tod::TimeOfDay.new(10), false
17
+ assert_equal "#<Tod::Shift 08:00:00..10:00:00>", shift.inspect
18
+
19
+ shift = Tod::Shift.new Tod::TimeOfDay.new(8), Tod::TimeOfDay.new(10), true
20
+ assert_equal "#<Tod::Shift 08:00:00...10:00:00>", shift.inspect
21
+ end
22
+ end
23
+
14
24
  describe "#duration" do
15
25
  it "returns correct duration when first time is lower than the second one" do
16
26
  duration_expected = 4 * 60 * 60 + 30 * 60 + 30 # 4 hours, 30 min and 30 sec later
@@ -162,6 +172,12 @@ describe "Shift" do
162
172
  shift2 = Tod::Shift.new(Tod::TimeOfDay.new(18), Tod::TimeOfDay.new(19))
163
173
  refute shift1.contains?(shift2)
164
174
  end
175
+
176
+ it "is true when beginning is included and exclusive endings match" do
177
+ inside = Tod::Shift.new(Tod::TimeOfDay.new(13), Tod::TimeOfDay.new(17), true)
178
+ outside = Tod::Shift.new(Tod::TimeOfDay.new(10), Tod::TimeOfDay.new(17), true)
179
+ assert outside.contains?(inside)
180
+ end
165
181
  end
166
182
 
167
183
  describe "#include?" do
@@ -190,6 +190,13 @@ describe "TimeOfDay" do
190
190
  end
191
191
  end
192
192
 
193
+ describe "inspect" do
194
+ it "is friendly representation" do
195
+ t = Tod::TimeOfDay.new(12,15,05)
196
+ assert_equal "#<Tod::TimeOfDay 12:15:05>", t.inspect
197
+ end
198
+ end
199
+
193
200
  describe "to_i" do
194
201
  it "formats to integer" do
195
202
  assert_equal 29730, Tod::TimeOfDay.new(8,15,30).to_i
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tod
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Christensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-06 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -150,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  requirements: []
153
- rubygems_version: 3.0.6
153
+ rubygems_version: 3.2.15
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Supplies TimeOfDay and Shift class