multiparameter_date_time 0.0.6 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a1d5bf1e19ef662fcef74a5542b2f6046dce1493
4
+ data.tar.gz: e8f92e002abf4866f473a5bdcada8df620e66881
5
+ SHA512:
6
+ metadata.gz: 498c0ffc96a2e09c3aa0bb84d504bc8f8f7c1cd472eaa59e2501712efacb396887bd1c47d85fc3383bfd95c8b47e3aa19ccde29b6a2b0fe33370d39502112d17
7
+ data.tar.gz: 6ef9b29279656b63bbc42bb03961114c773d4e84f5a7874f5553b7888ff95d82a8d9000462eeeadd61687ac4a01691c12c253d8f12d616e530cc306bfb6b8683
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ - 2.0.0
6
+ - jruby-19mode
7
+ - rbx-19mode
data/Gemfile CHANGED
@@ -3,8 +3,7 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in multiparameter_date_time.gemspec
4
4
  gemspec
5
5
 
6
- gem "rake"
7
- gem "sqlite3", :platforms => :ruby
8
- gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
9
- gem "pry"
10
-
6
+ gem 'activerecord-jdbcsqlite3-adapter', :platforms => :jruby
7
+ gem 'pry'
8
+ gem 'rake'
9
+ gem 'sqlite3', :platforms => :ruby
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Case Commons, LLC
1
+ Copyright (c) 2012-2013 Case Commons, LLC
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,13 +2,10 @@
2
2
 
3
3
  Set a DateTime via two accessors, one for the date, one for the time
4
4
 
5
- [![Build Status](https://secure.travis-ci.org/Casecommons/multiparameter_date_time.png?branch=master)](http://travis-ci.org/Casecommons/multiparameter_date_time)
5
+ [![Build Status](https://secure.travis-ci.org/Casecommons/multiparameter_date_time.png?branch=master)](https://travis-ci.org/Casecommons/multiparameter_date_time)
6
+ [![Code Climate](https://codeclimate.com/github/Casecommons/multiparameter_date_time.png)](https://codeclimate.com/github/Casecommons/multiparameter_date_time)
7
+ [![Gem Version](https://badge.fury.io/rb/multiparameter_date_time.png)](https://rubygems.org/gems/multiparameter_date_time)
6
8
  [![Dependency Status](https://gemnasium.com/Casecommons/multiparameter_date_time.png)](https://gemnasium.com/Casecommons/multiparameter_date_time)
7
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/Casecommons/multiparameter_date_time)
8
-
9
- ## Requirements
10
-
11
- * Ruby 1.9
12
9
 
13
10
  ## Installation
14
11
 
@@ -24,9 +21,11 @@ Or install it yourself as:
24
21
 
25
22
  $ gem install multiparameter_date_time
26
23
 
24
+ Note that Ruby 1.9.2+ is required.
25
+
27
26
  ## Usage
28
27
 
29
- ````ruby
28
+ ```ruby
30
29
  class Article < ActiveRecord::Base
31
30
  include MultiparameterDateTime
32
31
 
@@ -34,51 +33,51 @@ class Article < ActiveRecord::Base
34
33
  end
35
34
 
36
35
  record = Article.new(
37
- :publish_at_date_part => "01/01/2001",
38
- :publish_at_time_part => "4:30 pm"
36
+ :publish_at_date_part => '01/01/2001',
37
+ :publish_at_time_part => '4:30 pm'
39
38
  )
40
39
 
41
40
  record.publish_at #=> Mon, 01 Jan 2001 16:30:00 +0000
42
41
 
43
- record.publish_at_date_part = "2/3/2004"
42
+ record.publish_at_date_part = '2/3/2004'
44
43
  record.publish_at #=> Tue, 03 Feb 2004 16:30:00 +0000
45
44
 
46
45
  record = Article.new(
47
- :publish_at_date_part => "01/01/2001",
46
+ :publish_at_date_part => '01/01/2001',
48
47
  )
49
48
 
50
49
  record.publish_at #=> :incomplete
51
- record.publish_at_date_part #=> "01/01/2001"
50
+ record.publish_at_date_part #=> '01/01/2001'
52
51
  record.publish_at_time_part #=> nil
53
52
 
54
53
  record = Article.new(
55
- :publish_at_time_part => "09:30 am",
54
+ :publish_at_time_part => '09:30 am',
56
55
  )
57
56
 
58
57
  record.publish_at #=> :incomplete
59
58
  record.publish_at_date_part #=> nil
60
- record.publish_at_time_part #=> "09:30 am"
61
- ````
59
+ record.publish_at_time_part #=> '09:30 am'
60
+ ```
62
61
 
63
62
  ### Configuring the date and time formats
64
63
  In config/initializers/multiparameter\_date\_time.rb:
65
64
 
66
- ````ruby
67
- MultiparameterDateTime.date_format = "%-m/%-d/%Y"
68
- MultiparameterDateTime.time_format = "%-I:%M %P"
69
- ````
65
+ ```ruby
66
+ MultiparameterDateTime.date_format = '%-m/%-d/%0Y'
67
+ MultiparameterDateTime.time_format = '%-I:%0M %P'
68
+ ```
70
69
 
71
70
  ### Validating the multipart date time data
72
71
 
73
- ````ruby
72
+ ```ruby
74
73
  validates :published_at, presence: true, is_valid_multiparameter_date_time: true
75
- ````
74
+ ```
76
75
 
77
76
  ### Accessing the datetime error message used
78
77
 
79
- ````ruby
78
+ ```ruby
80
79
  IsValidMultiparameterDateTimeValidator.invalid_format_error_message
81
- ````
80
+ ```
82
81
 
83
82
  ## Contributing
84
83
 
@@ -87,3 +86,7 @@ IsValidMultiparameterDateTimeValidator.invalid_format_error_message
87
86
  3. Commit your changes (`git commit -am 'Added some feature'`)
88
87
  4. Push to the branch (`git push origin my-new-feature`)
89
88
  5. Create new Pull Request
89
+
90
+ ## License
91
+
92
+ Copyright © 2012–2013 Case Commons, LLC. License is available in the LICENSE file.
@@ -8,9 +8,9 @@ class IsValidMultiparameterDateTimeValidator < ActiveModel::EachValidator
8
8
  if date_invalid?(date_value) || time_invalid?(time_value)
9
9
  record.errors.add(attribute, self.class.invalid_format_error_message)
10
10
  elsif date_value.blank?
11
- record.errors.add(attribute, "Please enter a date.")
11
+ record.errors.add(attribute, 'Please enter a date.')
12
12
  elsif time_value.blank?
13
- record.errors.add(attribute, "Please enter a time.")
13
+ record.errors.add(attribute, 'Please enter a time.')
14
14
  else
15
15
  attribute_value = record.public_send(:"#{attribute}_time_part")
16
16
  begin
@@ -23,7 +23,7 @@ class IsValidMultiparameterDateTimeValidator < ActiveModel::EachValidator
23
23
  end
24
24
 
25
25
  def self.invalid_format_error_message
26
- date_time = Time.zone.parse("1/29/2000 5:15pm")
26
+ date_time = Time.zone.parse('1/29/2000 5:15pm')
27
27
  date_string = date_time.strftime(MultiparameterDateTime.date_format)
28
28
  time_string = date_time.strftime(MultiparameterDateTime.time_format)
29
29
 
@@ -32,12 +32,12 @@ class IsValidMultiparameterDateTimeValidator < ActiveModel::EachValidator
32
32
 
33
33
  def time_invalid?(time_value)
34
34
  if time_value.present?
35
- time_invalid_standard = time_value !~ MultiparameterDateTime::VALID_STANDARD_TIME_FORMAT
36
- time_invalid_military = time_value !~ MultiparameterDateTime::VALID_MILITARY_TIME_FORMAT
37
- time_invalid_standard && time_invalid_military
35
+ time_invalid_standard = time_value !~ MultiparameterDateTime::VALID_STANDARD_TIME_FORMAT
36
+ time_invalid_military = time_value !~ MultiparameterDateTime::VALID_MILITARY_TIME_FORMAT
37
+ time_invalid_standard && time_invalid_military
38
38
  end
39
39
  end
40
-
40
+
41
41
  def date_invalid?(date_value)
42
42
  if date_value.present?
43
43
  date_invalid = date_value !~ MultiparameterDateTime::VALID_DATE_FORMAT
@@ -1,3 +1,3 @@
1
1
  module MultiparameterDateTime
2
- VERSION = "0.0.6"
2
+ VERSION = '0.1.0'
3
3
  end
@@ -1,5 +1,5 @@
1
- require "active_support/concern"
2
- require "american_date"
1
+ require 'active_support/concern'
2
+ require 'american_date'
3
3
  require 'is_valid_multiparameter_date_time_validator'
4
4
 
5
5
  module MultiparameterDateTime
@@ -9,8 +9,8 @@ module MultiparameterDateTime
9
9
  VALID_STANDARD_TIME_FORMAT = /\A[0]*([1-9]|1[0-2]):\d{2}(:\d{2})?\s*([apAP][mM])?\s*([A-Z]{3,5})?\Z/
10
10
  VALID_MILITARY_TIME_FORMAT = /\A[0]*([0-9]|1[0-9]|2[0-3]):\d{2}(:\d{2})?\s*([A-Z]{3,5})?\Z/
11
11
 
12
- DEFAULT_DATE_FORMAT = "%-m/%-d/%Y"
13
- DEFAULT_TIME_FORMAT = "%-I:%M %P"
12
+ DEFAULT_DATE_FORMAT = '%-m/%-d/%0Y'
13
+ DEFAULT_TIME_FORMAT = '%-I:%0M %P'
14
14
 
15
15
  mattr_writer :date_format, :time_format
16
16
 
@@ -40,7 +40,7 @@ module MultiparameterDateTime
40
40
  if iso8601
41
41
  write_attribute_for_multiparameter_date_time(attribute_name, iso8601)
42
42
  else
43
- date_part, time_part = date_time_input.split(" ", 2)
43
+ date_part, time_part = date_time_input.split(' ', 2)
44
44
  parsed_date_part = Date.parse(date_part) rescue nil
45
45
  if time_part.nil? && parsed_date_part
46
46
  write_attribute_for_multiparameter_date_time(
@@ -2,21 +2,22 @@
2
2
  require File.expand_path('../lib/multiparameter_date_time/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Case Commons, LLC", "Grant Hutchins", "Trace Wax", "Jason Berlinsky"]
6
- gem.email = ["casecommons-dev@googlegroups.com", "gems@nertzy.com", "gems@tracedwax.com", "jason@jasonberlinsky.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"
5
+ gem.authors = ['Case Commons, LLC', 'Grant Hutchins', 'Trace Wax', 'Jason Berlinsky']
6
+ gem.email = ['casecommons-dev@googlegroups.com', 'gems@nertzy.com', 'gems@tracedwax.com', 'jason@jasonberlinsky.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
9
 
10
10
  gem.files = `git ls-files`.split($\)
11
11
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
12
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
- gem.name = "multiparameter_date_time"
14
- gem.require_paths = ["lib"]
13
+ gem.name = 'multiparameter_date_time'
14
+ gem.require_paths = ['lib']
15
15
  gem.version = MultiparameterDateTime::VERSION
16
+ gem.licenses = 'MIT'
16
17
 
17
18
  gem.required_ruby_version = '>= 1.9.2'
18
19
 
19
- gem.add_dependency "american_date"
20
+ gem.add_dependency 'american_date'
20
21
 
21
22
  gem.add_development_dependency 'activerecord'
22
23
  gem.add_development_dependency 'activesupport'
@@ -44,60 +44,60 @@ describe IsValidMultiparameterDateTimeValidator do
44
44
  end
45
45
 
46
46
  let(:bad_format_error) do
47
- "Please enter a valid date and time using the following formats: 1/29/2000, 5:15 pm"
47
+ 'Please enter a valid date and time using the following formats: 1/29/2000, 5:15 pm'
48
48
  end
49
- let(:missing_time_error) { "Please enter a time." }
50
- let(:missing_date_error) { "Please enter a date." }
49
+ let(:missing_time_error) { 'Please enter a time.' }
50
+ let(:missing_date_error) { 'Please enter a date.' }
51
51
 
52
52
  before { record.valid? }
53
53
 
54
54
  context "with valid date" do
55
- let(:date_string) { "01/01/2001" }
55
+ let(:date_string) { '01/01/2001' }
56
56
 
57
57
  context "with valid time in" do
58
58
  context "military format" do
59
59
  context "lots of zeros" do
60
- let(:time_string) { "00:00" }
60
+ let(:time_string) { '00:00' }
61
61
  it_should_behave_like "a valid time"
62
62
  end
63
63
 
64
64
  context "last valid value" do
65
- let(:time_string){ "23:59" }
65
+ let(:time_string) { '23:59' }
66
66
  it_should_behave_like "a valid time"
67
67
  end
68
68
 
69
69
  context "1 pm" do
70
- let(:time_string){ "13:00" }
70
+ let(:time_string) { '13:00' }
71
71
  it_should_behave_like "a valid time"
72
72
  end
73
73
  end
74
74
 
75
75
  context "standard format" do
76
- let(:time_string) { "12:31pm" }
76
+ let(:time_string) { '12:31pm' }
77
77
  it_should_behave_like "a valid time"
78
78
 
79
79
  context "with a capital AM or PM" do
80
- let(:time_string) { "12:31 PM" }
80
+ let(:time_string) { '12:31 PM' }
81
81
  it_should_behave_like "a valid time"
82
82
  end
83
83
 
84
84
  context "without a space between the time and AM or PM" do
85
- let(:time_string) { "12:31AM" }
85
+ let(:time_string) { '12:31AM' }
86
86
  it_should_behave_like "a valid time"
87
87
  end
88
88
 
89
89
  context "with no space and a mixed case aM or pM" do
90
- let(:time_string) { "12:31aM" }
90
+ let(:time_string) { '12:31aM' }
91
91
  it_should_behave_like "a valid time"
92
92
  end
93
93
 
94
94
  context "with a space and a mixed case aM or pM" do
95
- let(:time_string) { "12:31 aM" }
95
+ let(:time_string) { '12:31 aM' }
96
96
  it_should_behave_like "a valid time"
97
97
  end
98
98
 
99
99
  context "with a space and a lower case am or pm" do
100
- let(:time_string) { "12:31 am" }
100
+ let(:time_string) { '12:31 am' }
101
101
  it_should_behave_like "a valid time"
102
102
  end
103
103
  end
@@ -106,24 +106,24 @@ describe IsValidMultiparameterDateTimeValidator do
106
106
  context "with invalid time in" do
107
107
  context "military format" do
108
108
  context "above 23:59" do
109
- let(:time_string) { "25:00" }
109
+ let(:time_string) { '25:00' }
110
110
  it_should_behave_like "a badly formatted date or time"
111
111
  end
112
112
 
113
113
  context "with am or pm" do
114
- let(:time_string) { "23:00 am" }
114
+ let(:time_string) { '23:00 am' }
115
115
  it_should_behave_like "a badly formatted date or time"
116
116
  end
117
117
  end
118
118
 
119
119
  context "standard format" do
120
- let(:time_string) { "90:00pm" }
120
+ let(:time_string) { '90:00pm' }
121
121
 
122
122
  it_should_behave_like "a badly formatted date or time"
123
123
  end
124
124
  end
125
125
 
126
- [" ", nil].each do |time_value|
126
+ [' ', nil].each do |time_value|
127
127
  context "with time = #{time_value.inspect}" do
128
128
  let(:time_string) { time_value }
129
129
  it "should show the missing time error" do
@@ -134,21 +134,21 @@ describe IsValidMultiparameterDateTimeValidator do
134
134
  end
135
135
 
136
136
  context "with invalid date" do
137
- let(:date_string) { "asdf" }
137
+ let(:date_string) { 'asdf' }
138
138
 
139
139
  context "with valid time" do
140
- let(:time_string) { "12:31pm" }
140
+ let(:time_string) { '12:31pm' }
141
141
 
142
142
  it_should_behave_like "a badly formatted date or time"
143
143
  end
144
144
 
145
145
  context "with invalid time" do
146
- let(:time_string) { "asdf" }
146
+ let(:time_string) { 'asdf' }
147
147
 
148
148
  it_should_behave_like "a badly formatted date or time"
149
149
  end
150
150
 
151
- [" ", nil].each do |time_value|
151
+ [' ', nil].each do |time_value|
152
152
  context "with time = #{time_value.inspect}" do
153
153
  let(:time_string) { time_value }
154
154
  it_should_behave_like "a badly formatted date or time"
@@ -156,12 +156,12 @@ describe IsValidMultiparameterDateTimeValidator do
156
156
  end
157
157
  end
158
158
 
159
- [" ", nil].each do |date_value|
159
+ [' ', nil].each do |date_value|
160
160
  context "with date = #{date_value.inspect}" do
161
161
  let(:date_string) { date_value }
162
162
 
163
163
  context "with valid time" do
164
- let(:time_string) { "12:31pm" }
164
+ let(:time_string) { '12:31pm' }
165
165
 
166
166
  it "should show the missing date error" do
167
167
  record.errors[:foo].should == [missing_date_error]
@@ -169,7 +169,7 @@ describe IsValidMultiparameterDateTimeValidator do
169
169
  end
170
170
 
171
171
  context "with invalid time" do
172
- let(:time_string) { "asdf" }
172
+ let(:time_string) { 'asdf' }
173
173
 
174
174
  it_should_behave_like "a badly formatted date or time"
175
175
  end
@@ -209,7 +209,7 @@ describe IsValidMultiparameterDateTimeValidator do
209
209
  context "with an impossible date" do
210
210
  context "set in parts" do
211
211
  let(:record) do
212
- ModelWithDatetime.new(foo_date_part: "19/19/1919", foo_time_part: "04:50pm")
212
+ ModelWithDatetime.new(foo_date_part: '19/19/1919', foo_time_part: '04:50pm')
213
213
  end
214
214
 
215
215
  it_should_behave_like "a badly formatted date or time"
@@ -217,7 +217,7 @@ describe IsValidMultiparameterDateTimeValidator do
217
217
 
218
218
  context "set directly" do
219
219
  let(:record) do
220
- ModelWithDatetime.new(foo: "19/19/1919 04:50pm")
220
+ ModelWithDatetime.new(foo: '19/19/1919 04:50pm')
221
221
  end
222
222
 
223
223
  it_should_behave_like "a badly formatted date or time"
@@ -227,7 +227,7 @@ describe IsValidMultiparameterDateTimeValidator do
227
227
  context "with an impossible time" do
228
228
  context "set in parts" do
229
229
  let(:record) do
230
- ModelWithDatetime.new(foo_date_part: "01/01/2001", foo_time_part: "09:99pm")
230
+ ModelWithDatetime.new(foo_date_part: '01/01/2001', foo_time_part: '09:99pm')
231
231
  end
232
232
 
233
233
  it_should_behave_like "a badly formatted date or time"
@@ -235,7 +235,7 @@ describe IsValidMultiparameterDateTimeValidator do
235
235
 
236
236
  context "set directly" do
237
237
  let(:record) do
238
- ModelWithDatetime.new(foo: "01/01/2001 09:99pm")
238
+ ModelWithDatetime.new(foo: '01/01/2001 09:99pm')
239
239
  end
240
240
 
241
241
  it_should_behave_like "a badly formatted date or time"
@@ -243,18 +243,18 @@ describe IsValidMultiparameterDateTimeValidator do
243
243
  end
244
244
 
245
245
  context "when the display format has been configured" do
246
- let(:date_string) { "asdf" }
247
- let(:time_string) { "foo" }
246
+ let(:date_string) { 'asdf' }
247
+ let(:time_string) { 'foo' }
248
248
 
249
249
  context "when the date format is set" do
250
250
  before do
251
- MultiparameterDateTime.date_format = "%-m-%-e-%y"
251
+ MultiparameterDateTime.date_format = '%-m-%-e-%0y'
252
252
  record.valid?
253
253
  end
254
254
 
255
255
  it "should show the bad format error" do
256
256
  record.errors[:foo].should == [
257
- "Please enter a valid date and time using the following formats: 1-29-00, 5:15 pm"
257
+ 'Please enter a valid date and time using the following formats: 1-29-00, 5:15 pm'
258
258
  ]
259
259
  end
260
260
 
@@ -264,16 +264,16 @@ describe IsValidMultiparameterDateTimeValidator do
264
264
  end
265
265
 
266
266
  context "when the time format is set" do
267
- let(:time_string) { "asdf" }
267
+ let(:time_string) { 'asdf' }
268
268
 
269
269
  before do
270
- MultiparameterDateTime.time_format = "%H%M hours"
270
+ MultiparameterDateTime.time_format = '%H%M hours'
271
271
  record.valid?
272
272
  end
273
273
 
274
274
  it "should show the bad format error" do
275
275
  record.errors[:foo].should == [
276
- "Please enter a valid date and time using the following formats: 1/29/2000, 1715 hours"
276
+ 'Please enter a valid date and time using the following formats: 1/29/2000, 1715 hours'
277
277
  ]
278
278
  end
279
279
 
@@ -285,10 +285,10 @@ describe IsValidMultiparameterDateTimeValidator do
285
285
  end
286
286
 
287
287
  describe "accepts dates in a variety of formats" do
288
- ["2010-1-1", "02-01-1971", "4/4/92", "01/02/2001", "01/02/2001", "01.02.2011"].each do |format|
288
+ ['2010-1-1', '02-01-1971', '4/4/92', '01/02/2001', '01/02/2001', '01.02.2011'].each do |format|
289
289
  context format do
290
290
  let(:date_string) { format }
291
- let(:time_string) { "12:00am" }
291
+ let(:time_string) { '12:00am' }
292
292
  let(:record) do
293
293
  ModelWithDatetime.new(foo_date_part: date_string, foo_time_part: time_string)
294
294
  end
@@ -305,7 +305,7 @@ describe IsValidMultiparameterDateTimeValidator do
305
305
 
306
306
  it do
307
307
  should ==
308
- "Please enter a valid date and time using the following formats: 1/29/2000, 5:15 pm"
308
+ 'Please enter a valid date and time using the following formats: 1/29/2000, 5:15 pm'
309
309
  end
310
310
  end
311
311
  end
@@ -1,12 +1,12 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
- require "multiparameter_date_time"
4
- require "informal"
5
- require "active_support/core_ext/time/zones"
3
+ require 'multiparameter_date_time'
4
+ require 'informal'
5
+ require 'active_support/core_ext/time/zones'
6
6
 
7
7
  describe MultiparameterDateTime do
8
8
  before do
9
- Time.zone = "US/Eastern"
9
+ Time.zone = 'US/Eastern'
10
10
  end
11
11
 
12
12
  with_model :ModelWithDateTime do
@@ -42,35 +42,35 @@ describe MultiparameterDateTime do
42
42
  subject { record }
43
43
 
44
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" }
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
48
  end
49
49
 
50
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" }
51
+ let(:foo_date_part) { '01/02/2000' }
52
+ let(:foo_time_part) { '9:30 pm EST' }
53
53
 
54
54
  it "doesn't raise an exception" do
55
55
  expect { subject }.not_to raise_exception
56
56
  end
57
57
 
58
58
  it "sets the attribute to a DateTime object" do
59
- subject.foo.should == Time.zone.parse("1/2/2000 9:30 pm")
59
+ subject.foo.should == Time.zone.parse('1/2/2000 9:30 pm')
60
60
  end
61
61
 
62
62
  it "has the original date input" do
63
- subject.foo_date_part.should == "01/02/2000"
63
+ subject.foo_date_part.should == '01/02/2000'
64
64
  end
65
65
 
66
66
  it "has the original time input" do
67
- subject.foo_time_part.should == "9:30 pm EST"
67
+ subject.foo_time_part.should == '9:30 pm EST'
68
68
  end
69
69
  end
70
70
 
71
71
  describe "setting an invalid date" do
72
- let(:foo_date_part) { "bad input" }
73
- let(:foo_time_part) { "9:30 pm" }
72
+ let(:foo_date_part) { 'bad input' }
73
+ let(:foo_time_part) { '9:30 pm' }
74
74
 
75
75
  it "doesn't raise an exception" do
76
76
  expect { subject }.not_to raise_exception
@@ -81,17 +81,17 @@ describe MultiparameterDateTime do
81
81
  end
82
82
 
83
83
  it "has the original date" do
84
- subject.foo_date_part.should == "bad input"
84
+ subject.foo_date_part.should == 'bad input'
85
85
  end
86
86
 
87
87
  it "has the original time input" do
88
- subject.foo_time_part.should == "9:30 pm"
88
+ subject.foo_time_part.should == '9:30 pm'
89
89
  end
90
90
  end
91
91
 
92
92
  describe "setting a impossible date" do
93
- let(:foo_date_part) { "99/99/9999" }
94
- let(:foo_time_part) { "12:30 pm" }
93
+ let(:foo_date_part) { '99/99/9999' }
94
+ let(:foo_time_part) { '12:30 pm' }
95
95
 
96
96
  it "doesn't raise an exception" do
97
97
  expect { subject }.not_to raise_exception
@@ -102,17 +102,17 @@ describe MultiparameterDateTime do
102
102
  end
103
103
 
104
104
  it "has the original date" do
105
- subject.foo_date_part.should == "99/99/9999"
105
+ subject.foo_date_part.should == '99/99/9999'
106
106
  end
107
107
 
108
108
  it "has the original time" do
109
- subject.foo_time_part.should == "12:30 pm"
109
+ subject.foo_time_part.should == '12:30 pm'
110
110
  end
111
111
  end
112
112
 
113
113
  describe "setting an invalid time" do
114
- let(:foo_date_part) { "01/02/2000" }
115
- let(:foo_time_part) { "bad input" }
114
+ let(:foo_date_part) { '01/02/2000' }
115
+ let(:foo_time_part) { 'bad input' }
116
116
 
117
117
  it "doesn't raise an exception" do
118
118
  expect { subject }.not_to raise_exception
@@ -123,7 +123,7 @@ describe MultiparameterDateTime do
123
123
  end
124
124
 
125
125
  it "has the original date input" do
126
- subject.foo_date_part.should == "01/02/2000"
126
+ subject.foo_date_part.should == '01/02/2000'
127
127
  end
128
128
 
129
129
  it "has the original time input" do
@@ -132,8 +132,8 @@ describe MultiparameterDateTime do
132
132
  end
133
133
 
134
134
  describe "setting a impossible time" do
135
- let(:foo_date_part) { "01/02/2000" }
136
- let(:foo_time_part) { "99:99pm" }
135
+ let(:foo_date_part) { '01/02/2000' }
136
+ let(:foo_time_part) { '99:99pm' }
137
137
 
138
138
  it "doesn't raise an exception" do
139
139
  expect { subject }.not_to raise_exception
@@ -144,16 +144,16 @@ describe MultiparameterDateTime do
144
144
  end
145
145
 
146
146
  it "has the original date input" do
147
- subject.foo_date_part.should == "01/02/2000"
147
+ subject.foo_date_part.should == '01/02/2000'
148
148
  end
149
149
 
150
150
  it "has the original time input" do
151
- subject.foo_time_part.should == "99:99pm"
151
+ subject.foo_time_part.should == '99:99pm'
152
152
  end
153
153
  end
154
154
 
155
155
  describe "setting a date but not a time" do
156
- let(:record) { model.new(foo_date_part: "01/01/2000") }
156
+ let(:record) { model.new(foo_date_part: '01/01/2000') }
157
157
 
158
158
  it "doesn't raise an exception" do
159
159
  expect { subject }.not_to raise_exception
@@ -164,7 +164,7 @@ describe MultiparameterDateTime do
164
164
  end
165
165
 
166
166
  it "has the original date" do
167
- subject.foo_date_part.should == "01/01/2000"
167
+ subject.foo_date_part.should == '01/01/2000'
168
168
  end
169
169
 
170
170
  it "has the nil for the time input" do
@@ -173,7 +173,7 @@ describe MultiparameterDateTime do
173
173
  end
174
174
 
175
175
  describe "setting a time but not a date" do
176
- let(:record) { model.new(foo_time_part: "12:30 pm") }
176
+ let(:record) { model.new(foo_time_part: '12:30 pm') }
177
177
 
178
178
  it "doesn't raise an exception" do
179
179
  expect { subject }.not_to raise_exception
@@ -188,13 +188,13 @@ describe MultiparameterDateTime do
188
188
  end
189
189
 
190
190
  it "has the original time" do
191
- subject.foo_time_part.should == "12:30 pm"
191
+ subject.foo_time_part.should == '12:30 pm'
192
192
  end
193
193
  end
194
194
 
195
195
  describe "setting incorrect time and date" do
196
- let(:record) { model.new(foo_time_part: "qwer",
197
- foo_date_part: "asdf") }
196
+ let(:record) { model.new(foo_time_part: 'qwer',
197
+ foo_date_part: 'asdf') }
198
198
 
199
199
  it "doesn't raise an exception" do
200
200
  expect { subject }.not_to raise_exception
@@ -209,13 +209,13 @@ describe MultiparameterDateTime do
209
209
  end
210
210
 
211
211
  it "has the original time input" do
212
- subject.foo_time_part.should == "qwer"
212
+ subject.foo_time_part.should == 'qwer'
213
213
  end
214
214
  end
215
215
 
216
216
  describe "setting neither time nor a date" do
217
- let(:record) { model.new(foo_time_part: "",
218
- foo_date_part: "") }
217
+ let(:record) { model.new(foo_time_part: '',
218
+ foo_date_part: '') }
219
219
 
220
220
  it "doesn't raise an exception" do
221
221
  expect { subject }.not_to raise_exception
@@ -226,99 +226,97 @@ describe MultiparameterDateTime do
226
226
  end
227
227
 
228
228
  it "has the original date" do
229
- subject.foo_date_part.should == ""
229
+ subject.foo_date_part.should == ''
230
230
  end
231
231
 
232
232
  it "has the original time input" do
233
- subject.foo_time_part.should == ""
233
+ subject.foo_time_part.should == ''
234
234
  end
235
235
  end
236
236
 
237
237
  describe "setting a DateTime directly" do
238
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" }
239
+ let(:foo_date_part) { '01/02/2000' }
240
+ let(:foo_time_part) { '12:30 pm' }
242
241
 
243
242
  it "doesn't raise an exception" do
244
243
  expect { subject }.not_to raise_exception
245
244
  end
246
245
 
247
246
  it "sets the attribute to a DateTime object" do
248
- subject.foo.should == Time.zone.parse("01/02/2000 12:30 pm")
247
+ subject.foo.should == Time.zone.parse('01/02/2000 12:30 pm')
249
248
  end
250
249
 
251
250
  it "has the original date" do
252
- subject.foo_date_part.should == "1/2/2000"
251
+ subject.foo_date_part.should == '1/2/2000'
253
252
  end
254
253
 
255
254
  it "has the original time input" do
256
- subject.foo_time_part.should == "12:30 pm"
255
+ subject.foo_time_part.should == '12:30 pm'
257
256
  end
258
257
  end
259
258
 
260
259
  describe "setting a String directly" do
261
260
  context "When the string contains a date and time" do
262
261
  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" }
262
+ let(:foo_date_part) { '01/01/2000' }
263
+ let(:foo_time_part) { '12:30 pm' }
266
264
 
267
265
  it "doesn't raise an exception" do
268
266
  expect { subject }.not_to raise_exception
269
267
  end
270
268
 
271
269
  it "sets the attribute to a DateTime object" do
272
- subject.foo.should == Time.zone.parse("01/01/2000 12:30pm")
270
+ subject.foo.should == Time.zone.parse('01/01/2000 12:30pm')
273
271
  end
274
272
 
275
273
  it "has the original date" do
276
- subject.foo_date_part.should == "01/01/2000"
274
+ subject.foo_date_part.should == '01/01/2000'
277
275
  end
278
276
 
279
277
  it "has the original time" do
280
- subject.foo_time_part.should == "12:30 pm"
278
+ subject.foo_time_part.should == '12:30 pm'
281
279
  end
282
280
  end
283
281
 
284
282
  context "When the string contains an iso8601 datetime" do
285
- let(:record) { model.new(foo: "2011-12-03T01:00:00Z") }
283
+ let(:record) { model.new(foo: '2011-12-03T01:00:00Z') }
284
+
286
285
  it "doesn't raise an exception" do
287
286
  expect { subject }.not_to raise_exception
288
287
  end
289
288
 
290
289
  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")
290
+ subject.foo.should == Time.zone.parse('12/2/2011 8:00 pm')
292
291
  end
293
292
 
294
293
  it "has a date" do
295
- subject.foo_date_part.should == "12/2/2011"
294
+ subject.foo_date_part.should == '12/2/2011'
296
295
  end
297
296
 
298
297
  it "has a time" do
299
- subject.foo_time_part.should == "8:00 pm"
298
+ subject.foo_time_part.should == '8:00 pm'
300
299
  end
301
300
  end
302
301
 
303
302
  context "When the string contains only a date" do
304
303
  let(:record) { model.new(foo: "#{foo_date_part}") }
305
-
306
- let(:foo_date_part) { "01/01/2000" }
304
+ let(:foo_date_part) { '01/01/2000' }
307
305
 
308
306
  it "doesn't raise an exception" do
309
307
  expect { subject }.not_to raise_exception
310
308
  end
311
309
 
312
310
  it "sets the attribute to a DateTime object" do
313
- subject.foo.should == Time.zone.parse("01/01/2000 12:00am")
311
+ subject.foo.should == Time.zone.parse('01/01/2000 12:00am')
314
312
  end
315
313
 
316
314
  it "has the original date" do
317
- subject.foo_date_part.should == "1/1/2000"
315
+ subject.foo_date_part.should == '1/1/2000'
318
316
  end
319
317
 
320
318
  it "has midnight for the time input" do
321
- subject.foo_time_part.should == "12:00 am"
319
+ subject.foo_time_part.should == '12:00 am'
322
320
  end
323
321
  end
324
322
  end
@@ -326,39 +324,39 @@ describe MultiparameterDateTime do
326
324
  describe "setting a Date directly" do
327
325
  let(:record) { model.new(foo: Date.parse(foo_date_part)) }
328
326
 
329
- let(:foo_date_part) { "01/01/2000" }
327
+ let(:foo_date_part) { '01/01/2000' }
330
328
 
331
329
  it "doesn't raise an exception" do
332
330
  expect { subject }.not_to raise_exception
333
331
  end
334
332
 
335
333
  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")
334
+ subject.foo.should == Time.zone.parse('01/01/2000 12:00 am')
337
335
  end
338
336
 
339
337
  it "has the original date" do
340
- subject.foo_date_part.should == "1/1/2000"
338
+ subject.foo_date_part.should == '1/1/2000'
341
339
  end
342
340
 
343
341
  it "has midnight for the time input" do
344
- subject.foo_time_part.should == "12:00 am"
342
+ subject.foo_time_part.should == '12:00 am'
345
343
  end
346
344
  end
347
345
 
348
346
  describe "configuring the datetime format" do
349
- let(:record) { model.new(foo: Time.zone.parse("01/09/2000 1:30 pm")) }
347
+ let(:record) { model.new(foo: Time.zone.parse('01/09/2000 1:30 pm')) }
350
348
 
351
349
  context "when the date format is set" do
352
350
  before do
353
- MultiparameterDateTime.date_format = "%-m-%-e-%y"
351
+ MultiparameterDateTime.date_format = '%-m-%-e-%0y'
354
352
  end
355
353
 
356
354
  it "should format the date properly" do
357
- subject.foo_date_part.should == "1-9-00"
355
+ subject.foo_date_part.should == '1-9-00'
358
356
  end
359
357
 
360
358
  it "should use the default format for the time" do
361
- subject.foo_time_part.should == "1:30 pm"
359
+ subject.foo_time_part.should == '1:30 pm'
362
360
  end
363
361
 
364
362
  after do
@@ -368,22 +366,21 @@ describe MultiparameterDateTime do
368
366
 
369
367
  context "when the time format is set" do
370
368
  before do
371
- MultiparameterDateTime.time_format = "%H%M hours"
369
+ MultiparameterDateTime.time_format = '%H%M hours'
372
370
  end
373
371
 
374
372
  it "should format the time properly" do
375
- subject.foo_time_part.should == "1330 hours"
373
+ subject.foo_time_part.should == '1330 hours'
376
374
  end
377
375
 
378
376
  it "should use the default format for the date" do
379
- subject.foo_date_part.should == "1/9/2000"
377
+ subject.foo_date_part.should == '1/9/2000'
380
378
  end
381
379
 
382
380
  after do
383
381
  MultiparameterDateTime.time_format = MultiparameterDateTime::DEFAULT_TIME_FORMAT
384
382
  end
385
383
  end
386
-
387
384
  end
388
385
  end
389
386
  end
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,13 @@
1
- require "active_record"
2
- require "with_model"
1
+ require 'active_record'
2
+ require 'with_model'
3
3
 
4
4
  RSpec.configure do |config|
5
5
  config.extend WithModel
6
6
  end
7
7
 
8
8
  jruby = RUBY_PLATFORM =~ /\bjava\b/
9
- adapter = jruby ? "jdbcsqlite3" : "sqlite3"
9
+ adapter = jruby ? 'jdbcsqlite3' : 'sqlite3'
10
10
 
11
11
  # MultiparameterDateTime requires ActiveRecord::Base.connection to be established.
12
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
-
13
+ ActiveRecord::Base.establish_connection(:adapter => adapter, :database => ':memory:')
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multiparameter_date_time
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.1.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Case Commons, LLC
@@ -12,60 +11,53 @@ authors:
12
11
  autorequire:
13
12
  bindir: bin
14
13
  cert_chain: []
15
- date: 2013-10-03 00:00:00.000000000 Z
14
+ date: 2013-10-04 00:00:00.000000000 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: american_date
19
18
  requirement: !ruby/object:Gem::Requirement
20
- none: false
21
19
  requirements:
22
- - - ! '>='
20
+ - - '>='
23
21
  - !ruby/object:Gem::Version
24
22
  version: '0'
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
- - - ! '>='
27
+ - - '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '0'
33
30
  - !ruby/object:Gem::Dependency
34
31
  name: activerecord
35
32
  requirement: !ruby/object:Gem::Requirement
36
- none: false
37
33
  requirements:
38
- - - ! '>='
34
+ - - '>='
39
35
  - !ruby/object:Gem::Version
40
36
  version: '0'
41
37
  type: :development
42
38
  prerelease: false
43
39
  version_requirements: !ruby/object:Gem::Requirement
44
- none: false
45
40
  requirements:
46
- - - ! '>='
41
+ - - '>='
47
42
  - !ruby/object:Gem::Version
48
43
  version: '0'
49
44
  - !ruby/object:Gem::Dependency
50
45
  name: activesupport
51
46
  requirement: !ruby/object:Gem::Requirement
52
- none: false
53
47
  requirements:
54
- - - ! '>='
48
+ - - '>='
55
49
  - !ruby/object:Gem::Version
56
50
  version: '0'
57
51
  type: :development
58
52
  prerelease: false
59
53
  version_requirements: !ruby/object:Gem::Requirement
60
- none: false
61
54
  requirements:
62
- - - ! '>='
55
+ - - '>='
63
56
  - !ruby/object:Gem::Version
64
57
  version: '0'
65
58
  - !ruby/object:Gem::Dependency
66
59
  name: rspec
67
60
  requirement: !ruby/object:Gem::Requirement
68
- none: false
69
61
  requirements:
70
62
  - - ~>
71
63
  - !ruby/object:Gem::Version
@@ -73,7 +65,6 @@ dependencies:
73
65
  type: :development
74
66
  prerelease: false
75
67
  version_requirements: !ruby/object:Gem::Requirement
76
- none: false
77
68
  requirements:
78
69
  - - ~>
79
70
  - !ruby/object:Gem::Version
@@ -81,7 +72,6 @@ dependencies:
81
72
  - !ruby/object:Gem::Dependency
82
73
  name: with_model
83
74
  requirement: !ruby/object:Gem::Requirement
84
- none: false
85
75
  requirements:
86
76
  - - ~>
87
77
  - !ruby/object:Gem::Version
@@ -89,7 +79,6 @@ dependencies:
89
79
  type: :development
90
80
  prerelease: false
91
81
  version_requirements: !ruby/object:Gem::Requirement
92
- none: false
93
82
  requirements:
94
83
  - - ~>
95
84
  - !ruby/object:Gem::Version
@@ -97,7 +86,6 @@ dependencies:
97
86
  - !ruby/object:Gem::Dependency
98
87
  name: informal
99
88
  requirement: !ruby/object:Gem::Requirement
100
- none: false
101
89
  requirements:
102
90
  - - ~>
103
91
  - !ruby/object:Gem::Version
@@ -105,7 +93,6 @@ dependencies:
105
93
  type: :development
106
94
  prerelease: false
107
95
  version_requirements: !ruby/object:Gem::Requirement
108
- none: false
109
96
  requirements:
110
97
  - - ~>
111
98
  - !ruby/object:Gem::Version
@@ -121,6 +108,7 @@ extensions: []
121
108
  extra_rdoc_files: []
122
109
  files:
123
110
  - .gitignore
111
+ - .travis.yml
124
112
  - Gemfile
125
113
  - LICENSE
126
114
  - README.md
@@ -133,33 +121,31 @@ files:
133
121
  - spec/multiparameter_date_time_spec.rb
134
122
  - spec/spec_helper.rb
135
123
  homepage: https://github.com/Casecommons/multiparameter_date_time
136
- licenses: []
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
137
127
  post_install_message:
138
128
  rdoc_options: []
139
129
  require_paths:
140
130
  - lib
141
131
  required_ruby_version: !ruby/object:Gem::Requirement
142
- none: false
143
132
  requirements:
144
- - - ! '>='
133
+ - - '>='
145
134
  - !ruby/object:Gem::Version
146
135
  version: 1.9.2
147
136
  required_rubygems_version: !ruby/object:Gem::Requirement
148
- none: false
149
137
  requirements:
150
- - - ! '>='
138
+ - - '>='
151
139
  - !ruby/object:Gem::Version
152
140
  version: '0'
153
- segments:
154
- - 0
155
- hash: -4212657700101252110
156
141
  requirements: []
157
142
  rubyforge_project:
158
- rubygems_version: 1.8.25
143
+ rubygems_version: 2.1.5
159
144
  signing_key:
160
- specification_version: 3
145
+ specification_version: 4
161
146
  summary: Set a DateTime via two accessors, one for the date, one for the time
162
147
  test_files:
163
148
  - spec/is_valid_multiparameter_date_time_validator_spec.rb
164
149
  - spec/multiparameter_date_time_spec.rb
165
150
  - spec/spec_helper.rb
151
+ has_rdoc: