time_splitter 1.0.0 → 1.1.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 +4 -4
- data/.travis.yml +3 -1
- data/README.md +1 -1
- data/lib/time_splitter/accessors.rb +15 -2
- data/lib/time_splitter/version.rb +1 -1
- data/spec/time_splitter/accessors_spec.rb +18 -0
- data/time_splitter.gemspec +1 -1
- metadata +13 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0e9f28853c1647a7fafd682ebcda847bc8a81753
|
4
|
+
data.tar.gz: b791b89d4b08f3612c6d7276d4ffe5fd88267ac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dbb0a180afa136483c6a7130217fd5790d605e3a7887470763d7e116f0662609ed2ffd6bd4b87af69b90cbf6ca4bde8cb3ba9c811921c53ba92d989f5b09836
|
7
|
+
data.tar.gz: 5e69333f8465f15f41a62d51973578b8fab4f6709739ff7ac2d5488c8bdb5bab22a1725cf9a5d95c0f34f3cb77949e945556f309ade65e903a4da3f39211eeca
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -45,7 +45,7 @@ In your view:
|
|
45
45
|
|
46
46
|
Add your js datepicker and you're good to go. (Of course, this also works with standard Rails form helpers).
|
47
47
|
|
48
|
-
If you are using Rails < 4.0 and/or are not using StrongParameters, you must add
|
48
|
+
If you are using Rails < 4.0 and/or are not using StrongParameters, you must add `attr_accessible` for any of the split attributes you want to permit mass-assignment. TimeSplitter provides the methods that can be directly accessed, but will not automatically whitelist any of them for mass-assignment.
|
49
49
|
|
50
50
|
## Options
|
51
51
|
|
@@ -19,7 +19,13 @@ module TimeSplitter
|
|
19
19
|
|
20
20
|
define_method("#{attr}_date=") do |date|
|
21
21
|
return unless date.present?
|
22
|
-
date
|
22
|
+
unless date.is_a?(Date) || date.is_a?(Time)
|
23
|
+
if options[:date_format]
|
24
|
+
date = Date.strptime(date.to_s, options[:date_format])
|
25
|
+
else
|
26
|
+
date = Date.parse(date.to_s)
|
27
|
+
end
|
28
|
+
end
|
23
29
|
self.send("#{attr}=", self.send("#{attr}_or_new").change(year: date.year, month: date.month, day: date.day))
|
24
30
|
end
|
25
31
|
|
@@ -35,7 +41,14 @@ module TimeSplitter
|
|
35
41
|
|
36
42
|
define_method("#{attr}_time=") do |time|
|
37
43
|
return unless time.present?
|
38
|
-
|
44
|
+
|
45
|
+
unless time.is_a?(Date) || time.is_a?(Time)
|
46
|
+
if options[:time_format]
|
47
|
+
time = Time.strptime(time, options[:time_format])
|
48
|
+
else
|
49
|
+
time = Time.parse(time)
|
50
|
+
end
|
51
|
+
end
|
39
52
|
self.send("#{attr}=", self.send("#{attr}_or_new").change(hour: time.hour, min: time.min))
|
40
53
|
end
|
41
54
|
|
@@ -71,6 +71,18 @@ describe TimeSplitter::Accessors do
|
|
71
71
|
expect(model.starts_at).to eq Time.new(1111, 1, 1, 0, 0, 0, '+00:00')
|
72
72
|
end
|
73
73
|
|
74
|
+
it "can set from a string when format is modified" do
|
75
|
+
Model.split_accessor(:starts_at, date_format: "%m-%d-%Y")
|
76
|
+
model.starts_at_date = "12-31-1111"
|
77
|
+
expect(model.starts_at).to eq Time.new(1111, 12, 31, 0, 0, 0, '+00:00')
|
78
|
+
end
|
79
|
+
|
80
|
+
it "can set from a date when format is modified" do
|
81
|
+
Model.split_accessor(:starts_at, date_format: "%m-%d-%Y")
|
82
|
+
model.starts_at_date = Time.new(1111, 12, 31, 0, 0, 0, '+00:00')
|
83
|
+
expect(model.starts_at).to eq Time.new(1111, 12, 31, 0, 0, 0, '+00:00')
|
84
|
+
end
|
85
|
+
|
74
86
|
it "is nil if the string is empty" do
|
75
87
|
model.starts_at_date = ""
|
76
88
|
expect(model.starts_at).to be_nil
|
@@ -202,6 +214,12 @@ describe TimeSplitter::Accessors do
|
|
202
214
|
expect(model.starts_at_time).to eq "01:44PM"
|
203
215
|
end
|
204
216
|
|
217
|
+
it "can set from a string when format is modified" do
|
218
|
+
Model.split_accessor(:starts_at, time_format: "%k-%M")
|
219
|
+
model.starts_at_time = "23-59"
|
220
|
+
expect(model.starts_at).to eq Time.new(2222, 12, 22, 23, 59, 0, '+00:00')
|
221
|
+
end
|
222
|
+
|
205
223
|
it 'sets the hour and minute of #starts_at' do
|
206
224
|
model.starts_at_time = '08:33'
|
207
225
|
expect(model.starts_at).to eq Time.new(2222, 12, 22, 8, 33, 0, '+00:00')
|
data/time_splitter.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: time_splitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michi Huber
|
@@ -9,36 +9,36 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2015-05-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activesupport
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '0'
|
21
21
|
type: :development
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '0'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: rspec
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - ~>
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '2
|
34
|
+
version: '3.2'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - ~>
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '2
|
41
|
+
version: '3.2'
|
42
42
|
description: Add split accessors for Date/Time/DateTime objects to easily set the
|
43
43
|
date, time, hour, or minute.
|
44
44
|
email:
|
@@ -48,8 +48,8 @@ executables: []
|
|
48
48
|
extensions: []
|
49
49
|
extra_rdoc_files: []
|
50
50
|
files:
|
51
|
-
- .gitignore
|
52
|
-
- .travis.yml
|
51
|
+
- ".gitignore"
|
52
|
+
- ".travis.yml"
|
53
53
|
- Gemfile
|
54
54
|
- LICENSE
|
55
55
|
- README.md
|
@@ -69,17 +69,17 @@ require_paths:
|
|
69
69
|
- lib
|
70
70
|
required_ruby_version: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
|
-
- -
|
72
|
+
- - ">="
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
76
|
requirements:
|
77
|
-
- -
|
77
|
+
- - ">="
|
78
78
|
- !ruby/object:Gem::Version
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.
|
82
|
+
rubygems_version: 2.4.6
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Use `datetime_accessor :starts_at` to provide `starts_at_date`, `starts_at_time`,
|