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: fc63493a635ad27f89775a40b7341fa1c5d7dae1
4
- data.tar.gz: f0925022123dbae27fc5093a060fbca253f45feb
3
+ metadata.gz: 875e99239f026cac0e6448b8056af1aedfd46c2e
4
+ data.tar.gz: 153a5eaf6862baff4b8723097f3fc9125af25164
5
5
  SHA512:
6
- metadata.gz: e9fb1385f8e7def9fbb7a99f2a8920e9cddc845c559bf4fa31aea171b8cddde7eea602f4dc501d25ea901ed82e7dd0b7c86b3446e3ce41fa31d1986b0ea0633c
7
- data.tar.gz: b731a1ff6cbbd8a8b1cc21ec1c9cdab30afc0d6f1fe8afe8a5060948da84ca3b8f57223c63c7e013527e3e9a04357870ece28b40f6aa760f3483170d4a064bd5
6
+ metadata.gz: bfba5fef5626f7e3eb2e46aeac82bc68cb738383f46569b190acbbc85395970bb15e58b91bd7af85b0a38c1ef1dafdae7f50f729f35e817c9ae21cc7fa3421a7
7
+ data.tar.gz: f782f4b7e9a5ea768d08b583c90d407e2ed759a62f74447d066cf6bcef2cd3e188ae484c0b99428f33b1293cd7057c7fc02c0a8eeffa0f2316aa02dadaf33ff3
@@ -1,3 +1,3 @@
1
1
  module MultiparameterDateTime
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
@@ -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
- begin
37
- if date_time_input.respond_to?(:in_time_zone)
37
+ case date_time_input
38
+ when Date, Time, DateTime
39
+ begin
38
40
  date_time_input = date_time_input.in_time_zone
39
- elsif date_time_input.respond_to?(:to_time_in_current_zone)
40
- date_time_input = date_time_input.to_time_in_current_zone
41
+ rescue ArgumentError
41
42
  end
42
- rescue ArgumentError
43
- end
44
-
45
- if date_time_input.is_a?(String)
46
- iso8601 = Time.iso8601(date_time_input).in_time_zone(Time.zone) rescue nil
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 = Date.parse(date_part) rescue nil
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.to_time_in_current_zone)
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
 
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  require 'multiparameter_date_time'
4
- require 'active_support/core_ext/time/zones'
5
4
  require 'is_valid_multiparameter_date_time_validator'
6
5
 
7
6
  describe IsValidMultiparameterDateTimeValidator do
@@ -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('1/1/2000 12:30pm')
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 == '1/1/2000'
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.2.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-07 00:00:00.000000000 Z
14
+ date: 2014-07-08 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: american_date