tod 2.1.0 → 2.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
  SHA1:
3
- metadata.gz: 07c87817736be833dd3bc8ce83a55f075cdf79d9
4
- data.tar.gz: 6eec299d0c6fe1b0c4c9385d555d9bf60e794ae1
3
+ metadata.gz: 5546b071b1fedc06fb6af4b11dff091e05ffc98d
4
+ data.tar.gz: bda08b0019d1af90e0a4cb31f5d86833b096737d
5
5
  SHA512:
6
- metadata.gz: ac687afb2c4bf51aeb96143f955d68abcf5c1e4e9d82cd1fbd782131f4fbfa30c1992927f19715ef348fa05c8bb0732dc58a4cae24ea84dd41bc17f5bafbc06c
7
- data.tar.gz: f1c51e6615f4b1961f5ce874a878a66cd258d30ff3069bd8b3fe3b265412e36273b333286c4ea7ed0ce3046255cbba64e307f4e113e72f06dde63419cdd9934b
6
+ metadata.gz: 1c6993e9088d273ca572061ee93d80c5549e418dc7d720833dbba5d2ea68d199707e65d459657c3d6af961e4a1bb1c0cdce3b10ee31699c9b769e30e93bed335
7
+ data.tar.gz: 73c8d5a8b90b06de86d327abf54eac4ce6ee877609595977cbedb3da7322d06eeb1159fcc478eaa34ae7a7541e7fd7052d4407d687cb94a35b99e735f271133d
data/.gitignore CHANGED
@@ -5,3 +5,4 @@ nbproject
5
5
  *.swp
6
6
  .rvmrc
7
7
  vendor/
8
+ .idea
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.1
4
- - 2.2.5
5
- - 2.1.10
3
+ - 2.3.3
4
+ - 2.2.6
6
5
  gemfile:
7
- - gemfiles/3.2.gemfile
8
6
  - gemfiles/4.0.gemfile
9
7
  - gemfiles/4.1.gemfile
10
8
  - gemfiles/4.2.gemfile
9
+ - gemfiles/5.0.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ # 2.1.1 (April 14, 2017)
2
+
3
+ * Fix serialize Ruby Time to Tod::TimeOfDay (Ryan Dick)
4
+ * Fix TimeOfDay.from_second_of_day when passed float (Jack Christensen)
5
+ * Fix Rails 5 multi-param assignment (Miklos Fazekas)
6
+
1
7
  # 2.1.0 (May 9, 2016)
2
8
 
3
9
  * Fix date extensions requiring date (ambirdsall)
data/Gemfile.lock CHANGED
@@ -1,39 +1,36 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tod (2.1.0)
4
+ tod (2.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
- activemodel (4.2.3)
10
- activesupport (= 4.2.3)
11
- builder (~> 3.1)
12
- activerecord (4.2.3)
13
- activemodel (= 4.2.3)
14
- activesupport (= 4.2.3)
15
- arel (~> 6.0)
16
- activesupport (4.2.3)
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)
16
+ concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (~> 0.7)
18
- json (~> 1.7, >= 1.7.7)
19
18
  minitest (~> 5.1)
20
- thread_safe (~> 0.3, >= 0.3.4)
21
19
  tzinfo (~> 1.1)
22
- arel (6.0.2)
23
- builder (3.2.2)
24
- coderay (1.1.0)
25
- i18n (0.7.0)
26
- json (1.8.3)
20
+ arel (7.1.4)
21
+ coderay (1.1.1)
22
+ concurrent-ruby (1.0.5)
23
+ i18n (0.8.1)
27
24
  method_source (0.8.2)
28
- minitest (5.7.0)
29
- pry (0.10.1)
25
+ minitest (5.10.1)
26
+ pry (0.10.4)
30
27
  coderay (~> 1.1.0)
31
28
  method_source (~> 0.8.1)
32
29
  slop (~> 3.4)
33
- rake (10.4.2)
30
+ rake (12.0.0)
34
31
  slop (3.6.0)
35
- sqlite3 (1.3.10)
36
- thread_safe (0.3.5)
32
+ sqlite3 (1.3.13)
33
+ thread_safe (0.3.6)
37
34
  tzinfo (1.2.2)
38
35
  thread_safe (~> 0.1)
39
36
 
@@ -51,4 +48,4 @@ DEPENDENCIES
51
48
  tzinfo
52
49
 
53
50
  BUNDLED WITH
54
- 1.11.2
51
+ 1.14.6
data/README.markdown CHANGED
@@ -89,6 +89,15 @@ Format strings are passed to Time#strftime.
89
89
  Tod::TimeOfDay.new(17,15).strftime("%I:%M %p") # => "05:15 PM"
90
90
  Tod::TimeOfDay.new(22,5,15).strftime("%I:%M:%S %p") # => "10:05:15 PM"
91
91
 
92
+ Rounding
93
+ ----------
94
+
95
+ Round to the given nearest number of seconds.
96
+
97
+ Tod::TimeOfDay.new(8,15,31).round(5) # => "08:15:30"
98
+ Tod::TimeOfDay.new(8,15,34).round(60) # => "08:16:00"
99
+ Tod::TimeOfDay.new(8,02,29).round(300) # => "08:00:00"
100
+
92
101
  Convenience methods for dates and times
93
102
  ---------------------------------------
94
103
 
@@ -241,7 +250,7 @@ Compatibility
241
250
 
242
251
  [![Build Status](https://travis-ci.org/jackc/tod.png)](https://travis-ci.org/jackc/tod)
243
252
 
244
- Tod is compatible with Ruby 1.9.3, 2.0.0, 2.1.8, and 2.2.0. It is tested against Rails 3.2, 4.0, 4.1, 4.2.
253
+ Tod is compatible with Ruby 1.9.3, 2.0.0, 2.1.8, and 2.2.0. It is tested against Rails 3.2, 4.0, 4.1, 4.2, 5.0.
245
254
 
246
255
 
247
256
  License
@@ -1,5 +1,5 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "activerecord", "~> 3.2.13"
3
+ gem 'activerecord', '~> 5.0.0.1'
4
4
 
5
5
  gemspec :path=>"../"
@@ -61,6 +61,21 @@ module Tod
61
61
  @second_of_day <=> other.second_of_day
62
62
  end
63
63
 
64
+ # Rounding to the given nearest number of seconds
65
+ def round(round_sec = 1)
66
+ down = self - (self.to_i % round_sec)
67
+ up = down + round_sec
68
+
69
+ difference_down = self - down
70
+ difference_up = up - self
71
+
72
+ if (difference_down < difference_up)
73
+ return down
74
+ else
75
+ return up
76
+ end
77
+ end
78
+
64
79
  # Formats identically to Time#strftime
65
80
  def strftime(format_string)
66
81
  Time.local(2000,1,1, @hour, @minute, @second).strftime(format_string)
@@ -96,6 +111,7 @@ module Tod
96
111
  #
97
112
  # TimeOfDay.from_second_of_day(3600) == TimeOfDay.new(1) # => true
98
113
  def self.from_second_of_day(second_of_day)
114
+ second_of_day = Integer(second_of_day)
99
115
  remaining_seconds = second_of_day % NUM_SECONDS_IN_DAY
100
116
  hour = remaining_seconds / NUM_SECONDS_IN_HOUR
101
117
  remaining_seconds -= hour * NUM_SECONDS_IN_HOUR
@@ -162,10 +178,14 @@ module Tod
162
178
  end
163
179
 
164
180
  def self.dump(time_of_day)
165
- if time_of_day.to_s == ''
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 == ''
166
186
  nil
167
187
  else
168
- time_of_day.to_s
188
+ Tod::TimeOfDay(time_of_day).to_s
169
189
  end
170
190
  end
171
191
 
data/lib/tod/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Tod
2
- VERSION = "2.1.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
 
3
3
  describe "TimeOfDay()" do
4
4
  it "handles Tod::TimeOfDay" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
 
3
3
  describe "Date extensions" do
4
4
  describe "#at" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
 
3
3
  describe "Shift" do
4
4
  describe "#initialize" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
  require File.expand_path(File.join(File.dirname(__FILE__),'..','support/active_record'))
3
3
 
4
4
  class Order < ActiveRecord::Base
@@ -14,20 +14,32 @@ describe "TimeOfDay with ActiveRecord Serializable Attribute" do
14
14
  it "sets nil as value" do
15
15
  Order.create!(time: nil)
16
16
  end
17
+
18
+ it "works with multiparam time arguments" do
19
+ order = Order.create!({"time(4i)" => "8", "time(5i)" => "6", "time(6i)" => "5"})
20
+ assert_equal Tod::TimeOfDay.new(8,6,5), order.time
21
+ end
17
22
  end
18
23
 
19
24
  describe ".load" do
20
- it "loads set time" do
25
+ it "loads set Tod::TimeOfDay" do
21
26
  time_of_day = Tod::TimeOfDay.new(9, 30)
22
27
  order = Order.create!(time: time_of_day)
23
28
  order.reload
24
29
  assert_equal order.time, time_of_day
25
30
  end
26
31
 
32
+ it "loads set Time" do
33
+ time_of_day = Time.new(2015, 10, 21, 16, 29, 0, "-07:00")
34
+ order = Order.create!(time: time_of_day)
35
+ order.reload
36
+ assert_equal order.time, Tod::TimeOfDay.new(16, 29)
37
+ end
38
+
27
39
  it "returns nil if time is not set" do
28
40
  order = Order.create!(time: nil)
29
41
  order.reload
30
- assert_equal order.time, nil
42
+ assert_nil order.time
31
43
  end
32
44
  end
33
45
 
@@ -1,9 +1,9 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
 
3
3
  describe "TimeOfDay" do
4
4
  describe "#initialize" do
5
5
  it "blocks invalid hours" do
6
- assert_raises(ArgumentError) { Tod::TimeOfDay.new -1 }
6
+ assert_raises(ArgumentError) { Tod::TimeOfDay.new(-1) }
7
7
  assert_raises(ArgumentError) { Tod::TimeOfDay.new 24 }
8
8
  end
9
9
 
@@ -50,7 +50,7 @@ describe "TimeOfDay" do
50
50
  def self.should_not_parse(parse_string)
51
51
  it "does not parse '#{parse_string}'" do
52
52
  assert_equal false, Tod::TimeOfDay.parsable?(parse_string)
53
- assert_equal nil, Tod::TimeOfDay.try_parse(parse_string)
53
+ assert_nil Tod::TimeOfDay.try_parse(parse_string)
54
54
  assert_raises(ArgumentError) { Tod::TimeOfDay.parse(parse_string) }
55
55
  end
56
56
  end
@@ -98,12 +98,12 @@ describe "TimeOfDay" do
98
98
 
99
99
  it "does not parse 'nil'" do
100
100
  assert_equal false, Tod::TimeOfDay.parsable?(nil)
101
- assert_equal nil, Tod::TimeOfDay.try_parse(nil)
101
+ assert_nil Tod::TimeOfDay.try_parse(nil)
102
102
  assert_raises(ArgumentError) { Tod::TimeOfDay.parse(nil) }
103
103
  end
104
104
 
105
105
  it "provides spaceship operator" do
106
- assert_equal -1, Tod::TimeOfDay.new(8,0,0) <=> Tod::TimeOfDay.new(9,0,0)
106
+ assert_equal(-1, Tod::TimeOfDay.new(8,0,0) <=> Tod::TimeOfDay.new(9,0,0))
107
107
  assert_equal 0, Tod::TimeOfDay.new(9,0,0) <=> Tod::TimeOfDay.new(9,0,0)
108
108
  assert_equal 1, Tod::TimeOfDay.new(10,0,0) <=> Tod::TimeOfDay.new(9,0,0)
109
109
  end
@@ -112,6 +112,20 @@ describe "TimeOfDay" do
112
112
  assert_equal Tod::TimeOfDay.new(8,0,0), Tod::TimeOfDay.new(8,0,0)
113
113
  end
114
114
 
115
+ describe "round_nearest" do
116
+ it "rounds to the given nearest number of seconds" do
117
+ assert_equal Tod::TimeOfDay.new(8,15,30), Tod::TimeOfDay.new(8,15,31).round(5)
118
+ assert_equal Tod::TimeOfDay.new(8,15,35), Tod::TimeOfDay.new(8,15,33).round(5)
119
+ assert_equal Tod::TimeOfDay.new(8,16,0), Tod::TimeOfDay.new(8,15,34).round(60)
120
+ assert_equal Tod::TimeOfDay.new(8,15,0), Tod::TimeOfDay.new(8,15,15).round(60)
121
+ assert_equal Tod::TimeOfDay.new(8,15,0), Tod::TimeOfDay.new(8,17,15).round(300)
122
+ assert_equal Tod::TimeOfDay.new(8,20,0), Tod::TimeOfDay.new(8,18,15).round(300)
123
+ assert_equal Tod::TimeOfDay.new(8,20,0), Tod::TimeOfDay.new(8,20,00).round(300)
124
+ assert_equal Tod::TimeOfDay.new(9,0,0), Tod::TimeOfDay.new(8,58,00).round(300)
125
+ 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)
127
+ end
128
+ end
115
129
 
116
130
  describe "strftime" do
117
131
  it "accepts standard strftime format codes" do
@@ -219,6 +233,10 @@ describe "TimeOfDay" do
219
233
  it "has alias from_i" do
220
234
  assert_equal Tod::TimeOfDay.method(:from_second_of_day), Tod::TimeOfDay.method(:from_i)
221
235
  end
236
+
237
+ it "handles floats" do
238
+ assert_equal Tod::TimeOfDay.new(15,30,0), Tod::TimeOfDay.from_second_of_day(55800.0)
239
+ end
222
240
  end
223
241
 
224
242
  describe "on" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
 
3
3
  describe "TimeOfDay with ActiveSupport" do
4
4
  describe ".time_zone" do
@@ -1,4 +1,4 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__),'..','test_helper'))
1
+ require_relative '../test_helper'
2
2
 
3
3
  describe "Time extensions" do
4
4
  describe "#to_time_of_day" do
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.0
4
+ version: 2.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: 2016-05-09 00:00:00.000000000 Z
11
+ date: 2017-04-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -124,10 +124,10 @@ files:
124
124
  - MIT-LICENSE
125
125
  - README.markdown
126
126
  - Rakefile
127
- - gemfiles/3.2.gemfile
128
127
  - gemfiles/4.0.gemfile
129
128
  - gemfiles/4.1.gemfile
130
129
  - gemfiles/4.2.gemfile
130
+ - gemfiles/5.0.gemfile
131
131
  - lib/tod.rb
132
132
  - lib/tod/arel_extensions.rb
133
133
  - lib/tod/conversions.rb
@@ -168,17 +168,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  version: '0'
169
169
  requirements: []
170
170
  rubyforge_project:
171
- rubygems_version: 2.5.1
171
+ rubygems_version: 2.5.2
172
172
  signing_key:
173
173
  specification_version: 4
174
174
  summary: Supplies TimeOfDay and Shift class
175
- test_files:
176
- - test/support/active_record.rb
177
- - test/test_helper.rb
178
- - test/tod/conversion_test.rb
179
- - test/tod/date_test.rb
180
- - test/tod/shift_test.rb
181
- - test/tod/time_of_day_serializable_attribute_test.rb
182
- - test/tod/time_of_day_test.rb
183
- - test/tod/time_of_day_time_zone_with_active_support_test.rb
184
- - test/tod/time_test.rb
175
+ test_files: []