split_datetime 0.0.0 → 0.0.1
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.
- data/README.md +1 -1
- data/lib/split_datetime/accessors.rb +3 -0
- data/lib/split_datetime/version.rb +1 -1
- data/spec/split_datetime/accessors_spec.rb +16 -0
- metadata +10 -5
data/README.md
CHANGED
@@ -36,7 +36,7 @@ Add your js datepicker and you're good to go. (Of course, this also works with s
|
|
36
36
|
|
37
37
|
```ruby
|
38
38
|
accepts_split_datetime_for :starts_at, default: lambda { Time.now.change(min: 0) + 2.weeks }
|
39
|
-
accepts_split_datetime_for :starts_at, default: lambda {
|
39
|
+
accepts_split_datetime_for :starts_at, default: lambda { Time.now }
|
40
40
|
```
|
41
41
|
|
42
42
|
You can also specify the date format for the view:
|
@@ -16,15 +16,18 @@ module SplitDatetime
|
|
16
16
|
end
|
17
17
|
|
18
18
|
define_method("#{attr}_date=") do |date|
|
19
|
+
return unless date.present?
|
19
20
|
date = Date.parse(date.to_s)
|
20
21
|
self.send("#{attr}=", self.send(attr).change(year: date.year, month: date.month, day: date.day))
|
21
22
|
end
|
22
23
|
|
23
24
|
define_method("#{attr}_hour=") do |hour|
|
25
|
+
return unless hour.present?
|
24
26
|
self.send("#{attr}=", self.send(attr).change(hour: hour, min: self.send(attr).min))
|
25
27
|
end
|
26
28
|
|
27
29
|
define_method("#{attr}_min=") do |min|
|
30
|
+
return unless min.present?
|
28
31
|
self.send("#{attr}=", self.send(attr).change(min: min))
|
29
32
|
end
|
30
33
|
|
@@ -32,6 +32,7 @@ describe SplitDatetime::Accessors do
|
|
32
32
|
|
33
33
|
describe "split datetime methods" do
|
34
34
|
before { model.starts_at = Time.new(2222, 12, 22, 13, 44, 0) }
|
35
|
+
|
35
36
|
describe "#starts_at_date" do
|
36
37
|
it "returns the model's starts_at date as string" do
|
37
38
|
model.starts_at_date.should == "2222-12-22"
|
@@ -52,6 +53,11 @@ describe SplitDatetime::Accessors do
|
|
52
53
|
model.starts_at_date = "1111-01-01"
|
53
54
|
model.starts_at.should == Time.new(1111, 1, 1, 13, 44, 0)
|
54
55
|
end
|
56
|
+
|
57
|
+
it "uses the default if the string is empty" do
|
58
|
+
model.starts_at_date = ""
|
59
|
+
model.starts_at.should == Time.new(2222, 12, 22, 13, 44, 0)
|
60
|
+
end
|
55
61
|
end
|
56
62
|
|
57
63
|
describe "#starts_at_hour" do
|
@@ -63,6 +69,11 @@ describe SplitDatetime::Accessors do
|
|
63
69
|
model.starts_at_hour = 11
|
64
70
|
model.starts_at.should == Time.new(2222, 12, 22, 11, 44, 0)
|
65
71
|
end
|
72
|
+
|
73
|
+
it "uses the default if the string is empty" do
|
74
|
+
model.starts_at_hour = ""
|
75
|
+
model.starts_at.should == Time.new(2222, 12, 22, 13, 44, 0)
|
76
|
+
end
|
66
77
|
end
|
67
78
|
|
68
79
|
describe "#starts_at_min" do
|
@@ -74,6 +85,11 @@ describe SplitDatetime::Accessors do
|
|
74
85
|
model.starts_at_min = 55
|
75
86
|
model.starts_at.should == Time.new(2222, 12, 22, 13, 55, 0)
|
76
87
|
end
|
88
|
+
|
89
|
+
it "uses the default if the string is empty" do
|
90
|
+
model.starts_at_min = ""
|
91
|
+
model.starts_at.should == Time.new(2222, 12, 22, 13, 44, 0)
|
92
|
+
end
|
77
93
|
end
|
78
94
|
end
|
79
95
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: split_datetime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-04-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '2.11'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.11'
|
25
30
|
description: ! ' Adds accessors to a class so that the date can be set as a string
|
26
31
|
while minutes and hours can be set as integers. This allows you to have an input
|
27
32
|
textfield (with a javascript datepicker) for the date and dropdowns for the time.
|
@@ -60,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
60
65
|
version: '0'
|
61
66
|
requirements: []
|
62
67
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.8.
|
68
|
+
rubygems_version: 1.8.23
|
64
69
|
signing_key:
|
65
70
|
specification_version: 3
|
66
71
|
summary: Split datetime inputs into text and dropdowns in rails views
|