tod 3.1.0 → 3.1.2

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: 4c1822f3d5a2b798f5b61037371706e54b7588491c9470d8072ad93212239662
4
+ data.tar.gz: c9d25f0ec776493e5afe4cd2194b6d6d2226f43663842891c65efaef6224fc10
5
5
  SHA512:
6
- metadata.gz: df47cc6c284da3c00d8faa6b6fa064cd2d0e69fd696e2ef3be7e4a8a88823d82713de5e70407aea76d71f12dded69e8fb3f1fad45dfd2ccda2f223c48f76d7b1
7
- data.tar.gz: a9e9cd0823b2870e8ec4d2dd687b3ec963132a5c795a50d4bb16fbcc0f7117212bc188885f951acdf61806c2e6bb1fc6caf3937d91747857e9e184682b4157ed
6
+ metadata.gz: be10cd8868990590e93d07e97a8eb4861facbeb708fbf61a1b0b01a6aaaec8f84189a38d276d04133aeadd6aec199342dcb1be893b6a1ed19a68135c0fc9aa1d
7
+ data.tar.gz: 8c31766d217e42c06ada0cc193af5231c33d73a45b81ed62abe5a3e7c6ea11fb0e9c159d60322a242b5c9706936710390e880e0d72503911a698b10d455c38ad
data/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ # 3.1.2 (January 12, 2024)
2
+
3
+ * Add Tod::TimeOfDay#to_fs for Rails 7 compatibility (Igor S. Morozov)
4
+ * Shift internally calls second_of_day instead of to_i on objects that should quack like a Tod::TimeOfDay. This makes silent errors caused by passing a bad argument less likely.
5
+
6
+ # 3.1.1 (June 11, 2023)
7
+
8
+ * Allow use in Rails forms with time_select (Bill Pearce)
9
+ * Prevent error when comparing a range to nil (Chris Northwood)
10
+
1
11
  # 3.1.0 (December 20, 2021)
2
12
 
3
13
  * Allow / ignore parsing milliseconds (Eli Fatsi)
data/Gemfile.lock CHANGED
@@ -1,40 +1,54 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tod (3.1.0)
4
+ tod (3.1.2)
5
5
 
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.1.2)
10
+ activesupport (= 7.1.2)
11
+ activerecord (7.1.2)
12
+ activemodel (= 7.1.2)
13
+ activesupport (= 7.1.2)
14
+ timeout (>= 0.4.0)
15
+ activesupport (7.1.2)
16
+ base64
17
+ bigdecimal
15
18
  concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ connection_pool (>= 2.2.5)
20
+ drb
16
21
  i18n (>= 1.6, < 2)
17
22
  minitest (>= 5.1)
23
+ mutex_m
18
24
  tzinfo (~> 2.0)
19
- zeitwerk (~> 2.3)
25
+ base64 (0.2.0)
26
+ bigdecimal (3.1.5)
20
27
  byebug (11.1.3)
21
28
  coderay (1.1.3)
22
- concurrent-ruby (1.1.8)
23
- i18n (1.8.9)
29
+ concurrent-ruby (1.2.2)
30
+ connection_pool (2.4.1)
31
+ drb (2.2.0)
32
+ ruby2_keywords
33
+ i18n (1.14.1)
24
34
  concurrent-ruby (~> 1.0)
25
35
  method_source (1.0.0)
26
- minitest (5.14.4)
27
- pry (0.13.1)
36
+ mini_portile2 (2.8.5)
37
+ minitest (5.21.1)
38
+ mutex_m (0.2.0)
39
+ pry (0.14.2)
28
40
  coderay (~> 1.1)
29
41
  method_source (~> 1.0)
30
- pry-byebug (3.9.0)
42
+ pry-byebug (3.10.1)
31
43
  byebug (~> 11.0)
32
- pry (~> 0.13.0)
33
- rake (13.0.3)
34
- sqlite3 (1.4.2)
35
- tzinfo (2.0.4)
44
+ pry (>= 0.13, < 0.15)
45
+ rake (13.1.0)
46
+ ruby2_keywords (0.0.5)
47
+ sqlite3 (1.7.0)
48
+ mini_portile2 (~> 2.8.0)
49
+ timeout (0.4.1)
50
+ tzinfo (2.0.6)
36
51
  concurrent-ruby (~> 1.0)
37
- zeitwerk (2.4.2)
38
52
 
39
53
  PLATFORMS
40
54
  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
@@ -16,10 +16,10 @@ module Tod
16
16
  @ending = ending
17
17
  @exclude_end = exclude_end
18
18
 
19
- normalized_ending = ending.to_i
20
- normalized_ending += TimeOfDay::NUM_SECONDS_IN_DAY if normalized_ending < beginning.to_i
19
+ normalized_ending = ending.second_of_day
20
+ normalized_ending += TimeOfDay::NUM_SECONDS_IN_DAY if normalized_ending < beginning.second_of_day
21
21
 
22
- @range = Range.new(beginning.to_i, normalized_ending, @exclude_end)
22
+ @range = Range.new(beginning.second_of_day, normalized_ending, @exclude_end)
23
23
 
24
24
  freeze # Shift instances are value objects
25
25
  end
@@ -30,7 +30,7 @@ module Tod
30
30
 
31
31
  # Returns true if the time of day is inside the shift, false otherwise.
32
32
  def include?(tod)
33
- second = tod.to_i
33
+ second = tod.second_of_day
34
34
  second += TimeOfDay::NUM_SECONDS_IN_DAY if second < @range.first
35
35
  @range.cover?(second)
36
36
  end
@@ -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
@@ -107,6 +107,7 @@ module Tod
107
107
  end
108
108
  end
109
109
  alias_method :to_s, :to_formatted_s
110
+ alias_method :to_fs, :to_formatted_s
110
111
 
111
112
  def value_for_database
112
113
  to_s
@@ -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.2"
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
@@ -190,6 +190,13 @@ describe "TimeOfDay" do
190
190
  end
191
191
  end
192
192
 
193
+ describe "to_fs" do
194
+ it "is aliased to to_formatted_s" do
195
+ t = Tod::TimeOfDay.new(8,15,30)
196
+ assert_equal t.to_formatted_s, t.to_s
197
+ end
198
+ end
199
+
193
200
  describe "inspect" do
194
201
  it "is friendly representation" do
195
202
  t = Tod::TimeOfDay.new(12,15,05)
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.2
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: 2024-01-12 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.5.3
154
154
  signing_key:
155
155
  specification_version: 4
156
156
  summary: Supplies TimeOfDay and Shift class