multiparameter_date_time 0.3.5 → 0.3.6
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 +4 -3
- data/README.md +2 -2
- data/lib/is_valid_multiparameter_date_time_validator.rb +1 -0
- data/lib/multiparameter_date_time.rb +1 -0
- data/lib/multiparameter_date_time/version.rb +1 -1
- data/spec/is_valid_multiparameter_date_time_validator_spec.rb +109 -91
- data/spec/multiparameter_date_time_spec.rb +148 -127
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7dbe4e334a2cdfcaffabfc6e283e801b6ec7a2c4
|
4
|
+
data.tar.gz: f1dc19849afde4d9ca07c7e8c0d11bbcb82a5ebd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4246599e275e0200c000547dcbeffa5fa0be0731aaaba88c424311d80b63e0cbe4994cb41825cf49e0845a8393171571fe119fc3220cd7de77495bc64afafb4c
|
7
|
+
data.tar.gz: e0c95dcb0ddcfb50a5ef77b57fc108e15413720194dd191552fd8630a30cdf509605b3e997678bcb18cf9eb47dd9ab898d5c946e70c2e10b8b056ea44e074c6a
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -21,7 +21,7 @@ Or install it yourself as:
|
|
21
21
|
|
22
22
|
$ gem install multiparameter_date_time
|
23
23
|
|
24
|
-
Note that Ruby
|
24
|
+
Note that Ruby 2.x is required.
|
25
25
|
|
26
26
|
## Usage
|
27
27
|
|
@@ -108,4 +108,4 @@ en:
|
|
108
108
|
|
109
109
|
## License
|
110
110
|
|
111
|
-
Copyright © 2012–
|
111
|
+
Copyright © 2012–2016 Case Commons, LLC. License is available in the LICENSE file.
|
@@ -20,6 +20,7 @@ class IsValidMultiparameterDateTimeValidator < ActiveModel::EachValidator
|
|
20
20
|
else
|
21
21
|
attribute_value = record.public_send(:"#{attribute}_time_part")
|
22
22
|
begin
|
23
|
+
Date.parse(date_value)
|
23
24
|
Time.zone.parse("#{date_value} #{time_value}")
|
24
25
|
Time.zone.parse(attribute_value)
|
25
26
|
rescue ArgumentError
|
@@ -117,6 +117,7 @@ module MultiparameterDateTime
|
|
117
117
|
formatted_date_string = MultiparameterDateTime.date_string_formatter.format(date_string)
|
118
118
|
end
|
119
119
|
|
120
|
+
Date.parse(formatted_date_string)
|
120
121
|
write_attribute_for_multiparameter_date_time(
|
121
122
|
name, Time.zone.parse("#{formatted_date_string} #{time_string}")
|
122
123
|
)
|
@@ -5,7 +5,7 @@ require 'is_valid_multiparameter_date_time_validator'
|
|
5
5
|
|
6
6
|
describe IsValidMultiparameterDateTimeValidator do
|
7
7
|
before do
|
8
|
-
Time.zone =
|
8
|
+
Time.zone = 'US/Eastern'
|
9
9
|
end
|
10
10
|
|
11
11
|
with_model :ModelWithDatetime do
|
@@ -20,21 +20,21 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
|
-
shared_examples_for
|
24
|
-
it
|
23
|
+
shared_examples_for 'a valid time' do
|
24
|
+
it 'does not have an error' do
|
25
25
|
record.valid?
|
26
|
-
record.errors[:foo].
|
26
|
+
expect(record.errors[:foo]).to be_empty
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
shared_examples_for
|
31
|
-
it
|
30
|
+
shared_examples_for 'a badly formatted date or time' do
|
31
|
+
it 'shows the bad format error' do
|
32
32
|
record.valid?
|
33
|
-
record.errors[:foo].
|
33
|
+
expect(record.errors[:foo]).to eq [bad_format_error]
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
-
describe
|
37
|
+
describe '#validate_each' do
|
38
38
|
subject { record }
|
39
39
|
let(:record) do
|
40
40
|
ModelWithDatetime.new(
|
@@ -49,75 +49,75 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
49
49
|
let(:missing_time_error) { 'Please enter a time.' }
|
50
50
|
let(:missing_date_error) { 'Please enter a date.' }
|
51
51
|
|
52
|
-
context
|
52
|
+
context 'with valid date' do
|
53
53
|
let(:date_string) { '01/01/2001' }
|
54
54
|
|
55
|
-
context
|
56
|
-
context
|
57
|
-
context
|
55
|
+
context 'with valid time in' do
|
56
|
+
context 'military format' do
|
57
|
+
context 'lots of zeros' do
|
58
58
|
let(:time_string) { '00:00' }
|
59
|
-
it_should_behave_like
|
59
|
+
it_should_behave_like 'a valid time'
|
60
60
|
end
|
61
61
|
|
62
|
-
context
|
62
|
+
context 'last valid value' do
|
63
63
|
let(:time_string) { '23:59' }
|
64
|
-
it_should_behave_like
|
64
|
+
it_should_behave_like 'a valid time'
|
65
65
|
end
|
66
66
|
|
67
|
-
context
|
67
|
+
context '1 pm' do
|
68
68
|
let(:time_string) { '13:00' }
|
69
|
-
it_should_behave_like
|
69
|
+
it_should_behave_like 'a valid time'
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
context
|
73
|
+
context 'standard format' do
|
74
74
|
let(:time_string) { '12:31pm' }
|
75
|
-
it_should_behave_like
|
75
|
+
it_should_behave_like 'a valid time'
|
76
76
|
|
77
|
-
context
|
77
|
+
context 'with a capital AM or PM' do
|
78
78
|
let(:time_string) { '12:31 PM' }
|
79
|
-
it_should_behave_like
|
79
|
+
it_should_behave_like 'a valid time'
|
80
80
|
end
|
81
81
|
|
82
|
-
context
|
82
|
+
context 'without a space between the time and AM or PM' do
|
83
83
|
let(:time_string) { '12:31AM' }
|
84
|
-
it_should_behave_like
|
84
|
+
it_should_behave_like 'a valid time'
|
85
85
|
end
|
86
86
|
|
87
|
-
context
|
87
|
+
context 'with no space and a mixed case aM or pM' do
|
88
88
|
let(:time_string) { '12:31aM' }
|
89
|
-
it_should_behave_like
|
89
|
+
it_should_behave_like 'a valid time'
|
90
90
|
end
|
91
91
|
|
92
|
-
context
|
92
|
+
context 'with a space and a mixed case aM or pM' do
|
93
93
|
let(:time_string) { '12:31 aM' }
|
94
|
-
it_should_behave_like
|
94
|
+
it_should_behave_like 'a valid time'
|
95
95
|
end
|
96
96
|
|
97
|
-
context
|
97
|
+
context 'with a space and a lower case am or pm' do
|
98
98
|
let(:time_string) { '12:31 am' }
|
99
|
-
it_should_behave_like
|
99
|
+
it_should_behave_like 'a valid time'
|
100
100
|
end
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
104
|
-
context
|
105
|
-
context
|
106
|
-
context
|
104
|
+
context 'with invalid time in' do
|
105
|
+
context 'military format' do
|
106
|
+
context 'above 23:59' do
|
107
107
|
let(:time_string) { '25:00' }
|
108
|
-
it_should_behave_like
|
108
|
+
it_should_behave_like 'a badly formatted date or time'
|
109
109
|
end
|
110
110
|
|
111
|
-
context
|
111
|
+
context 'with am or pm' do
|
112
112
|
let(:time_string) { '23:00 am' }
|
113
|
-
it_should_behave_like
|
113
|
+
it_should_behave_like 'a badly formatted date or time'
|
114
114
|
end
|
115
115
|
end
|
116
116
|
|
117
|
-
context
|
117
|
+
context 'standard format' do
|
118
118
|
let(:time_string) { '90:00pm' }
|
119
119
|
|
120
|
-
it_should_behave_like
|
120
|
+
it_should_behave_like 'a badly formatted date or time'
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
@@ -158,56 +158,56 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
context
|
161
|
+
context 'with invalid date' do
|
162
162
|
let(:date_string) { 'asdf' }
|
163
163
|
|
164
|
-
context
|
164
|
+
context 'with valid time' do
|
165
165
|
let(:time_string) { '12:31pm' }
|
166
166
|
|
167
|
-
it_should_behave_like
|
167
|
+
it_should_behave_like 'a badly formatted date or time'
|
168
168
|
end
|
169
169
|
|
170
|
-
context
|
170
|
+
context 'with invalid time' do
|
171
171
|
let(:time_string) { 'asdf' }
|
172
172
|
|
173
|
-
it_should_behave_like
|
173
|
+
it_should_behave_like 'a badly formatted date or time'
|
174
174
|
end
|
175
175
|
|
176
176
|
[' ', nil].each do |time_value|
|
177
177
|
context "with time = #{time_value.inspect}" do
|
178
178
|
let(:time_string) { time_value }
|
179
|
-
it_should_behave_like
|
179
|
+
it_should_behave_like 'a badly formatted date or time'
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
183
183
|
|
184
|
-
context
|
185
|
-
context
|
184
|
+
context 'with a date that has invalid format' do
|
185
|
+
context 'with year has 5 digits' do
|
186
186
|
let(:date_string) { '1/1/12012' }
|
187
187
|
let(:time_string) { '12:31pm' }
|
188
188
|
|
189
|
-
it_should_behave_like
|
189
|
+
it_should_behave_like 'a badly formatted date or time'
|
190
190
|
end
|
191
191
|
|
192
|
-
context
|
192
|
+
context 'with year has 1 digit' do
|
193
193
|
let(:date_string) { '1/1/2' }
|
194
194
|
let(:time_string) { '12:31pm' }
|
195
195
|
|
196
|
-
it_should_behave_like
|
196
|
+
it_should_behave_like 'a badly formatted date or time'
|
197
197
|
end
|
198
198
|
|
199
|
-
context
|
199
|
+
context 'with month has 3 digits' do
|
200
200
|
let(:date_string) { '100/1/2012' }
|
201
201
|
let(:time_string) { '12:31pm' }
|
202
202
|
|
203
|
-
it_should_behave_like
|
203
|
+
it_should_behave_like 'a badly formatted date or time'
|
204
204
|
end
|
205
205
|
|
206
|
-
context
|
206
|
+
context 'with day has 3 digits' do
|
207
207
|
let(:date_string) { '10/100/2012' }
|
208
208
|
let(:time_string) { '12:31pm' }
|
209
209
|
|
210
|
-
it_should_behave_like
|
210
|
+
it_should_behave_like 'a badly formatted date or time'
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
@@ -215,19 +215,19 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
215
215
|
context "with date = #{date_value.inspect}" do
|
216
216
|
let(:date_string) { date_value }
|
217
217
|
|
218
|
-
context
|
218
|
+
context 'with valid time' do
|
219
219
|
let(:time_string) { '12:31pm' }
|
220
220
|
|
221
|
-
it
|
221
|
+
it 'should show the missing date error' do
|
222
222
|
record.valid?
|
223
|
-
record.errors[:foo].
|
223
|
+
expect(record.errors[:foo]).to eq [missing_date_error]
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
|
-
context
|
227
|
+
context 'with invalid time' do
|
228
228
|
let(:time_string) { 'asdf' }
|
229
229
|
|
230
|
-
it_should_behave_like
|
230
|
+
it_should_behave_like 'a badly formatted date or time'
|
231
231
|
end
|
232
232
|
|
233
233
|
[' ', nil].each do |time_value|
|
@@ -235,7 +235,7 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
235
235
|
let(:time_string) { time_value }
|
236
236
|
it 'should not have an error' do
|
237
237
|
record.valid?
|
238
|
-
record.errors[:foo].
|
238
|
+
expect(record.errors[:foo]).to be_empty
|
239
239
|
end
|
240
240
|
end
|
241
241
|
end
|
@@ -243,7 +243,7 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
243
243
|
end
|
244
244
|
|
245
245
|
[' ', nil].each do |date_value|
|
246
|
-
context
|
246
|
+
context 'with valid time' do
|
247
247
|
let(:date_string) { date_value }
|
248
248
|
let(:time_string) { '12:31pm' }
|
249
249
|
|
@@ -260,86 +260,104 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
260
260
|
end
|
261
261
|
|
262
262
|
context 'and I18n error messages' do
|
263
|
-
it
|
263
|
+
it 'should show the missing date error' do
|
264
264
|
record.valid?
|
265
|
-
record.errors[:foo].
|
265
|
+
expect(record.errors[:foo]).to eq ['custom error']
|
266
266
|
end
|
267
267
|
end
|
268
268
|
end
|
269
269
|
end
|
270
270
|
|
271
|
-
context
|
271
|
+
context 'when the datetime is set directly' do
|
272
272
|
let(:record) { ModelWithDatetime.new(foo: Time.current) }
|
273
|
-
it
|
273
|
+
it 'should not have an error' do
|
274
274
|
record.valid?
|
275
|
-
record.errors[:foo].
|
275
|
+
expect(record.errors[:foo]).to be_empty
|
276
276
|
end
|
277
277
|
end
|
278
278
|
|
279
|
-
context
|
279
|
+
context 'when the datetime is set directly to nil' do
|
280
280
|
let(:record) { ModelWithDatetime.new(foo: nil) }
|
281
|
-
it
|
281
|
+
it 'should not have an error' do
|
282
282
|
record.valid?
|
283
|
-
record.errors[:foo].
|
283
|
+
expect(record.errors[:foo]).to be_empty
|
284
284
|
end
|
285
285
|
end
|
286
286
|
|
287
|
-
context
|
287
|
+
context 'when nothing is set at all' do
|
288
288
|
let(:record) { ModelWithDatetime.new }
|
289
|
-
it
|
289
|
+
it 'should not have an error' do
|
290
290
|
record.valid?
|
291
|
-
record.errors[:foo].
|
291
|
+
expect(record.errors[:foo]).to be_empty
|
292
292
|
end
|
293
293
|
end
|
294
294
|
|
295
|
-
context
|
296
|
-
context
|
295
|
+
context 'with an impossible date' do
|
296
|
+
context 'set in parts' do
|
297
297
|
let(:record) do
|
298
298
|
ModelWithDatetime.new(foo_date_part: '19/19/1919', foo_time_part: '04:50pm')
|
299
299
|
end
|
300
300
|
|
301
|
-
it_should_behave_like
|
301
|
+
it_should_behave_like 'a badly formatted date or time'
|
302
302
|
end
|
303
303
|
|
304
|
-
context
|
304
|
+
context 'set directly' do
|
305
305
|
let(:record) do
|
306
306
|
ModelWithDatetime.new(foo: '19/19/1919 04:50pm')
|
307
307
|
end
|
308
308
|
|
309
|
-
it_should_behave_like
|
309
|
+
it_should_behave_like 'a badly formatted date or time'
|
310
|
+
end
|
311
|
+
|
312
|
+
context 'having a valid month but invalid day for that month' do
|
313
|
+
context 'set in parts' do
|
314
|
+
let(:record) do
|
315
|
+
ModelWithDatetime.new(foo_date_part: '2/31/2015', foo_time_part: '04:50pm')
|
316
|
+
end
|
317
|
+
|
318
|
+
it_should_behave_like 'a badly formatted date or time'
|
319
|
+
end
|
320
|
+
|
321
|
+
context 'set directly' do
|
322
|
+
let(:record) do
|
323
|
+
ModelWithDatetime.new(foo: '2/31/2015 04:50pm')
|
324
|
+
end
|
325
|
+
|
326
|
+
it_should_behave_like 'a badly formatted date or time'
|
327
|
+
end
|
310
328
|
end
|
311
329
|
end
|
312
330
|
|
313
|
-
context
|
314
|
-
context
|
331
|
+
context 'with an impossible time' do
|
332
|
+
context 'set in parts' do
|
315
333
|
let(:record) do
|
316
334
|
ModelWithDatetime.new(foo_date_part: '01/01/2001', foo_time_part: '09:99pm')
|
317
335
|
end
|
318
336
|
|
319
|
-
it_should_behave_like
|
337
|
+
it_should_behave_like 'a badly formatted date or time'
|
320
338
|
end
|
321
339
|
|
322
|
-
context
|
340
|
+
context 'set directly' do
|
323
341
|
let(:record) do
|
324
342
|
ModelWithDatetime.new(foo: '01/01/2001 09:99pm')
|
325
343
|
end
|
326
344
|
|
327
|
-
it_should_behave_like
|
345
|
+
it_should_behave_like 'a badly formatted date or time'
|
328
346
|
end
|
329
347
|
end
|
330
348
|
|
331
|
-
context
|
349
|
+
context 'when the display format has been configured' do
|
332
350
|
let(:date_string) { 'asdf' }
|
333
351
|
let(:time_string) { 'foo' }
|
334
352
|
|
335
|
-
context
|
353
|
+
context 'when the date format is set' do
|
336
354
|
before do
|
337
355
|
MultiparameterDateTime.date_format = '%-m-%-e-%0y'
|
338
356
|
end
|
339
357
|
|
340
|
-
it
|
358
|
+
it 'shows the bad format error' do
|
341
359
|
record.valid?
|
342
|
-
record.errors[:foo].
|
360
|
+
expect(record.errors[:foo]).to eq [
|
343
361
|
'Please enter a valid date and time using the following formats: 1-29-00, 5:15 pm'
|
344
362
|
]
|
345
363
|
end
|
@@ -349,16 +367,16 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
349
367
|
end
|
350
368
|
end
|
351
369
|
|
352
|
-
context
|
370
|
+
context 'when the time format is set' do
|
353
371
|
let(:time_string) { 'asdf' }
|
354
372
|
|
355
373
|
before do
|
356
374
|
MultiparameterDateTime.time_format = '%H%M hours'
|
357
375
|
end
|
358
376
|
|
359
|
-
it
|
377
|
+
it 'shows the bad format error' do
|
360
378
|
record.valid?
|
361
|
-
record.errors[:foo].
|
379
|
+
expect(record.errors[:foo]).to eq [
|
362
380
|
'Please enter a valid date and time using the following formats: 1/29/2000, 1715 hours'
|
363
381
|
]
|
364
382
|
end
|
@@ -370,7 +388,7 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
370
388
|
end
|
371
389
|
end
|
372
390
|
|
373
|
-
describe
|
391
|
+
describe 'accepts dates in a variety of formats' do
|
374
392
|
['2010-1-1', '02-01-1971', '4/4/92', '01/02/2001', '01/02/2001', '01.02.2011'].each do |format|
|
375
393
|
context format do
|
376
394
|
let(:date_string) { format }
|
@@ -379,14 +397,14 @@ describe IsValidMultiparameterDateTimeValidator do
|
|
379
397
|
ModelWithDatetime.new(foo_date_part: date_string, foo_time_part: time_string)
|
380
398
|
end
|
381
399
|
|
382
|
-
it
|
383
|
-
record.
|
400
|
+
it 'is accepted' do
|
401
|
+
expect(record).to be_valid
|
384
402
|
end
|
385
403
|
end
|
386
404
|
end
|
387
405
|
end
|
388
406
|
|
389
|
-
describe
|
407
|
+
describe '.invalid_format_error_message' do
|
390
408
|
it do
|
391
409
|
expected_error = 'Please enter a valid date and time using the following formats: 1/29/2000, 5:15 pm'
|
392
410
|
expect(described_class.invalid_format_error_message).to eq expected_error
|
@@ -40,7 +40,7 @@ describe MultiparameterDateTime do
|
|
40
40
|
|
41
41
|
subject { record }
|
42
42
|
|
43
|
-
describe
|
43
|
+
describe 'when a value is present' do
|
44
44
|
let(:record) { model.new(foo: Time.zone.parse('1/2/2003 04:05pm')) }
|
45
45
|
it 'assigns date_part' do
|
46
46
|
expect(subject.foo_date_part).to eq '1/2/2003'
|
@@ -51,304 +51,325 @@ describe MultiparameterDateTime do
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
describe
|
54
|
+
describe 'setting a valid date and time' do
|
55
55
|
let(:foo_date_part) { '01/02/2000' }
|
56
56
|
let(:foo_time_part) { '9:30 pm EST' }
|
57
57
|
|
58
|
-
it
|
58
|
+
it 'does not raise an exception' do
|
59
59
|
expect { subject }.not_to raise_exception
|
60
60
|
end
|
61
61
|
|
62
|
-
it
|
63
|
-
subject.foo.
|
62
|
+
it 'sets the attribute to a DateTime object' do
|
63
|
+
expect(subject.foo).to eq Time.zone.parse('1/2/2000 9:30 pm')
|
64
64
|
end
|
65
65
|
|
66
|
-
it
|
67
|
-
subject.foo_date_part.
|
66
|
+
it 'has the original date input' do
|
67
|
+
expect(subject.foo_date_part).to eq '01/02/2000'
|
68
68
|
end
|
69
69
|
|
70
|
-
it
|
71
|
-
subject.foo_time_part.
|
70
|
+
it 'has the original time input' do
|
71
|
+
expect(subject.foo_time_part).to eq '9:30 pm EST'
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
describe
|
75
|
+
describe 'setting an invalid date' do
|
76
76
|
let(:foo_date_part) { 'bad input' }
|
77
77
|
let(:foo_time_part) { '9:30 pm' }
|
78
78
|
|
79
|
-
it
|
79
|
+
it 'does not raise an exception' do
|
80
80
|
expect { subject }.not_to raise_exception
|
81
81
|
end
|
82
82
|
|
83
|
-
it
|
84
|
-
subject.foo.
|
83
|
+
it 'sets the attribute to :incomplete' do
|
84
|
+
expect(subject.foo).to eq :incomplete
|
85
85
|
end
|
86
86
|
|
87
|
-
it
|
88
|
-
subject.foo_date_part.
|
87
|
+
it 'has the original date' do
|
88
|
+
expect(subject.foo_date_part).to eq 'bad input'
|
89
89
|
end
|
90
90
|
|
91
|
-
it
|
92
|
-
subject.foo_time_part.
|
91
|
+
it 'has the original time input' do
|
92
|
+
expect(subject.foo_time_part).to eq '9:30 pm'
|
93
|
+
end
|
94
|
+
|
95
|
+
context 'valid month but invalid day for the month' do
|
96
|
+
let(:foo_date_part) { '2/31/2015' }
|
97
|
+
let(:foo_time_part) { '9:30 pm' }
|
98
|
+
|
99
|
+
it 'does not raise an exception' do
|
100
|
+
expect { subject }.not_to raise_exception
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'sets the attribute to :incomplete' do
|
104
|
+
expect(subject.foo).to eq :incomplete
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'has the original date' do
|
108
|
+
expect(subject.foo_date_part).to eq '2/31/2015'
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'has the original time input' do
|
112
|
+
expect(subject.foo_time_part).to eq '9:30 pm'
|
113
|
+
end
|
93
114
|
end
|
94
115
|
end
|
95
116
|
|
96
|
-
describe
|
117
|
+
describe 'setting an impossible date' do
|
97
118
|
let(:foo_date_part) { '99/99/9999' }
|
98
119
|
let(:foo_time_part) { '12:30 pm' }
|
99
120
|
|
100
|
-
it
|
121
|
+
it 'does not raise an exception' do
|
101
122
|
expect { subject }.not_to raise_exception
|
102
123
|
end
|
103
124
|
|
104
|
-
it
|
105
|
-
subject.foo.
|
125
|
+
it 'sets the attribute to :incomplete' do
|
126
|
+
expect(subject.foo).to eq :incomplete
|
106
127
|
end
|
107
128
|
|
108
|
-
it
|
109
|
-
subject.foo_date_part.
|
129
|
+
it 'has the original date' do
|
130
|
+
expect(subject.foo_date_part).to eq '99/99/9999'
|
110
131
|
end
|
111
132
|
|
112
|
-
it
|
113
|
-
subject.foo_time_part.
|
133
|
+
it 'has the original time' do
|
134
|
+
expect(subject.foo_time_part).to eq '12:30 pm'
|
114
135
|
end
|
115
136
|
end
|
116
137
|
|
117
|
-
describe
|
138
|
+
describe 'setting an invalid time' do
|
118
139
|
let(:foo_date_part) { '01/02/2000' }
|
119
140
|
let(:foo_time_part) { 'bad input' }
|
120
141
|
|
121
|
-
it
|
142
|
+
it 'does not raise an exception' do
|
122
143
|
expect { subject }.not_to raise_exception
|
123
144
|
end
|
124
145
|
|
125
|
-
it
|
126
|
-
subject.foo.
|
146
|
+
it 'sets the attribute to :incomplete' do
|
147
|
+
expect(subject.foo).to eq :incomplete
|
127
148
|
end
|
128
149
|
|
129
|
-
it
|
130
|
-
subject.foo_date_part.
|
150
|
+
it 'has the original date input' do
|
151
|
+
expect(subject.foo_date_part).to eq '01/02/2000'
|
131
152
|
end
|
132
153
|
|
133
|
-
it
|
134
|
-
subject.foo_time_part.
|
154
|
+
it 'has the original time input' do
|
155
|
+
expect(subject.foo_time_part).to eq 'bad input'
|
135
156
|
end
|
136
157
|
end
|
137
158
|
|
138
|
-
describe
|
159
|
+
describe 'setting a impossible time' do
|
139
160
|
let(:foo_date_part) { '01/02/2000' }
|
140
161
|
let(:foo_time_part) { '99:99pm' }
|
141
162
|
|
142
|
-
it
|
163
|
+
it 'does not raise an exception' do
|
143
164
|
expect { subject }.not_to raise_exception
|
144
165
|
end
|
145
166
|
|
146
|
-
it
|
147
|
-
subject.foo.
|
167
|
+
it 'sets the attribute to :incomplete' do
|
168
|
+
expect(subject.foo).to eq :incomplete
|
148
169
|
end
|
149
170
|
|
150
|
-
it
|
151
|
-
subject.foo_date_part.
|
171
|
+
it 'has the original date input' do
|
172
|
+
expect(subject.foo_date_part).to eq '01/02/2000'
|
152
173
|
end
|
153
174
|
|
154
|
-
it
|
155
|
-
subject.foo_time_part.
|
175
|
+
it 'has the original time input' do
|
176
|
+
expect(subject.foo_time_part).to eq '99:99pm'
|
156
177
|
end
|
157
178
|
end
|
158
179
|
|
159
|
-
describe
|
180
|
+
describe 'setting a date but not a time' do
|
160
181
|
let(:record) { model.new(foo_date_part: '01/01/2000') }
|
161
182
|
|
162
|
-
it
|
183
|
+
it 'does not raise an exception' do
|
163
184
|
expect { subject }.not_to raise_exception
|
164
185
|
end
|
165
186
|
|
166
|
-
it
|
167
|
-
subject.foo.
|
187
|
+
it 'sets the attribute to :incomplete' do
|
188
|
+
expect(subject.foo).to eq :incomplete
|
168
189
|
end
|
169
190
|
|
170
|
-
it
|
171
|
-
subject.foo_date_part.
|
191
|
+
it 'has the original date' do
|
192
|
+
expect(subject.foo_date_part).to eq '01/01/2000'
|
172
193
|
end
|
173
194
|
|
174
|
-
it
|
175
|
-
subject.foo_time_part.
|
195
|
+
it 'has the nil for the time input' do
|
196
|
+
expect(subject.foo_time_part).to eq nil
|
176
197
|
end
|
177
198
|
end
|
178
199
|
|
179
|
-
describe
|
200
|
+
describe 'setting a time but not a date' do
|
180
201
|
let(:record) { model.new(foo_time_part: '12:30 pm') }
|
181
202
|
|
182
|
-
it
|
203
|
+
it 'does not raise an exception' do
|
183
204
|
expect { subject }.not_to raise_exception
|
184
205
|
end
|
185
206
|
|
186
|
-
it
|
187
|
-
subject.foo.
|
207
|
+
it 'sets the attribute to :incomplete' do
|
208
|
+
expect(subject.foo).to eq :incomplete
|
188
209
|
end
|
189
210
|
|
190
|
-
it
|
191
|
-
subject.foo_date_part.
|
211
|
+
it 'has the nil for the date input' do
|
212
|
+
expect(subject.foo_date_part).to eq nil
|
192
213
|
end
|
193
214
|
|
194
|
-
it
|
195
|
-
subject.foo_time_part.
|
215
|
+
it 'has the original time' do
|
216
|
+
expect(subject.foo_time_part).to eq '12:30 pm'
|
196
217
|
end
|
197
218
|
end
|
198
219
|
|
199
|
-
describe
|
220
|
+
describe 'setting incorrect time and date' do
|
200
221
|
let(:record) { model.new(foo_time_part: 'qwer',
|
201
222
|
foo_date_part: 'asdf') }
|
202
223
|
|
203
|
-
it
|
224
|
+
it 'does not raise an exception' do
|
204
225
|
expect { subject }.not_to raise_exception
|
205
226
|
end
|
206
227
|
|
207
|
-
it
|
208
|
-
subject.foo.
|
228
|
+
it 'sets the attribute to :incomplete' do
|
229
|
+
expect(subject.foo).to eq :incomplete
|
209
230
|
end
|
210
231
|
|
211
|
-
it
|
212
|
-
subject.foo_date_part.
|
232
|
+
it 'has the original date' do
|
233
|
+
expect(subject.foo_date_part).to eq 'asdf'
|
213
234
|
end
|
214
235
|
|
215
|
-
it
|
216
|
-
subject.foo_time_part.
|
236
|
+
it 'has the original time input' do
|
237
|
+
expect(subject.foo_time_part).to eq 'qwer'
|
217
238
|
end
|
218
239
|
end
|
219
240
|
|
220
|
-
describe
|
241
|
+
describe 'setting neither time nor a date' do
|
221
242
|
let(:record) { model.new(foo_time_part: '',
|
222
243
|
foo_date_part: '') }
|
223
244
|
|
224
|
-
it
|
245
|
+
it 'does not raise an exception' do
|
225
246
|
expect { subject }.not_to raise_exception
|
226
247
|
end
|
227
248
|
|
228
|
-
it
|
229
|
-
subject.foo.
|
249
|
+
it 'has nil for the attribute' do
|
250
|
+
expect(subject.foo).to eq nil
|
230
251
|
end
|
231
252
|
|
232
|
-
it
|
233
|
-
subject.foo_date_part.
|
253
|
+
it 'has the original date' do
|
254
|
+
expect(subject.foo_date_part).to eq ''
|
234
255
|
end
|
235
256
|
|
236
|
-
it
|
237
|
-
subject.foo_time_part.
|
257
|
+
it 'has the original time input' do
|
258
|
+
expect(subject.foo_time_part).to eq ''
|
238
259
|
end
|
239
260
|
end
|
240
261
|
|
241
|
-
describe
|
262
|
+
describe 'setting a DateTime directly' do
|
242
263
|
let(:record) { model.new(foo: Time.zone.parse("#{foo_date_part} #{foo_time_part}")) }
|
243
264
|
let(:foo_date_part) { '01/02/2000' }
|
244
265
|
let(:foo_time_part) { '12:30 pm' }
|
245
266
|
|
246
|
-
it
|
267
|
+
it 'does not raise an exception' do
|
247
268
|
expect { subject }.not_to raise_exception
|
248
269
|
end
|
249
270
|
|
250
|
-
it
|
251
|
-
subject.foo.
|
271
|
+
it 'sets the attribute to a DateTime object' do
|
272
|
+
expect(subject.foo).to eq Time.zone.parse('01/02/2000 12:30 pm')
|
252
273
|
end
|
253
274
|
|
254
|
-
it
|
255
|
-
subject.foo_date_part.
|
275
|
+
it 'has the original date' do
|
276
|
+
expect(subject.foo_date_part).to eq '1/2/2000'
|
256
277
|
end
|
257
278
|
|
258
|
-
it
|
259
|
-
subject.foo_time_part.
|
279
|
+
it 'has the original time input' do
|
280
|
+
expect(subject.foo_time_part).to eq '12:30 pm'
|
260
281
|
end
|
261
282
|
end
|
262
283
|
|
263
|
-
describe
|
264
|
-
context
|
284
|
+
describe 'setting a String directly' do
|
285
|
+
context 'When the string contains a date and time' do
|
265
286
|
let(:record) { model.new(foo: "#{foo_date_part} #{foo_time_part}") }
|
266
287
|
let(:foo_date_part) { '01/01/2000' }
|
267
288
|
let(:foo_time_part) { '12:30 pm' }
|
268
289
|
|
269
|
-
it
|
290
|
+
it 'does not raise an exception' do
|
270
291
|
expect { subject }.not_to raise_exception
|
271
292
|
end
|
272
293
|
|
273
|
-
it
|
274
|
-
subject.foo.
|
294
|
+
it 'sets the attribute to a DateTime object' do
|
295
|
+
expect(subject.foo).to eq Time.zone.parse('01/01/2000 12:30pm')
|
275
296
|
end
|
276
297
|
|
277
|
-
it
|
278
|
-
subject.foo_date_part.
|
298
|
+
it 'has the original date' do
|
299
|
+
expect(subject.foo_date_part).to eq '01/01/2000'
|
279
300
|
end
|
280
301
|
|
281
|
-
it
|
282
|
-
subject.foo_time_part.
|
302
|
+
it 'has the original time' do
|
303
|
+
expect(subject.foo_time_part).to eq '12:30 pm'
|
283
304
|
end
|
284
305
|
end
|
285
306
|
|
286
|
-
context
|
307
|
+
context 'When the string contains an iso8601 datetime' do
|
287
308
|
let(:record) { model.new(foo: '2011-12-03T01:00:00Z') }
|
288
309
|
|
289
|
-
it
|
310
|
+
it 'does not raise an exception' do
|
290
311
|
expect { subject }.not_to raise_exception
|
291
312
|
end
|
292
313
|
|
293
|
-
it
|
294
|
-
subject.foo.
|
314
|
+
it 'sets the attribute to a DateTime object with the correct EST time' do
|
315
|
+
expect(subject.foo).to eq Time.zone.parse('12/2/2011 8:00 pm')
|
295
316
|
end
|
296
317
|
|
297
|
-
it
|
298
|
-
subject.foo_date_part.
|
318
|
+
it 'has a date' do
|
319
|
+
expect(subject.foo_date_part).to eq '12/2/2011'
|
299
320
|
end
|
300
321
|
|
301
|
-
it
|
302
|
-
subject.foo_time_part.
|
322
|
+
it 'has a time' do
|
323
|
+
expect(subject.foo_time_part).to eq '8:00 pm'
|
303
324
|
end
|
304
325
|
end
|
305
326
|
|
306
|
-
context
|
327
|
+
context 'When the string contains only a date' do
|
307
328
|
let(:record) { model.new(foo: "#{foo_date_part}") }
|
308
329
|
let(:foo_date_part) { '01/01/2000' }
|
309
330
|
|
310
|
-
it
|
331
|
+
it 'does not raise an exception' do
|
311
332
|
expect { subject }.not_to raise_exception
|
312
333
|
end
|
313
334
|
|
314
|
-
it
|
315
|
-
subject.foo.
|
335
|
+
it 'sets the attribute to a DateTime object' do
|
336
|
+
expect(subject.foo).to eq Time.zone.parse('01/01/2000 12:00am')
|
316
337
|
end
|
317
338
|
|
318
|
-
it
|
319
|
-
subject.foo_date_part.
|
339
|
+
it 'has the original date' do
|
340
|
+
expect(subject.foo_date_part).to eq '1/1/2000'
|
320
341
|
end
|
321
342
|
|
322
|
-
it
|
323
|
-
subject.foo_time_part.
|
343
|
+
it 'has midnight for the time input' do
|
344
|
+
expect(subject.foo_time_part).to eq '12:00 am'
|
324
345
|
end
|
325
346
|
end
|
326
347
|
end
|
327
348
|
|
328
|
-
describe
|
349
|
+
describe 'setting a Date directly' do
|
329
350
|
let(:record) { model.new(foo: Date.parse(foo_date_part)) }
|
330
351
|
|
331
352
|
let(:foo_date_part) { '01/01/2000' }
|
332
353
|
|
333
|
-
it
|
354
|
+
it 'does not raise an exception' do
|
334
355
|
expect { subject }.not_to raise_exception
|
335
356
|
end
|
336
357
|
|
337
|
-
it
|
338
|
-
subject.foo.
|
358
|
+
it 'sets the attribute to a DateTime object in the current time zone' do
|
359
|
+
expect(subject.foo).to eq Time.zone.parse('01/01/2000 12:00 am')
|
339
360
|
end
|
340
361
|
|
341
|
-
it
|
342
|
-
subject.foo_date_part.
|
362
|
+
it 'has the original date' do
|
363
|
+
expect(subject.foo_date_part).to eq '1/1/2000'
|
343
364
|
end
|
344
365
|
|
345
|
-
it
|
346
|
-
subject.foo_time_part.
|
366
|
+
it 'has midnight for the time input' do
|
367
|
+
expect(subject.foo_time_part).to eq '12:00 am'
|
347
368
|
end
|
348
369
|
end
|
349
370
|
|
350
|
-
describe
|
351
|
-
it
|
371
|
+
describe 'setting to nil' do
|
372
|
+
it 'is nil' do
|
352
373
|
record = ModelWithDateTime.new
|
353
374
|
record.foo = Time.current
|
354
375
|
record.foo = nil
|
@@ -356,20 +377,20 @@ describe MultiparameterDateTime do
|
|
356
377
|
end
|
357
378
|
end
|
358
379
|
|
359
|
-
describe
|
380
|
+
describe 'configuring the datetime format' do
|
360
381
|
let(:record) { model.new(foo: Time.zone.parse('01/09/2000 1:30 pm')) }
|
361
382
|
|
362
|
-
context
|
383
|
+
context 'when the date format is set' do
|
363
384
|
before do
|
364
385
|
MultiparameterDateTime.date_format = '%-m-%-e-%0y'
|
365
386
|
end
|
366
387
|
|
367
|
-
it
|
368
|
-
subject.foo_date_part.
|
388
|
+
it 'formats the date properly' do
|
389
|
+
expect(subject.foo_date_part).to eq '1-9-00'
|
369
390
|
end
|
370
391
|
|
371
|
-
it
|
372
|
-
subject.foo_time_part.
|
392
|
+
it 'uses the default format for the time' do
|
393
|
+
expect(subject.foo_time_part).to eq '1:30 pm'
|
373
394
|
end
|
374
395
|
|
375
396
|
after do
|
@@ -377,17 +398,17 @@ describe MultiparameterDateTime do
|
|
377
398
|
end
|
378
399
|
end
|
379
400
|
|
380
|
-
context
|
401
|
+
context 'when the time format is set' do
|
381
402
|
before do
|
382
403
|
MultiparameterDateTime.time_format = '%H%M hours'
|
383
404
|
end
|
384
405
|
|
385
|
-
it
|
386
|
-
subject.foo_time_part.
|
406
|
+
it 'formats the time properly' do
|
407
|
+
expect(subject.foo_time_part).to eq '1330 hours'
|
387
408
|
end
|
388
409
|
|
389
|
-
it
|
390
|
-
subject.foo_date_part.
|
410
|
+
it 'uses the default format for the date' do
|
411
|
+
expect(subject.foo_date_part).to eq '1/9/2000'
|
391
412
|
end
|
392
413
|
|
393
414
|
after do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: multiparameter_date_time
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Case Commons, LLC
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2016-01-11 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: american_date
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.
|
129
|
+
rubygems_version: 2.2.2
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Set a DateTime via two accessors, one for the date, one for the time
|
@@ -134,3 +134,4 @@ test_files:
|
|
134
134
|
- spec/is_valid_multiparameter_date_time_validator_spec.rb
|
135
135
|
- spec/multiparameter_date_time_spec.rb
|
136
136
|
- spec/spec_helper.rb
|
137
|
+
has_rdoc:
|