tod 2.1.1 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5546b071b1fedc06fb6af4b11dff091e05ffc98d
4
- data.tar.gz: bda08b0019d1af90e0a4cb31f5d86833b096737d
2
+ SHA256:
3
+ metadata.gz: 5b81b1887eee62d6f7a98bf6281f16da3cffd47206925beca789a94b91c3e7c2
4
+ data.tar.gz: 662b50760caef5be2bf7e41b1b59ced86ece56b8d46b10aa6fe7cd24e33cb869
5
5
  SHA512:
6
- metadata.gz: 1c6993e9088d273ca572061ee93d80c5549e418dc7d720833dbba5d2ea68d199707e65d459657c3d6af961e4a1bb1c0cdce3b10ee31699c9b769e30e93bed335
7
- data.tar.gz: 73c8d5a8b90b06de86d327abf54eac4ce6ee877609595977cbedb3da7322d06eeb1159fcc478eaa34ae7a7541e7fd7052d4407d687cb94a35b99e735f271133d
6
+ metadata.gz: 8b97d86a5945a3f274b3674b11bd4f09add9ca409e4512ddba81c107acc8e5bc339896fa7b94a5da7d9e61bf8d579e7c866b0473dfc86ef3e6cd2b63c0174964
7
+ data.tar.gz: f539df0792da43d8a45244e9ba978732d59c02ffc36406047725c7209a44e1958926647b05bdb9c7d51a5d1417d6f2f396246e9aeba63bb17b017b87756a9195
@@ -7,3 +7,7 @@ gemfile:
7
7
  - gemfiles/4.1.gemfile
8
8
  - gemfiles/4.2.gemfile
9
9
  - gemfiles/5.0.gemfile
10
+ matrix:
11
+ include:
12
+ - rvm: 2.5.1
13
+ gemfile: gemfiles/5.2.gemfile
@@ -1,3 +1,8 @@
1
+ # 2.2.0 (October 10, 2018)
2
+
3
+ * Add string formatting compatible with Rails (Tate Johnson)
4
+ * Add ability to use ActiveRecord's attribute API (Brent Wheeldon)
5
+
1
6
  # 2.1.1 (April 14, 2017)
2
7
 
3
8
  * Fix serialize Ruby Time to Tod::TimeOfDay (Ryan Dick)
@@ -1,37 +1,40 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tod (2.1.1)
4
+ tod (2.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (5.0.2)
10
- activesupport (= 5.0.2)
11
- activerecord (5.0.2)
12
- activemodel (= 5.0.2)
13
- activesupport (= 5.0.2)
14
- arel (~> 7.0)
15
- activesupport (5.0.2)
9
+ activemodel (5.2.0)
10
+ activesupport (= 5.2.0)
11
+ activerecord (5.2.0)
12
+ activemodel (= 5.2.0)
13
+ activesupport (= 5.2.0)
14
+ arel (>= 9.0)
15
+ activesupport (5.2.0)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
- i18n (~> 0.7)
17
+ i18n (>= 0.7, < 2)
18
18
  minitest (~> 5.1)
19
19
  tzinfo (~> 1.1)
20
- arel (7.1.4)
21
- coderay (1.1.1)
20
+ arel (9.0.0)
21
+ byebug (10.0.2)
22
+ coderay (1.1.2)
22
23
  concurrent-ruby (1.0.5)
23
- i18n (0.8.1)
24
- method_source (0.8.2)
25
- minitest (5.10.1)
26
- pry (0.10.4)
24
+ i18n (1.0.1)
25
+ concurrent-ruby (~> 1.0)
26
+ method_source (0.9.0)
27
+ minitest (5.11.3)
28
+ pry (0.11.3)
27
29
  coderay (~> 1.1.0)
28
- method_source (~> 0.8.1)
29
- slop (~> 3.4)
30
- rake (12.0.0)
31
- slop (3.6.0)
30
+ method_source (~> 0.9.0)
31
+ pry-byebug (3.6.0)
32
+ byebug (~> 10.0)
33
+ pry (~> 0.10)
34
+ rake (12.3.1)
32
35
  sqlite3 (1.3.13)
33
36
  thread_safe (0.3.6)
34
- tzinfo (1.2.2)
37
+ tzinfo (1.2.5)
35
38
  thread_safe (~> 0.1)
36
39
 
37
40
  PLATFORMS
@@ -41,11 +44,11 @@ DEPENDENCIES
41
44
  activerecord (>= 3.0.0)
42
45
  arel
43
46
  minitest
44
- pry
47
+ pry-byebug
45
48
  rake
46
49
  sqlite3
47
50
  tod!
48
51
  tzinfo
49
52
 
50
53
  BUNDLED WITH
51
- 1.14.6
54
+ 1.16.3
@@ -54,6 +54,12 @@ parsable.
54
54
  Tod::TimeOfDay.try_parse "3:30pm" # => 15:30:00
55
55
  Tod::TimeOfDay.try_parse "foo" # => nil
56
56
 
57
+ You can also give a block to parse to handle special input with your own logic.
58
+
59
+ Tod::TimeOfDay.parse "25" do |time_string|
60
+ Tod::TimeOfDay.new(time_string.to_i % 24)
61
+ end # => 01:00:00
62
+
57
63
  Values can be tested with Tod::TimeOfDay.parsable? to see if they can be parsed.
58
64
 
59
65
  Tod::TimeOfDay.parsable? "3:30pm" # => true
@@ -62,7 +68,7 @@ Values can be tested with Tod::TimeOfDay.parsable? to see if they can be parsed.
62
68
  Adding or subtracting time
63
69
  -----------------------------
64
70
 
65
- Seconds can be added to or subtracted Tod::TimeOfDay objects. Time correctly wraps
71
+ Seconds can be added to or subtracted from Tod::TimeOfDay objects. Time correctly wraps
66
72
  around midnight.
67
73
 
68
74
  Tod::TimeOfDay.new(8) + 3600 # => 09:00:00
@@ -89,6 +95,19 @@ Format strings are passed to Time#strftime.
89
95
  Tod::TimeOfDay.new(17,15).strftime("%I:%M %p") # => "05:15 PM"
90
96
  Tod::TimeOfDay.new(22,5,15).strftime("%I:%M:%S %p") # => "10:05:15 PM"
91
97
 
98
+ Or a Rails style `to_formatted_s` is aliased to `to_s`.
99
+
100
+ Tod::TimeOfDay.new(8,30).to_s(:short) # => "8:30 am"
101
+
102
+ Or [i18n](https://github.com/svenfuchs/i18n) in a Rails ERB view.
103
+
104
+ <%= l Tod::TimeOfDay.new(8, 30), format: :short %>
105
+
106
+ Add new formatters to `Tod::TimeOfDay::FORMATS`.
107
+
108
+ Tod::TimeOfDay::FORMATS[:seconds_only] = "%S"
109
+ Tod::TimeOfDay.new(8,30,57).to_s(:seconds_only) # => "57"
110
+
92
111
  Rounding
93
112
  ----------
94
113
 
@@ -101,7 +120,8 @@ Round to the given nearest number of seconds.
101
120
  Convenience methods for dates and times
102
121
  ---------------------------------------
103
122
 
104
- Pass a date to Tod::TimeOfDay#on and it will return a time with that date and time.
123
+ Pass a date to Tod::TimeOfDay#on and it will return a time with that date and time,
124
+ in the time zone of the ruby runtime (`Time.now.zone`).
105
125
 
106
126
  tod = Tod::TimeOfDay.new 8, 30 # => 08:30:00
107
127
  tod.on Date.today # => 2010-12-29 08:30:00 -0600
@@ -193,13 +213,26 @@ Contains?
193
213
  Rails Time Zone Support
194
214
  =======================
195
215
 
196
- If Rails time zone support is loaded, Date#on and Tod::TimeOfDay#at will automatically use Time.zone.
216
+ If Rails time zone support is loaded, Date#on and Tod::TimeOfDay#at (when given a Date) will automatically use Time.zone.
197
217
 
198
- Active Record Serializable Attribute Support
218
+ When Tod::TimeOfDay#on is given a `Time` or `Time`-like object like `ActiveSupport::TimeWithZone`,
219
+ Tod will ignore the specified timezone and return the time on that date in UTC. In order to
220
+ produce an object with the correct time and time zone, pass in an
221
+ `ActiveSupport::TimeZone` object. Date#at has analogous behavior.
222
+
223
+ time = Time.now.in_time_zone("US/Eastern") # => Mon, 24 Sep 2018 05:07:23 EDT -04:00
224
+ tod.on time # => Mon, 24 Sep 2018 08:30:00 UTC +00:00
225
+ tod.on time, time.time_zone # => Mon, 24 Sep 2018 08:30:00 EDT -04:00
226
+ tod.on time, Time.find_zone!("US/Mountain") # => Mon, 24 Sep 2018 08:30:00 MDT -06:00
227
+ Date.tomorrow.at tod, Time.find_zone!("US/Mountain") # => Tue, 25 Sep 2018 08:30:00 MDT -06:00
228
+
229
+ ActiveRecord Serializable Attribute Support
199
230
  =======================
200
231
  Tod::TimeOfDay implements a custom serialization contract for ActiveRecord serialize which allows to store Tod::TimeOfDay directly
201
232
  in a column of the time type.
233
+
202
234
  Example:
235
+
203
236
  ```ruby
204
237
  class Order < ActiveRecord::Base
205
238
  serialize :time, Tod::TimeOfDay
@@ -208,6 +241,17 @@ order = Order.create(time: Tod::TimeOfDay.new(9,30))
208
241
  order.time # => 09:30:00
209
242
  ```
210
243
 
244
+ By default Rails 5.1 treats database `time` values as if time zones are
245
+ meaningful. Tod::TimeOfDay cannot correctly save and restore values when Rails
246
+ automatically shifts values based on time zone and the normal `serialize`
247
+ interface is not able to override this behavior. To correctly serialize
248
+ Tod::TimeOfDay values with Rails 5.1 time zone handling must be disabled for
249
+ database `time` types. This can be done with the following config:
250
+
251
+ ```
252
+ config.active_record.time_zone_aware_types = [:datetime]
253
+ ```
254
+
211
255
  MongoDB Support
212
256
  ===============
213
257
 
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'activerecord', '~> 5.2.1'
4
+
5
+ gemspec :path=>"../"
data/lib/tod.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  require 'tod/time_of_day'
2
2
  require 'tod/shift'
3
3
  require 'tod/conversions'
4
+
5
+ require 'tod/railtie' if defined?(Rails)
@@ -1,5 +1,5 @@
1
1
  module Tod
2
- def TimeOfDay(obj_or_string)
2
+ def TimeOfDay(obj_or_string, &block)
3
3
  if obj_or_string.is_a?(TimeOfDay)
4
4
  obj_or_string
5
5
  elsif obj_or_string.respond_to?(:to_time_of_day)
@@ -9,7 +9,7 @@ module Tod
9
9
  elsif obj_or_string.is_a?(Date)
10
10
  TimeOfDay.new 0
11
11
  else
12
- TimeOfDay.parse(obj_or_string)
12
+ TimeOfDay.parse(obj_or_string, &block)
13
13
  end
14
14
  end
15
15
 
@@ -0,0 +1,9 @@
1
+ require "tod/time_of_day_type"
2
+
3
+ module Tod
4
+ class Railtie < Rails::Railtie
5
+ initializer "tod.register_active_record_type" do
6
+ ActiveRecord::Type.register(:time_only, Tod::TimeOfDayType)
7
+ end
8
+ end
9
+ end
@@ -9,7 +9,7 @@ module Tod
9
9
 
10
10
  PARSE_24H_REGEX = /
11
11
  \A
12
- ([01]?\d|2[0-3])
12
+ ([01]?\d|2[0-4])
13
13
  :?
14
14
  ([0-5]\d)?
15
15
  :?
@@ -42,12 +42,21 @@ module Tod
42
42
  NUM_SECONDS_IN_HOUR = 3600
43
43
  NUM_SECONDS_IN_MINUTE = 60
44
44
 
45
+ FORMATS = {
46
+ short: "%-l:%M %P",
47
+ medium: "%-l:%M:%S %P",
48
+ time: "%H:%M"
49
+ }
50
+
45
51
  def initialize(h, m=0, s=0)
46
52
  @hour = Integer(h)
47
53
  @minute = Integer(m)
48
54
  @second = Integer(s)
49
55
 
50
- raise ArgumentError, "hour must be between 0 and 23" unless (0..23).include?(@hour)
56
+ raise ArgumentError, "hour must be between 0 and 24" unless (0..24).include?(@hour)
57
+ if @hour == 24 && (@minute != 0 || @second != 0)
58
+ raise ArgumentError, "hour can only be 24 when minute and second are 0"
59
+ end
51
60
  raise ArgumentError, "minute must be between 0 and 59" unless (0..59).include?(@minute)
52
61
  raise ArgumentError, "second must be between 0 and 59" unless (0..59).include?(@second)
53
62
 
@@ -78,12 +87,24 @@ module Tod
78
87
 
79
88
  # Formats identically to Time#strftime
80
89
  def strftime(format_string)
90
+ # Special case 2400 because strftime will load TimeOfDay into Time which
91
+ # will convert 24 to 0
92
+ format_string.gsub!(/%H|%k/, '24') if @hour == 24
81
93
  Time.local(2000,1,1, @hour, @minute, @second).strftime(format_string)
82
94
  end
83
95
 
84
- def to_s
85
- strftime "%H:%M:%S"
96
+ def to_formatted_s(format = :default)
97
+ if formatter = FORMATS[format]
98
+ if formatter.respond_to?(:call)
99
+ formatter.call(self).to_s
100
+ else
101
+ strftime(formatter)
102
+ end
103
+ else
104
+ strftime "%H:%M:%S"
105
+ end
86
106
  end
107
+ alias_method :to_s, :to_formatted_s
87
108
 
88
109
  # Return a new TimeOfDay num_seconds greater than self. It will wrap around
89
110
  # at midnight.
@@ -112,6 +133,7 @@ module Tod
112
133
  # TimeOfDay.from_second_of_day(3600) == TimeOfDay.new(1) # => true
113
134
  def self.from_second_of_day(second_of_day)
114
135
  second_of_day = Integer(second_of_day)
136
+ return new 24 if second_of_day == NUM_SECONDS_IN_DAY
115
137
  remaining_seconds = second_of_day % NUM_SECONDS_IN_DAY
116
138
  hour = remaining_seconds / NUM_SECONDS_IN_HOUR
117
139
  remaining_seconds -= hour * NUM_SECONDS_IN_HOUR
@@ -138,8 +160,10 @@ module Tod
138
160
  # TimeOfDay.parse "3:25:58" # => 03:25:58
139
161
  # TimeOfDay.parse "515p" # => 17:15:00
140
162
  # TimeOfDay.parse "151253" # => 15:12:53
163
+ # You can give a block, that is called with the input if the string is not parsable.
164
+ # If no block is given an ArgumentError is raised if try_parse returns nil.
141
165
  def self.parse(tod_string)
142
- try_parse(tod_string) || (raise ArgumentError, "Invalid time of day string")
166
+ try_parse(tod_string) || (block_given? ? yield(tod_string) : raise(ArgumentError, "Invalid time of day string"))
143
167
  end
144
168
 
145
169
  # Same as parse(), but return nil if not parsable (instead of raising an error)
@@ -178,19 +202,23 @@ module Tod
178
202
  end
179
203
 
180
204
  def self.dump(time_of_day)
181
- if time_of_day.is_a? Hash
182
- # rails multiparam attribute
183
- hour,minute,second = time_of_day[4], time_of_day[5], time_of_day[6]
184
- ::Tod::TimeOfDay.new(hour, minute, second).to_s
185
- elsif time_of_day.to_s == ''
186
- nil
187
- else
188
- Tod::TimeOfDay(time_of_day).to_s
189
- end
205
+ time_of_day =
206
+ if time_of_day.is_a? Hash
207
+ # rails multiparam attribute
208
+ # get hour, minute and second and construct new TimeOfDay object
209
+ ::Tod::TimeOfDay.new(time_of_day[4], time_of_day[5], time_of_day[6])
210
+ else
211
+ # return nil, if input is not parsable
212
+ Tod::TimeOfDay(time_of_day){}
213
+ end
214
+ time_of_day.to_s if time_of_day
190
215
  end
191
216
 
192
217
  def self.load(time)
193
- ::Tod::TimeOfDay(time) if time && !time.to_s.empty?
218
+ if time && !time.to_s.empty?
219
+ return ::Tod::TimeOfDay.new(24) if time.respond_to?(:day) && time.day == 2 && time.hour == 0 && time.min == 0 && time.sec == 0
220
+ ::Tod::TimeOfDay(time)
221
+ end
194
222
  end
195
223
  end
196
224
  end
@@ -0,0 +1,11 @@
1
+ module Tod
2
+ class TimeOfDayType < ActiveRecord::Type::Value
3
+ def cast(value)
4
+ TimeOfDay.load(value)
5
+ end
6
+
7
+ def serialize(value)
8
+ TimeOfDay.dump(value)
9
+ end
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module Tod
2
- VERSION = "2.1.1"
2
+ VERSION = "2.2.0"
3
3
  end
@@ -81,4 +81,11 @@ describe "TimeOfDay()" do
81
81
 
82
82
  assert_equal(tod, Tod::TimeOfDay.new(0, 00, 00))
83
83
  end
84
+
85
+ it "parses 24:00:00" do
86
+ t = "24:00:00"
87
+ tod = Tod::TimeOfDay(t)
88
+
89
+ assert_equal(tod, Tod::TimeOfDay.new(24, 00, 00))
90
+ end
84
91
  end
@@ -19,6 +19,18 @@ describe "TimeOfDay with ActiveRecord Serializable Attribute" do
19
19
  order = Order.create!({"time(4i)" => "8", "time(5i)" => "6", "time(6i)" => "5"})
20
20
  assert_equal Tod::TimeOfDay.new(8,6,5), order.time
21
21
  end
22
+
23
+ it "should not raise Exception on access of unparsable values" do
24
+ order = Order.new(time: 'unparsable')
25
+ order.time
26
+ assert order.valid?
27
+ end
28
+
29
+ it "should dump unparsable values to nil" do
30
+ assert_nil Tod::TimeOfDay.dump('')
31
+ assert_nil Tod::TimeOfDay.dump('unparsable')
32
+ assert_nil Tod::TimeOfDay.dump(nil)
33
+ end
22
34
  end
23
35
 
24
36
  describe ".load" do
@@ -41,6 +53,13 @@ describe "TimeOfDay with ActiveRecord Serializable Attribute" do
41
53
  order.reload
42
54
  assert_nil order.time
43
55
  end
56
+
57
+ it "dump 24:00:00 and get it back" do
58
+ time_of_day = Tod::TimeOfDay.new(24, 0, 0)
59
+ order = Order.create!(time: time_of_day)
60
+ order.reload
61
+ assert_equal Tod::TimeOfDay.new(24), order.time
62
+ end
44
63
  end
45
64
 
46
65
  describe "Order.where" do
@@ -4,7 +4,7 @@ describe "TimeOfDay" do
4
4
  describe "#initialize" do
5
5
  it "blocks invalid hours" do
6
6
  assert_raises(ArgumentError) { Tod::TimeOfDay.new(-1) }
7
- assert_raises(ArgumentError) { Tod::TimeOfDay.new 24 }
7
+ assert_raises(ArgumentError) { Tod::TimeOfDay.new 25 }
8
8
  end
9
9
 
10
10
  it "blocks invalid minutes" do
@@ -31,6 +31,10 @@ describe "TimeOfDay" do
31
31
  assert_equal 86399, Tod::TimeOfDay.new(23,59,59).second_of_day
32
32
  end
33
33
 
34
+ it "is 86400 at beginning of next day" do
35
+ assert_equal 86400, Tod::TimeOfDay.new(24,0,0).second_of_day
36
+ end
37
+
34
38
  it "have alias to_i" do
35
39
  tod = Tod::TimeOfDay.new(0,0,0)
36
40
  assert_equal tod.method(:second_of_day), tod.method(:to_i)
@@ -84,9 +88,12 @@ describe "TimeOfDay" do
84
88
  should_parse "12a", 0, 0, 0
85
89
  should_parse "12p", 12, 0, 0
86
90
 
91
+ should_parse "24:00:00", 24, 0, 0
92
+ should_parse "24:00", 24, 0, 0
93
+ should_parse "24", 24, 0, 0
94
+ should_parse "2400", 24, 0, 0
95
+
87
96
  should_not_parse "-1:30"
88
- should_not_parse "24:00:00"
89
- should_not_parse "24"
90
97
  should_not_parse "00:60"
91
98
  should_not_parse "00:00:60"
92
99
  should_not_parse "13a"
@@ -102,6 +109,11 @@ describe "TimeOfDay" do
102
109
  assert_raises(ArgumentError) { Tod::TimeOfDay.parse(nil) }
103
110
  end
104
111
 
112
+ it "executes block on parsing failure and return result instead" do
113
+ assert_equal Tod::TimeOfDay.new(1), Tod::TimeOfDay.parse('25:00:00') { Tod::TimeOfDay.new(1) }
114
+ assert_equal Tod::TimeOfDay.new(1), Tod::TimeOfDay.parse('25:00:00') { |time_string| Tod::TimeOfDay.parse(time_string.sub('25', '01')) }
115
+ end
116
+
105
117
  it "provides spaceship operator" do
106
118
  assert_equal(-1, Tod::TimeOfDay.new(8,0,0) <=> Tod::TimeOfDay.new(9,0,0))
107
119
  assert_equal 0, Tod::TimeOfDay.new(9,0,0) <=> Tod::TimeOfDay.new(9,0,0)
@@ -123,7 +135,7 @@ describe "TimeOfDay" do
123
135
  assert_equal Tod::TimeOfDay.new(8,20,0), Tod::TimeOfDay.new(8,20,00).round(300)
124
136
  assert_equal Tod::TimeOfDay.new(9,0,0), Tod::TimeOfDay.new(8,58,00).round(300)
125
137
  assert_equal Tod::TimeOfDay.new(8,0,0), Tod::TimeOfDay.new(8,02,29).round(300)
126
- assert_equal Tod::TimeOfDay.new(0,0,0), Tod::TimeOfDay.new(23,58,29).round(300)
138
+ assert_equal Tod::TimeOfDay.new(24,0,0), Tod::TimeOfDay.new(23,58,29).round(300)
127
139
  end
128
140
  end
129
141
 
@@ -133,10 +145,41 @@ describe "TimeOfDay" do
133
145
  end
134
146
  end
135
147
 
148
+ describe "to_formatted_s" do
149
+ it "has a default format" do
150
+ assert_equal "08:15:30", Tod::TimeOfDay.new(8,15,30).to_formatted_s
151
+ assert_equal "22:10:45", Tod::TimeOfDay.new(22,10,45).to_formatted_s
152
+ end
153
+
154
+ it "has a short format" do
155
+ assert_equal "8:15 am", Tod::TimeOfDay.new(8,15,30).to_formatted_s(:short)
156
+ assert_equal "10:10 pm", Tod::TimeOfDay.new(22,10,45).to_formatted_s(:short)
157
+ end
158
+
159
+ it "has a medium format" do
160
+ assert_equal "8:15:30 am", Tod::TimeOfDay.new(8,15,30).to_formatted_s(:medium)
161
+ assert_equal "10:10:45 pm", Tod::TimeOfDay.new(22,10,45).to_formatted_s(:medium)
162
+ end
163
+
164
+ it "has an ActiveSupport compatible time format" do
165
+ assert_equal "08:15", Tod::TimeOfDay.new(8,15,30).to_formatted_s(:time)
166
+ assert_equal "22:10", Tod::TimeOfDay.new(22,10,45).to_formatted_s(:time)
167
+ end
168
+
169
+ it "evaluates custom lambda lambda formats" do
170
+ begin
171
+ Tod::TimeOfDay::FORMATS[:lambda] = -> (t) { t.strftime("%H%M 😎") }
172
+ assert_equal "1337 😎", Tod::TimeOfDay.new(13,37).to_formatted_s(:lambda)
173
+ ensure
174
+ Tod::TimeOfDay::FORMATS.delete(:lambda)
175
+ end
176
+ end
177
+ end
178
+
136
179
  describe "to_s" do
137
- it "formats to HH:MM:SS" do
138
- assert_equal "08:15:30", Tod::TimeOfDay.new(8,15,30).to_s
139
- assert_equal "22:10:45", Tod::TimeOfDay.new(22,10,45).to_s
180
+ it "is aliased to to_formatted_s" do
181
+ t = Tod::TimeOfDay.new(8,15,30)
182
+ assert_equal t.to_formatted_s, t.to_s
140
183
  end
141
184
  end
142
185
 
@@ -215,7 +258,7 @@ describe "TimeOfDay" do
215
258
  end
216
259
 
217
260
  it "handles positive numbers a day or more away" do
218
- assert_equal Tod::TimeOfDay.new(0,0,0), Tod::TimeOfDay.from_second_of_day(86400)
261
+ assert_equal Tod::TimeOfDay.new(24,0,0), Tod::TimeOfDay.from_second_of_day(86400)
219
262
  assert_equal Tod::TimeOfDay.new(0,0,30), Tod::TimeOfDay.from_second_of_day(86430)
220
263
  assert_equal Tod::TimeOfDay.new(0,1,30), Tod::TimeOfDay.from_second_of_day(86490)
221
264
  assert_equal Tod::TimeOfDay.new(1,1,5), Tod::TimeOfDay.from_second_of_day(90065)
@@ -18,7 +18,7 @@ Gem::Specification.new do |s|
18
18
  s.add_development_dependency "rake"
19
19
  s.add_development_dependency "activerecord", ">= 3.0.0"
20
20
  s.add_development_dependency "sqlite3"
21
- s.add_development_dependency "pry"
21
+ s.add_development_dependency "pry-byebug"
22
22
  s.add_development_dependency "arel"
23
23
 
24
24
  s.files = `git ls-files`.split("\n")
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: 2.1.1
4
+ version: 2.2.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: 2017-04-14 00:00:00.000000000 Z
11
+ date: 2018-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: pry-byebug
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -128,15 +128,18 @@ files:
128
128
  - gemfiles/4.1.gemfile
129
129
  - gemfiles/4.2.gemfile
130
130
  - gemfiles/5.0.gemfile
131
+ - gemfiles/5.2.gemfile
131
132
  - lib/tod.rb
132
133
  - lib/tod/arel_extensions.rb
133
134
  - lib/tod/conversions.rb
134
135
  - lib/tod/core_extensions.rb
135
136
  - lib/tod/date_extensions.rb
136
137
  - lib/tod/mongoization.rb
138
+ - lib/tod/railtie.rb
137
139
  - lib/tod/shift.rb
138
140
  - lib/tod/time_extensions.rb
139
141
  - lib/tod/time_of_day.rb
142
+ - lib/tod/time_of_day_type.rb
140
143
  - lib/tod/version.rb
141
144
  - test/support/active_record.rb
142
145
  - test/test_helper.rb
@@ -168,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
171
  version: '0'
169
172
  requirements: []
170
173
  rubyforge_project:
171
- rubygems_version: 2.5.2
174
+ rubygems_version: 2.7.6
172
175
  signing_key:
173
176
  specification_version: 4
174
177
  summary: Supplies TimeOfDay and Shift class