multiparameter_date_time 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +10 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +7 -0
- data/lib/multiparameter_date_time/version.rb +3 -0
- data/lib/multiparameter_date_time.rb +103 -0
- data/multiparameter_date_time.gemspec +24 -0
- data/spec/multiparameter_date_time_spec.rb +350 -0
- data/spec/spec_helper.rb +14 -0
- metadata +163 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Case Commons, LLC
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# MultiparameterDateTime
|
2
|
+
|
3
|
+
Set a DateTime via two accessors, one for the date, one for the time
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'multiparameter_date_time'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install multiparameter_date_time
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
````ruby
|
22
|
+
class Article < ActiveRecord::Base
|
23
|
+
include MultiparameterDateTime
|
24
|
+
|
25
|
+
multiparameter_date_time :publish_at
|
26
|
+
end
|
27
|
+
|
28
|
+
record = Article.new(
|
29
|
+
:publish_at_date_part => "01/01/2001",
|
30
|
+
:publish_at_time_part => "4:30 pm"
|
31
|
+
)
|
32
|
+
|
33
|
+
record.publish_at #=> Mon, 01 Jan 2001 16:30:00 +0000
|
34
|
+
|
35
|
+
record.publish_at_date_part = "2/3/2004"
|
36
|
+
record.publish_at #=> Tue, 03 Feb 2004 16:30:00 +0000
|
37
|
+
|
38
|
+
record = Article.new(
|
39
|
+
:publish_at_date_part => "01/01/2001",
|
40
|
+
)
|
41
|
+
|
42
|
+
record.publish_at #=> :incomplete
|
43
|
+
record.publish_at_date_part #=> "01/01/2001"
|
44
|
+
record.publish_at_time_part #=> nil
|
45
|
+
|
46
|
+
record = Article.new(
|
47
|
+
:publish_at_time_part => "09:30 am",
|
48
|
+
)
|
49
|
+
|
50
|
+
record.publish_at #=> :incomplete
|
51
|
+
record.publish_at_date_part #=> nil
|
52
|
+
record.publish_at_time_part #=> "09:30 am"
|
53
|
+
````
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
require "active_support/concern"
|
2
|
+
require "american_date"
|
3
|
+
|
4
|
+
module MultiparameterDateTime
|
5
|
+
extend ActiveSupport::Concern
|
6
|
+
|
7
|
+
VALID_TIME_FORMAT = /\A\d?\d:\d{2}(:\d{2})?\s*([ap]m)?\s*([A-Z]{3,5})?\Z/
|
8
|
+
VALID_DATE_FORMAT = /\A\d?\d\/\d?\d\/\d{4}|(\d{4}-\d{2}-\d{2})\Z/
|
9
|
+
|
10
|
+
module ClassMethods
|
11
|
+
def multiparameter_date_time(attribute_name)
|
12
|
+
date_attribute = :"#{attribute_name}_date_part"
|
13
|
+
time_attribute = :"#{attribute_name}_time_part"
|
14
|
+
|
15
|
+
date_ivar_name = "@#{date_attribute}"
|
16
|
+
time_ivar_name = "@#{time_attribute}"
|
17
|
+
|
18
|
+
date_part_setter = :"#{date_attribute}="
|
19
|
+
time_part_setter = :"#{time_attribute}="
|
20
|
+
|
21
|
+
define_method "#{attribute_name}=" do |date_time_input|
|
22
|
+
date_time_input = date_time_input.to_time_in_current_zone if date_time_input.respond_to?(:to_time_in_current_zone)
|
23
|
+
if date_time_input.is_a?(String)
|
24
|
+
iso8601 = Time.iso8601(date_time_input).in_time_zone(Time.zone) rescue nil
|
25
|
+
if iso8601
|
26
|
+
write_attribute_for_multiparameter_date_time(attribute_name, iso8601)
|
27
|
+
else
|
28
|
+
date_part, time_part = date_time_input.split(" ", 2)
|
29
|
+
parsed_date_part = Date.parse(date_part) rescue nil
|
30
|
+
if time_part.nil? && parsed_date_part
|
31
|
+
write_attribute_for_multiparameter_date_time(
|
32
|
+
attribute_name,
|
33
|
+
parsed_date_part.to_time_in_current_zone)
|
34
|
+
else
|
35
|
+
public_send(date_part_setter, date_part)
|
36
|
+
public_send(time_part_setter, time_part)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
write_attribute_for_multiparameter_date_time(attribute_name, date_time_input)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
define_method date_part_setter do |date_string|
|
45
|
+
instance_variable_set(date_ivar_name, date_string)
|
46
|
+
time_string = send(time_attribute)
|
47
|
+
set_combined_datetime(attribute_name, date_string, time_string)
|
48
|
+
end
|
49
|
+
|
50
|
+
define_method time_part_setter do |time_string|
|
51
|
+
instance_variable_set(time_ivar_name, time_string)
|
52
|
+
date_string = send(date_attribute)
|
53
|
+
set_combined_datetime(attribute_name, date_string, time_string)
|
54
|
+
end
|
55
|
+
|
56
|
+
define_method time_attribute do
|
57
|
+
if instance_variable_defined?(time_ivar_name)
|
58
|
+
instance_variable_get(time_ivar_name)
|
59
|
+
else
|
60
|
+
time = public_send(attribute_name)
|
61
|
+
return nil if time.nil? || time == :incomplete
|
62
|
+
|
63
|
+
time.strftime("%-I:%M %P")
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
define_method date_attribute do
|
68
|
+
if instance_variable_defined?(date_ivar_name)
|
69
|
+
instance_variable_get(date_ivar_name)
|
70
|
+
else
|
71
|
+
date = public_send(attribute_name)
|
72
|
+
return nil if date.nil? || date == :incomplete
|
73
|
+
date.strftime("%-m/%-d/%Y")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
|
81
|
+
def set_combined_datetime(name, date_string, time_string)
|
82
|
+
if date_string =~ MultiparameterDateTime::VALID_DATE_FORMAT && time_string =~ MultiparameterDateTime::VALID_TIME_FORMAT
|
83
|
+
begin
|
84
|
+
write_attribute_for_multiparameter_date_time(
|
85
|
+
name, Time.zone.parse("#{date_string} #{time_string}")
|
86
|
+
)
|
87
|
+
rescue ArgumentError
|
88
|
+
write_attribute_for_multiparameter_date_time(name, :incomplete)
|
89
|
+
end
|
90
|
+
|
91
|
+
elsif date_string.blank? && time_string.blank?
|
92
|
+
write_attribute_for_multiparameter_date_time(name, nil)
|
93
|
+
else
|
94
|
+
write_attribute_for_multiparameter_date_time(name, :incomplete)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
def write_attribute_for_multiparameter_date_time(attribute_name, value)
|
99
|
+
write_attribute(attribute_name, value)
|
100
|
+
rescue NoMethodError
|
101
|
+
instance_variable_set("@#{attribute_name}", value)
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/multiparameter_date_time/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Case Commons, LLC", "Grant Hutchins", "Trace Wax"]
|
6
|
+
gem.email = ["casecommons-dev@googlegroups.com", "gems@nertzy.com", "gems@tracedwax.com"]
|
7
|
+
gem.summary = "Set a DateTime via two accessors, one for the date, one for the time"
|
8
|
+
gem.homepage = "https://github.com/Casecommons/multiparameter_date_time"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "multiparameter_date_time"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = MultiparameterDateTime::VERSION
|
16
|
+
|
17
|
+
gem.add_dependency "american_date"
|
18
|
+
|
19
|
+
gem.add_development_dependency 'activerecord'
|
20
|
+
gem.add_development_dependency 'activesupport'
|
21
|
+
gem.add_development_dependency 'rspec', '~> 2.11'
|
22
|
+
gem.add_development_dependency 'with_model', "~> 0.3"
|
23
|
+
gem.add_development_dependency 'informal', "~> 0.0.3"
|
24
|
+
end
|
@@ -0,0 +1,350 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
require "multiparameter_date_time"
|
4
|
+
require "informal"
|
5
|
+
require "active_support/core_ext/time/zones"
|
6
|
+
|
7
|
+
describe MultiparameterDateTime do
|
8
|
+
before do
|
9
|
+
Time.zone = "US/Eastern"
|
10
|
+
end
|
11
|
+
|
12
|
+
with_model :ModelWithDateTime do
|
13
|
+
table do |t|
|
14
|
+
t.datetime :foo
|
15
|
+
end
|
16
|
+
|
17
|
+
model do
|
18
|
+
include MultiparameterDateTime
|
19
|
+
multiparameter_date_time :foo
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class ActiveModelWithDateTime
|
24
|
+
include Informal::Model
|
25
|
+
attr_accessor :foo
|
26
|
+
include MultiparameterDateTime
|
27
|
+
multiparameter_date_time :foo
|
28
|
+
end
|
29
|
+
|
30
|
+
%w[ModelWithDateTime ActiveModelWithDateTime].each do |model_name|
|
31
|
+
let(:parent_model) { model_name.constantize }
|
32
|
+
let(:subclass_model) { Class.new(parent_model) }
|
33
|
+
|
34
|
+
[false, true].each do |use_subclass|
|
35
|
+
let(:model) { use_subclass ? subclass_model : parent_model }
|
36
|
+
|
37
|
+
context "for #{"a subclass of " if use_subclass}#{model_name}" do
|
38
|
+
let(:record) do
|
39
|
+
model.new(foo_date_part: foo_date_part, foo_time_part: foo_time_part)
|
40
|
+
end
|
41
|
+
|
42
|
+
subject { record }
|
43
|
+
|
44
|
+
describe "when a value is present" do
|
45
|
+
let(:record) { model.new(foo: Time.zone.parse("1/2/2003 04:05pm")) }
|
46
|
+
its(:foo_date_part) { should == "1/2/2003" }
|
47
|
+
its(:foo_time_part) { should == "4:05 pm" }
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "setting a valid date and time" do
|
51
|
+
let(:foo_date_part) { "01/02/2000" }
|
52
|
+
let(:foo_time_part) { "9:30 pm EST" }
|
53
|
+
|
54
|
+
it "doesn't raise an exception" do
|
55
|
+
expect { subject }.not_to raise_exception
|
56
|
+
end
|
57
|
+
|
58
|
+
it "sets the attribute to a DateTime object" do
|
59
|
+
subject.foo.should == Time.zone.parse("1/2/2000 9:30 pm")
|
60
|
+
end
|
61
|
+
|
62
|
+
it "has the original date input" do
|
63
|
+
subject.foo_date_part.should == "01/02/2000"
|
64
|
+
end
|
65
|
+
|
66
|
+
it "has the original time input" do
|
67
|
+
subject.foo_time_part.should == "9:30 pm EST"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "setting an invalid date" do
|
72
|
+
let(:foo_date_part) { "bad input" }
|
73
|
+
let(:foo_time_part) { "9:30 pm" }
|
74
|
+
|
75
|
+
it "doesn't raise an exception" do
|
76
|
+
expect { subject }.not_to raise_exception
|
77
|
+
end
|
78
|
+
|
79
|
+
it "sets the attribute to :incomplete" do
|
80
|
+
subject.foo.should == :incomplete
|
81
|
+
end
|
82
|
+
|
83
|
+
it "has the original date" do
|
84
|
+
subject.foo_date_part.should == "bad input"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has the original time input" do
|
88
|
+
subject.foo_time_part.should == "9:30 pm"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "setting a impossible date" do
|
93
|
+
let(:foo_date_part) { "99/99/9999" }
|
94
|
+
let(:foo_time_part) { "12:30 pm" }
|
95
|
+
|
96
|
+
it "doesn't raise an exception" do
|
97
|
+
expect { subject }.not_to raise_exception
|
98
|
+
end
|
99
|
+
|
100
|
+
it "sets the attribute to :incomplete" do
|
101
|
+
subject.foo.should == :incomplete
|
102
|
+
end
|
103
|
+
|
104
|
+
it "has the original date" do
|
105
|
+
subject.foo_date_part.should == "99/99/9999"
|
106
|
+
end
|
107
|
+
|
108
|
+
it "has the original time" do
|
109
|
+
subject.foo_time_part.should == "12:30 pm"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe "setting an invalid time" do
|
114
|
+
let(:foo_date_part) { "01/02/2000" }
|
115
|
+
let(:foo_time_part) { "bad input" }
|
116
|
+
|
117
|
+
it "doesn't raise an exception" do
|
118
|
+
expect { subject }.not_to raise_exception
|
119
|
+
end
|
120
|
+
|
121
|
+
it "sets the attribute to :incomplete" do
|
122
|
+
subject.foo.should == :incomplete
|
123
|
+
end
|
124
|
+
|
125
|
+
it "has the original date input" do
|
126
|
+
subject.foo_date_part.should == "01/02/2000"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "has the original time input" do
|
130
|
+
subject.foo_time_part.should == "bad input"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
describe "setting a impossible time" do
|
135
|
+
let(:foo_date_part) { "01/02/2000" }
|
136
|
+
let(:foo_time_part) { "99:99pm" }
|
137
|
+
|
138
|
+
it "doesn't raise an exception" do
|
139
|
+
expect { subject }.not_to raise_exception
|
140
|
+
end
|
141
|
+
|
142
|
+
it "sets the attribute to :incomplete" do
|
143
|
+
subject.foo.should == :incomplete
|
144
|
+
end
|
145
|
+
|
146
|
+
it "has the original date input" do
|
147
|
+
subject.foo_date_part.should == "01/02/2000"
|
148
|
+
end
|
149
|
+
|
150
|
+
it "has the original time input" do
|
151
|
+
subject.foo_time_part.should == "99:99pm"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "setting a date but not a time" do
|
156
|
+
let(:record) { model.new(foo_date_part: "01/01/2000") }
|
157
|
+
|
158
|
+
it "doesn't raise an exception" do
|
159
|
+
expect { subject }.not_to raise_exception
|
160
|
+
end
|
161
|
+
|
162
|
+
it "sets the attribute to :incomplete" do
|
163
|
+
subject.foo.should == :incomplete
|
164
|
+
end
|
165
|
+
|
166
|
+
it "has the original date" do
|
167
|
+
subject.foo_date_part.should == "01/01/2000"
|
168
|
+
end
|
169
|
+
|
170
|
+
it "has the nil for the time input" do
|
171
|
+
subject.foo_time_part.should == nil
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
describe "setting a time but not a date" do
|
176
|
+
let(:record) { model.new(foo_time_part: "12:30 pm") }
|
177
|
+
|
178
|
+
it "doesn't raise an exception" do
|
179
|
+
expect { subject }.not_to raise_exception
|
180
|
+
end
|
181
|
+
|
182
|
+
it "sets the attribute to :incomplete" do
|
183
|
+
subject.foo.should == :incomplete
|
184
|
+
end
|
185
|
+
|
186
|
+
it "has the nil for the date input" do
|
187
|
+
subject.foo_date_part.should == nil
|
188
|
+
end
|
189
|
+
|
190
|
+
it "has the original time" do
|
191
|
+
subject.foo_time_part.should == "12:30 pm"
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "setting incorrect time and date" do
|
196
|
+
let(:record) { model.new(foo_time_part: "qwer",
|
197
|
+
foo_date_part: "asdf") }
|
198
|
+
|
199
|
+
it "doesn't raise an exception" do
|
200
|
+
expect { subject }.not_to raise_exception
|
201
|
+
end
|
202
|
+
|
203
|
+
it "sets the attribute to :incomplete" do
|
204
|
+
subject.foo.should == :incomplete
|
205
|
+
end
|
206
|
+
|
207
|
+
it "has the original date" do
|
208
|
+
subject.foo_date_part.should == 'asdf'
|
209
|
+
end
|
210
|
+
|
211
|
+
it "has the original time input" do
|
212
|
+
subject.foo_time_part.should == "qwer"
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
describe "setting neither time nor a date" do
|
217
|
+
let(:record) { model.new(foo_time_part: "",
|
218
|
+
foo_date_part: "") }
|
219
|
+
|
220
|
+
it "doesn't raise an exception" do
|
221
|
+
expect { subject }.not_to raise_exception
|
222
|
+
end
|
223
|
+
|
224
|
+
it "has nil for the attribute" do
|
225
|
+
subject.foo.should == nil
|
226
|
+
end
|
227
|
+
|
228
|
+
it "has the original date" do
|
229
|
+
subject.foo_date_part.should == ""
|
230
|
+
end
|
231
|
+
|
232
|
+
it "has the original time input" do
|
233
|
+
subject.foo_time_part.should == ""
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "setting a DateTime directly" do
|
238
|
+
let(:record) { model.new(foo: Time.zone.parse("#{foo_date_part} #{foo_time_part}")) }
|
239
|
+
|
240
|
+
let(:foo_date_part) { "01/02/2000" }
|
241
|
+
let(:foo_time_part) { "12:30 pm" }
|
242
|
+
|
243
|
+
it "doesn't raise an exception" do
|
244
|
+
expect { subject }.not_to raise_exception
|
245
|
+
end
|
246
|
+
|
247
|
+
it "sets the attribute to a DateTime object" do
|
248
|
+
subject.foo.should == Time.zone.parse("01/02/2000 12:30 pm")
|
249
|
+
end
|
250
|
+
|
251
|
+
it "has the original date" do
|
252
|
+
subject.foo_date_part.should == "1/2/2000"
|
253
|
+
end
|
254
|
+
|
255
|
+
it "has the original time input" do
|
256
|
+
subject.foo_time_part.should == "12:30 pm"
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe "setting a String directly" do
|
261
|
+
context "When the string contains a date and time" do
|
262
|
+
let(:record) { model.new(foo: "#{foo_date_part} #{foo_time_part}") }
|
263
|
+
|
264
|
+
let(:foo_date_part) { "01/01/2000" }
|
265
|
+
let(:foo_time_part) { "12:30 pm" }
|
266
|
+
|
267
|
+
it "doesn't raise an exception" do
|
268
|
+
expect { subject }.not_to raise_exception
|
269
|
+
end
|
270
|
+
|
271
|
+
it "sets the attribute to a DateTime object" do
|
272
|
+
subject.foo.should == Time.zone.parse("01/01/2000 12:30pm")
|
273
|
+
end
|
274
|
+
|
275
|
+
it "has the original date" do
|
276
|
+
subject.foo_date_part.should == "01/01/2000"
|
277
|
+
end
|
278
|
+
|
279
|
+
it "has the original time" do
|
280
|
+
subject.foo_time_part.should == "12:30 pm"
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
context "When the string contains an iso8601 datetime" do
|
285
|
+
let(:record) { model.new(foo: "2011-12-03T01:00:00Z") }
|
286
|
+
it "doesn't raise an exception" do
|
287
|
+
expect { subject }.not_to raise_exception
|
288
|
+
end
|
289
|
+
|
290
|
+
it "sets the attribute to a DateTime object with the correct EST time" do
|
291
|
+
subject.foo.should == Time.zone.parse("12/2/2011 8:00 pm")
|
292
|
+
end
|
293
|
+
|
294
|
+
it "has a date" do
|
295
|
+
subject.foo_date_part.should == "12/2/2011"
|
296
|
+
end
|
297
|
+
|
298
|
+
it "has a time" do
|
299
|
+
subject.foo_time_part.should == "8:00 pm"
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
context "When the string contains only a date" do
|
304
|
+
let(:record) { model.new(foo: "#{foo_date_part}") }
|
305
|
+
|
306
|
+
let(:foo_date_part) { "01/01/2000" }
|
307
|
+
|
308
|
+
it "doesn't raise an exception" do
|
309
|
+
expect { subject }.not_to raise_exception
|
310
|
+
end
|
311
|
+
|
312
|
+
it "sets the attribute to a DateTime object" do
|
313
|
+
subject.foo.should == Time.zone.parse("01/01/2000 12:00am")
|
314
|
+
end
|
315
|
+
|
316
|
+
it "has the original date" do
|
317
|
+
subject.foo_date_part.should == "1/1/2000"
|
318
|
+
end
|
319
|
+
|
320
|
+
it "has midnight for the time input" do
|
321
|
+
subject.foo_time_part.should == "12:00 am"
|
322
|
+
end
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
describe "setting a Date directly" do
|
327
|
+
let(:record) { model.new(foo: Date.parse(foo_date_part)) }
|
328
|
+
|
329
|
+
let(:foo_date_part) { "01/01/2000" }
|
330
|
+
|
331
|
+
it "doesn't raise an exception" do
|
332
|
+
expect { subject }.not_to raise_exception
|
333
|
+
end
|
334
|
+
|
335
|
+
it "sets the attribute to a DateTime object in the current time zone" do
|
336
|
+
subject.foo.should == Time.zone.parse("01/01/2000 12:00 am")
|
337
|
+
end
|
338
|
+
|
339
|
+
it "has the original date" do
|
340
|
+
subject.foo_date_part.should == "1/1/2000"
|
341
|
+
end
|
342
|
+
|
343
|
+
it "has midnight for the time input" do
|
344
|
+
subject.foo_time_part.should == "12:00 am"
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
end
|
350
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require "active_record"
|
2
|
+
require "with_model"
|
3
|
+
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.extend WithModel
|
6
|
+
end
|
7
|
+
|
8
|
+
jruby = RUBY_PLATFORM =~ /\bjava\b/
|
9
|
+
adapter = jruby ? "jdbcsqlite3" : "sqlite3"
|
10
|
+
|
11
|
+
# MultiparameterDateTime requires ActiveRecord::Base.connection to be established.
|
12
|
+
# If ActiveRecord already has a connection, as in a Rails app, this is unnecessary.
|
13
|
+
ActiveRecord::Base.establish_connection(:adapter => adapter, :database => ":memory:")
|
14
|
+
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: multiparameter_date_time
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Case Commons, LLC
|
9
|
+
- Grant Hutchins
|
10
|
+
- Trace Wax
|
11
|
+
autorequire:
|
12
|
+
bindir: bin
|
13
|
+
cert_chain: []
|
14
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
15
|
+
dependencies:
|
16
|
+
- !ruby/object:Gem::Dependency
|
17
|
+
name: american_date
|
18
|
+
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ! '>='
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '0'
|
24
|
+
type: :runtime
|
25
|
+
prerelease: false
|
26
|
+
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
28
|
+
requirements:
|
29
|
+
- - ! '>='
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '0'
|
32
|
+
- !ruby/object:Gem::Dependency
|
33
|
+
name: activerecord
|
34
|
+
requirement: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: activesupport
|
50
|
+
requirement: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: rspec
|
66
|
+
requirement: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ~>
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '2.11'
|
72
|
+
type: :development
|
73
|
+
prerelease: false
|
74
|
+
version_requirements: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ~>
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '2.11'
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: with_model
|
82
|
+
requirement: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ~>
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0.3'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
none: false
|
92
|
+
requirements:
|
93
|
+
- - ~>
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.3'
|
96
|
+
- !ruby/object:Gem::Dependency
|
97
|
+
name: informal
|
98
|
+
requirement: !ruby/object:Gem::Requirement
|
99
|
+
none: false
|
100
|
+
requirements:
|
101
|
+
- - ~>
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.0.3
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 0.0.3
|
112
|
+
description:
|
113
|
+
email:
|
114
|
+
- casecommons-dev@googlegroups.com
|
115
|
+
- gems@nertzy.com
|
116
|
+
- gems@tracedwax.com
|
117
|
+
executables: []
|
118
|
+
extensions: []
|
119
|
+
extra_rdoc_files: []
|
120
|
+
files:
|
121
|
+
- .gitignore
|
122
|
+
- Gemfile
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- lib/multiparameter_date_time.rb
|
127
|
+
- lib/multiparameter_date_time/version.rb
|
128
|
+
- multiparameter_date_time.gemspec
|
129
|
+
- spec/multiparameter_date_time_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
131
|
+
homepage: https://github.com/Casecommons/multiparameter_date_time
|
132
|
+
licenses: []
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
segments:
|
144
|
+
- 0
|
145
|
+
hash: -1009483105681798666
|
146
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
+
none: false
|
148
|
+
requirements:
|
149
|
+
- - ! '>='
|
150
|
+
- !ruby/object:Gem::Version
|
151
|
+
version: '0'
|
152
|
+
segments:
|
153
|
+
- 0
|
154
|
+
hash: -1009483105681798666
|
155
|
+
requirements: []
|
156
|
+
rubyforge_project:
|
157
|
+
rubygems_version: 1.8.24
|
158
|
+
signing_key:
|
159
|
+
specification_version: 3
|
160
|
+
summary: Set a DateTime via two accessors, one for the date, one for the time
|
161
|
+
test_files:
|
162
|
+
- spec/multiparameter_date_time_spec.rb
|
163
|
+
- spec/spec_helper.rb
|