multiparameter_date_time 0.2.0 → 0.3.0
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 875e99239f026cac0e6448b8056af1aedfd46c2e
|
4
|
+
data.tar.gz: 153a5eaf6862baff4b8723097f3fc9125af25164
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfba5fef5626f7e3eb2e46aeac82bc68cb738383f46569b190acbbc85395970bb15e58b91bd7af85b0a38c1ef1dafdae7f50f729f35e817c9ae21cc7fa3421a7
|
7
|
+
data.tar.gz: f782f4b7e9a5ea768d08b583c90d407e2ed759a62f74447d066cf6bcef2cd3e188ae484c0b99428f33b1293cd7057c7fc02c0a8eeffa0f2316aa02dadaf33ff3
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'active_support/concern'
|
2
|
+
require 'active_support/core_ext/time/zones'
|
2
3
|
require 'american_date'
|
3
4
|
require 'is_valid_multiparameter_date_time_validator'
|
4
5
|
|
@@ -33,33 +34,37 @@ module MultiparameterDateTime
|
|
33
34
|
time_part_setter = :"#{time_attribute}="
|
34
35
|
|
35
36
|
define_method "#{attribute_name}=" do |date_time_input|
|
36
|
-
|
37
|
-
|
37
|
+
case date_time_input
|
38
|
+
when Date, Time, DateTime
|
39
|
+
begin
|
38
40
|
date_time_input = date_time_input.in_time_zone
|
39
|
-
|
40
|
-
date_time_input = date_time_input.to_time_in_current_zone
|
41
|
+
rescue ArgumentError
|
41
42
|
end
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
43
|
+
write_attribute_for_multiparameter_date_time(attribute_name, date_time_input)
|
44
|
+
when String
|
45
|
+
iso8601 = begin
|
46
|
+
Time.iso8601(date_time_input).in_time_zone
|
47
|
+
rescue ArgumentError
|
48
|
+
nil
|
49
|
+
end
|
47
50
|
if iso8601
|
48
51
|
write_attribute_for_multiparameter_date_time(attribute_name, iso8601)
|
49
52
|
else
|
50
53
|
date_part, time_part = date_time_input.split(' ', 2)
|
51
|
-
parsed_date_part =
|
54
|
+
parsed_date_part = begin
|
55
|
+
Date.parse(date_part)
|
56
|
+
rescue ArgumentError
|
57
|
+
nil
|
58
|
+
end
|
52
59
|
if time_part.nil? && parsed_date_part
|
53
60
|
write_attribute_for_multiparameter_date_time(
|
54
61
|
attribute_name,
|
55
|
-
parsed_date_part.
|
62
|
+
parsed_date_part.in_time_zone)
|
56
63
|
else
|
57
64
|
public_send(date_part_setter, date_part)
|
58
65
|
public_send(time_part_setter, time_part)
|
59
66
|
end
|
60
67
|
end
|
61
|
-
else
|
62
|
-
write_attribute_for_multiparameter_date_time(attribute_name, date_time_input)
|
63
68
|
end
|
64
69
|
end
|
65
70
|
|
@@ -266,11 +266,11 @@ describe MultiparameterDateTime do
|
|
266
266
|
end
|
267
267
|
|
268
268
|
it "sets the attribute to a DateTime object" do
|
269
|
-
subject.foo.should == Time.zone.parse('
|
269
|
+
subject.foo.should == Time.zone.parse('01/01/2000 12:30pm')
|
270
270
|
end
|
271
271
|
|
272
272
|
it "has the original date" do
|
273
|
-
subject.foo_date_part.should == '
|
273
|
+
subject.foo_date_part.should == '01/01/2000'
|
274
274
|
end
|
275
275
|
|
276
276
|
it "has the original time" 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.
|
4
|
+
version: 0.3.0
|
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: 2014-07-
|
14
|
+
date: 2014-07-08 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: american_date
|