tod 3.1.0 → 3.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
  SHA256:
3
- metadata.gz: fd0d2d6c4e128195e0162e4516a89be2ceb08d42787e114e9a03a094e2d24f35
4
- data.tar.gz: 1a879241486d84fb99744a23688e48b3d9cd1da0d42019d221ab332c145aaea6
3
+ metadata.gz: 9abbaa919b6c5095de1d85a9e4db5da1160d4d80038515366502c2144d007b75
4
+ data.tar.gz: 87106d404f688c2ba9997b18874172440f34f7bcacfe35f41c693309693c7654
5
5
  SHA512:
6
- metadata.gz: df47cc6c284da3c00d8faa6b6fa064cd2d0e69fd696e2ef3be7e4a8a88823d82713de5e70407aea76d71f12dded69e8fb3f1fad45dfd2ccda2f223c48f76d7b1
7
- data.tar.gz: a9e9cd0823b2870e8ec4d2dd687b3ec963132a5c795a50d4bb16fbcc0f7117212bc188885f951acdf61806c2e6bb1fc6caf3937d91747857e9e184682b4157ed
6
+ metadata.gz: a890e3dc2b7aee24401388d8d85214c01e0f730c0547a61f7c46d9a097dce842fccf2a43836d46e52af3eba87f1df2c9aa2bd13fe6f10f5e780b085e43b9741d
7
+ data.tar.gz: f6bdb357ba0c50aaba4b30f84038378a5418112776452832b2bfa8a53313975c88ca7caea2cdc8f4701acc7206b55dab19dfd08a3eb32214e3cf53f0fa771760
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 3.1.1 (June 11, 2023)
2
+
3
+ * Allow use in Rails forms with time_select (Bill Pearce)
4
+ * Prevent error when comparing a range to nil (Chris Northwood)
5
+
1
6
  # 3.1.0 (December 20, 2021)
2
7
 
3
8
  * Allow / ignore parsing milliseconds (Eli Fatsi)
data/Gemfile.lock CHANGED
@@ -6,35 +6,35 @@ PATH
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (6.1.3)
10
- activesupport (= 6.1.3)
11
- activerecord (6.1.3)
12
- activemodel (= 6.1.3)
13
- activesupport (= 6.1.3)
14
- activesupport (6.1.3)
9
+ activemodel (7.0.5)
10
+ activesupport (= 7.0.5)
11
+ activerecord (7.0.5)
12
+ activemodel (= 7.0.5)
13
+ activesupport (= 7.0.5)
14
+ activesupport (7.0.5)
15
15
  concurrent-ruby (~> 1.0, >= 1.0.2)
16
16
  i18n (>= 1.6, < 2)
17
17
  minitest (>= 5.1)
18
18
  tzinfo (~> 2.0)
19
- zeitwerk (~> 2.3)
20
19
  byebug (11.1.3)
21
20
  coderay (1.1.3)
22
- concurrent-ruby (1.1.8)
23
- i18n (1.8.9)
21
+ concurrent-ruby (1.2.2)
22
+ i18n (1.14.1)
24
23
  concurrent-ruby (~> 1.0)
25
24
  method_source (1.0.0)
26
- minitest (5.14.4)
27
- pry (0.13.1)
25
+ mini_portile2 (2.8.2)
26
+ minitest (5.18.0)
27
+ pry (0.14.2)
28
28
  coderay (~> 1.1)
29
29
  method_source (~> 1.0)
30
- pry-byebug (3.9.0)
30
+ pry-byebug (3.10.1)
31
31
  byebug (~> 11.0)
32
- pry (~> 0.13.0)
33
- rake (13.0.3)
34
- sqlite3 (1.4.2)
35
- tzinfo (2.0.4)
32
+ pry (>= 0.13, < 0.15)
33
+ rake (13.0.6)
34
+ sqlite3 (1.6.3)
35
+ mini_portile2 (~> 2.8.0)
36
+ tzinfo (2.0.6)
36
37
  concurrent-ruby (~> 1.0)
37
- zeitwerk (2.4.2)
38
38
 
39
39
  PLATFORMS
40
40
  ruby
data/README.markdown CHANGED
@@ -201,8 +201,8 @@ Overlaps?
201
201
 
202
202
  Contains?
203
203
  --------------------
204
- workday = Shift.new(TimeOfDay.new(9), TimeOfDay.new(17))
205
- lunch = Shift.new(TimeOfDay.new(10), TimeOfDay.new(14))
204
+ workday = Tod::Shift.new(Tod::TimeOfDay.new(9), Tod::TimeOfDay.new(17))
205
+ lunch = Tod::Shift.new(Tod::TimeOfDay.new(10), Tod::TimeOfDay.new(14))
206
206
  workday.contains?(lunch) # => true
207
207
  lunch.contains?(workday) # => false
208
208
 
@@ -244,6 +244,18 @@ order = Order.create(time: Tod::TimeOfDay.new(9,30))
244
244
  order.time # => 09:30:00
245
245
  ```
246
246
 
247
+ In Rails, this can be used with `time_select` in forms like so:
248
+
249
+ ```ruby
250
+ f.time_select :time, ignore_date: true
251
+ ```
252
+
253
+ Or with **simple_form**:
254
+
255
+ ```ruby
256
+ f.input :time, as: :time, ignore_date: true
257
+ ```
258
+
247
259
  MongoDB Support
248
260
  ===============
249
261
 
data/lib/tod/shift.rb CHANGED
@@ -88,11 +88,11 @@ module Tod
88
88
  end
89
89
 
90
90
  def ==(other)
91
- @range == other.range
91
+ !other.nil? && @range == other.range
92
92
  end
93
93
 
94
94
  def eql?(other)
95
- @range.eql?(other.range)
95
+ !other.nil? && @range.eql?(other.range)
96
96
  end
97
97
 
98
98
  def hash
@@ -4,7 +4,7 @@ module Tod
4
4
  if value.is_a? Hash
5
5
  # rails multiparam attribute
6
6
  # get hour, minute and second and construct new TimeOfDay object
7
- ::Tod::TimeOfDay.new(value[4], value[5], value[6])
7
+ ::Tod::TimeOfDay.new(value[4], value[5], value[6] || 0)
8
8
  else
9
9
  # return nil, if input is not parsable
10
10
  Tod::TimeOfDay(value){}
data/lib/tod/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tod
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
data/test/test_helper.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__),'..','lib')
2
2
 
3
3
  require 'bundler/setup'
4
+ require 'active_support'
4
5
  require 'active_support/time'
5
6
  require 'tod'
6
7
  require 'tod/core_extensions'
@@ -295,6 +295,13 @@ describe "Shift" do
295
295
  shift2 = Tod::Shift.new tod1, tod2, true
296
296
  assert !(shift1 == shift2)
297
297
  end
298
+
299
+ it "is false when one side is nil" do
300
+ tod1 = Tod::TimeOfDay.new 8,30
301
+ tod2 = Tod::TimeOfDay.new 13,00,30
302
+ shift = Tod::Shift.new tod1, tod2
303
+ assert !(shift == nil)
304
+ end
298
305
  end
299
306
 
300
307
  describe "#eql?" do
@@ -329,6 +336,13 @@ describe "Shift" do
329
336
  shift2 = Tod::Shift.new tod1, tod2, true
330
337
  assert !shift1.eql?(shift2)
331
338
  end
339
+
340
+ it "is false when one side is nil" do
341
+ tod1 = Tod::TimeOfDay.new 8,30
342
+ tod2 = Tod::TimeOfDay.new 13,00,30
343
+ shift = Tod::Shift.new tod1, tod2
344
+ assert !shift.eql?(nil )
345
+ end
332
346
  end
333
347
 
334
348
  describe "#hash" do
@@ -24,6 +24,11 @@ describe "TimeOfDay with ActiveRecord Attribute" do
24
24
  assert_equal Tod::TimeOfDay.new(8,6,5), order.time
25
25
  end
26
26
 
27
+ it "works with multiparam time arguments without seconds" do
28
+ order = Order.create!({"time(4i)" => "8", "time(5i)" => "6"})
29
+ assert_equal Tod::TimeOfDay.new(8,6,0), order.time
30
+ end
31
+
27
32
  it "should not raise Exception on access of unparsable values" do
28
33
  order = Order.new(time: 'unparsable')
29
34
  order.time
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.1.0
4
+ version: 3.1.1
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-12-20 00:00:00.000000000 Z
11
+ date: 2023-06-11 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.2.15
153
+ rubygems_version: 3.4.1
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Supplies TimeOfDay and Shift class