multiparameter_date_time 0.3.3 → 0.3.4

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: 5d0cfeb2fce7550d8d25996a0311794250af84f2
4
- data.tar.gz: 5309314fdb18b0b2b13ade0535eeae882ed8c0dd
3
+ metadata.gz: 6ddf8a324cd35af351af34df75e7a89f3c159554
4
+ data.tar.gz: a025da039da052889e1fd2627eaa3e94cce1341b
5
5
  SHA512:
6
- metadata.gz: 481030cfc94b83cda61d86cc5c4117676ce829d9440b8a3c0acbb2c336c2f56f5858b0f3a33488aabd937b7210f9b8bcffbb69aed46a9c199a62e2381847d551
7
- data.tar.gz: 919d1c9d62544e0c887d040a70528df9665308d8d0a01be86cc98cb6fb81c1f99dba83a8225402c9d610f5e8e91d279b17bf5052589f63f4848b298d9312948f
6
+ metadata.gz: 9a2131a2c0a35f1c7eb7f1037134a714f58c21258eaae2259d603dfb2d765d74c813a69fbc35b11a806f428f46e97f07baf5a092fcbea31145f8d5f6add08592
7
+ data.tar.gz: ad58b2a5835233d8bf5256a64f8d4529f8ca248539c08eccf78c87213f4d34dbd4a2a480a539f10b084bea0950aeaa95a563816fce3653c508ba79e2d6969b81
@@ -14,6 +14,7 @@ module MultiparameterDateTime
14
14
  DEFAULT_TIME_FORMAT = '%-I:%0M %P'
15
15
 
16
16
  mattr_writer :date_format, :time_format
17
+ mattr_accessor :date_string_formatter
17
18
 
18
19
  def self.date_format
19
20
  @@date_format ||= DEFAULT_DATE_FORMAT
@@ -111,8 +112,13 @@ module MultiparameterDateTime
111
112
  def set_combined_datetime(name, date_string, time_string)
112
113
  if date_string =~ MultiparameterDateTime::VALID_DATE_FORMAT && (time_string =~ MultiparameterDateTime::VALID_STANDARD_TIME_FORMAT || time_string =~ VALID_MILITARY_TIME_FORMAT)
113
114
  begin
115
+ formatted_date_string = date_string
116
+ if MultiparameterDateTime.date_string_formatter.present?
117
+ formatted_date_string = MultiparameterDateTime.date_string_formatter.format(date_string)
118
+ end
119
+
114
120
  write_attribute_for_multiparameter_date_time(
115
- name, Time.zone.parse("#{date_string} #{time_string}")
121
+ name, Time.zone.parse("#{formatted_date_string} #{time_string}")
116
122
  )
117
123
  rescue ArgumentError
118
124
  write_attribute_for_multiparameter_date_time(name, :incomplete)
@@ -1,3 +1,3 @@
1
1
  module MultiparameterDateTime
2
- VERSION = '0.3.3'
2
+ VERSION = '0.3.4'
3
3
  end
@@ -42,8 +42,13 @@ describe MultiparameterDateTime do
42
42
 
43
43
  describe "when a value is present" do
44
44
  let(:record) { model.new(foo: Time.zone.parse('1/2/2003 04:05pm')) }
45
- its(:foo_date_part) { should == '1/2/2003' }
46
- its(:foo_time_part) { should == '4:05 pm' }
45
+ it 'assigns date_part' do
46
+ expect(subject.foo_date_part).to eq '1/2/2003'
47
+ end
48
+
49
+ it 'assigns time_part' do
50
+ expect(subject.foo_time_part).to eq '4:05 pm'
51
+ end
47
52
  end
48
53
 
49
54
  describe "setting a valid date and time" do
@@ -390,6 +395,44 @@ describe MultiparameterDateTime do
390
395
  end
391
396
  end
392
397
  end
398
+
399
+ describe 'using a custom date string formatter' do
400
+ let(:foo_date_part) { '1/12/15' }
401
+ let(:foo_time_part) { '9:30 pm EST' }
402
+
403
+ context 'when the date string formatter is nil' do
404
+ it 'parses the unmodified date string' do
405
+ MultiparameterDateTime.date_string_formatter = nil
406
+ expect(Time.zone).to receive(:parse)
407
+ .with("#{foo_date_part} #{foo_time_part}")
408
+
409
+ model.new(foo_date_part: foo_date_part, foo_time_part: foo_time_part)
410
+ end
411
+ end
412
+
413
+ context 'when the date string formatter is present' do
414
+ before do
415
+ class TestFormatter
416
+ def self.format(date_string)
417
+ '12/31/1995'
418
+ end
419
+ end
420
+
421
+ MultiparameterDateTime.date_string_formatter = TestFormatter
422
+ end
423
+
424
+ after do
425
+ MultiparameterDateTime.date_string_formatter = nil
426
+ end
427
+
428
+ it 'uses a formatted date string' do
429
+ expect(Time.zone).to receive(:parse)
430
+ .with("#{'12/31/1995'} #{foo_time_part}")
431
+
432
+ model.new(foo_date_part: foo_date_part, foo_time_part: foo_time_part)
433
+ end
434
+ end
435
+ end
393
436
  end
394
437
  end
395
438
  end
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.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Case Commons, LLC
@@ -11,76 +11,76 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2014-09-08 00:00:00.000000000 Z
14
+ date: 2015-06-09 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: american_date
18
18
  requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
- - - '>='
20
+ - - ">="
21
21
  - !ruby/object:Gem::Version
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: activesupport
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  requirements:
34
- - - ~>
34
+ - - "~>"
35
35
  - !ruby/object:Gem::Version
36
36
  version: '4.0'
37
37
  type: :runtime
38
38
  prerelease: false
39
39
  version_requirements: !ruby/object:Gem::Requirement
40
40
  requirements:
41
- - - ~>
41
+ - - "~>"
42
42
  - !ruby/object:Gem::Version
43
43
  version: '4.0'
44
44
  - !ruby/object:Gem::Dependency
45
45
  name: activerecord
46
46
  requirement: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  type: :development
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
54
54
  requirements:
55
- - - '>='
55
+ - - ">="
56
56
  - !ruby/object:Gem::Version
57
57
  version: '0'
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec
60
60
  requirement: !ruby/object:Gem::Requirement
61
61
  requirements:
62
- - - ~>
62
+ - - "~>"
63
63
  - !ruby/object:Gem::Version
64
64
  version: '2.11'
65
65
  type: :development
66
66
  prerelease: false
67
67
  version_requirements: !ruby/object:Gem::Requirement
68
68
  requirements:
69
- - - ~>
69
+ - - "~>"
70
70
  - !ruby/object:Gem::Version
71
71
  version: '2.11'
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: with_model
74
74
  requirement: !ruby/object:Gem::Requirement
75
75
  requirements:
76
- - - ~>
76
+ - - "~>"
77
77
  - !ruby/object:Gem::Version
78
78
  version: '1.0'
79
79
  type: :development
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
82
82
  requirements:
83
- - - ~>
83
+ - - "~>"
84
84
  - !ruby/object:Gem::Version
85
85
  version: '1.0'
86
86
  description:
@@ -93,8 +93,8 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - .gitignore
97
- - .travis.yml
96
+ - ".gitignore"
97
+ - ".travis.yml"
98
98
  - Gemfile
99
99
  - LICENSE
100
100
  - README.md
@@ -116,17 +116,17 @@ require_paths:
116
116
  - lib
117
117
  required_ruby_version: !ruby/object:Gem::Requirement
118
118
  requirements:
119
- - - '>='
119
+ - - ">="
120
120
  - !ruby/object:Gem::Version
121
121
  version: 1.9.2
122
122
  required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  requirements:
124
- - - '>='
124
+ - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
128
  rubyforge_project:
129
- rubygems_version: 2.2.2
129
+ rubygems_version: 2.4.5
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