partial-date 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +3 -0
- data/.gitignore +4 -0
- data/.rspec +1 -0
- data/.yardopts +1 -0
- data/ChangeLog.textile +4 -0
- data/Guardfile +8 -0
- data/LICENSE.txt +20 -0
- data/README.textile +59 -0
- data/Rakefile +40 -0
- data/lib/partial-date.rb +4 -0
- data/lib/partial-date/date.rb +209 -0
- data/lib/partial-date/error.rb +4 -0
- data/lib/partial-date/version.rb +4 -0
- data/partial-date.gemspec +23 -0
- data/spec/partial-date_spec.rb +167 -0
- data/spec/spec_helper.rb +4 -0
- metadata +115 -0
data/.document
ADDED
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour --format documentation
|
data/.yardopts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--plugin yard-tomdoc --markup textile --title "PartialDate Documentation" --protected
|
data/ChangeLog.textile
ADDED
data/Guardfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 Anthony Bouch
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.textile
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
h1. partial-date
|
2
|
+
|
3
|
+
* "Homepage":https://github.com/58bits/partial-date#readme
|
4
|
+
* "Issues":https://github.com/58bits/partial-date/issues
|
5
|
+
* "Documentation":http://rubydoc.info/gems/partial-date/frames
|
6
|
+
|
7
|
+
h2. Description
|
8
|
+
|
9
|
+
A simple date class that can be used to store partial date values in a single column/attribute. An example use case would include an archive, or catalogue entry where the complete date is unknown.
|
10
|
+
|
11
|
+
h2. Features
|
12
|
+
|
13
|
+
PartialDate::Date uses an 8 digit integer to store year, month and day values. Values for month and day are optional.
|
14
|
+
|
15
|
+
h2. Examples
|
16
|
+
|
17
|
+
bc.. require 'partial-date'
|
18
|
+
|
19
|
+
#Default initializer
|
20
|
+
date = PartialDate::Date.new
|
21
|
+
# =>
|
22
|
+
date.value
|
23
|
+
# => 0
|
24
|
+
|
25
|
+
# Initialize from a block of integers
|
26
|
+
date = PartialDate::Date.new {|d| d.year = 2012, d.month = 01}
|
27
|
+
# => 2012-01
|
28
|
+
date.value
|
29
|
+
# => 20120100
|
30
|
+
|
31
|
+
# Initialize from a block of strings
|
32
|
+
date = PartialDate::Date.new {|d| d.year = "2012", d.month = "01"}
|
33
|
+
# => 2012-01
|
34
|
+
date.value
|
35
|
+
# => 20120100
|
36
|
+
|
37
|
+
# Initialize from the class load method - for rehydrating a date instance from a stored integer date value.
|
38
|
+
date = PartialDate::Date.load 20121201
|
39
|
+
# => 2012-12-01
|
40
|
+
date.year
|
41
|
+
# => 2012
|
42
|
+
date.month
|
43
|
+
# => 12
|
44
|
+
date.day
|
45
|
+
# => 1
|
46
|
+
|
47
|
+
h2. Install
|
48
|
+
|
49
|
+
@$ gem install partial-date@
|
50
|
+
|
51
|
+
h2. TODO
|
52
|
+
|
53
|
+
Implement @PartialDate::Date.parse@ method for construction from strings.
|
54
|
+
|
55
|
+
h2. Copyright
|
56
|
+
|
57
|
+
Copyright (c) 2012 Anthony Bouch
|
58
|
+
|
59
|
+
See {file:LICENSE.txt} for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rake'
|
5
|
+
|
6
|
+
begin
|
7
|
+
gem 'rubygems-tasks', '~> 0.2'
|
8
|
+
require 'rubygems/tasks'
|
9
|
+
|
10
|
+
Gem::Tasks.new
|
11
|
+
rescue LoadError => e
|
12
|
+
warn e.message
|
13
|
+
warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
|
14
|
+
end
|
15
|
+
|
16
|
+
begin
|
17
|
+
gem 'rspec', '~> 2.4'
|
18
|
+
require 'rspec/core/rake_task'
|
19
|
+
|
20
|
+
RSpec::Core::RakeTask.new
|
21
|
+
rescue LoadError => e
|
22
|
+
task :spec do
|
23
|
+
abort "Please run `gem install rspec` to install RSpec."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
task :test => :spec
|
28
|
+
task :default => :spec
|
29
|
+
|
30
|
+
begin
|
31
|
+
gem 'yard', '~> 0.7'
|
32
|
+
require 'yard'
|
33
|
+
|
34
|
+
YARD::Rake::YardocTask.new
|
35
|
+
rescue LoadError => e
|
36
|
+
task :yard do
|
37
|
+
abort "Please run `gem install yard` to install YARD."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
task :doc => :yard
|
data/lib/partial-date.rb
ADDED
@@ -0,0 +1,209 @@
|
|
1
|
+
|
2
|
+
# Public module containing Date, Error and Version types.
|
3
|
+
module PartialDate
|
4
|
+
|
5
|
+
# Public: A class for handling partial date storage. Partial dates are stored
|
6
|
+
# as an 8 digit integer with optional month and day values.
|
7
|
+
#
|
8
|
+
# Examples
|
9
|
+
#
|
10
|
+
# date = PartialDate::Date.new
|
11
|
+
# date.year = 2012
|
12
|
+
# date.month = 12
|
13
|
+
# date.day = 1
|
14
|
+
#
|
15
|
+
# date = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 1}
|
16
|
+
#
|
17
|
+
# date = PartialDate::Date.new {|d| d.year = 2012 }
|
18
|
+
#
|
19
|
+
class Date
|
20
|
+
|
21
|
+
# Public: Create a new partial date class from a block of integers
|
22
|
+
# or strings.
|
23
|
+
#
|
24
|
+
# Examples
|
25
|
+
#
|
26
|
+
# # From integers
|
27
|
+
# date = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 1}
|
28
|
+
# date.value
|
29
|
+
# # => 20121201
|
30
|
+
#
|
31
|
+
# # From strings
|
32
|
+
# date = PartialDate::Date.new {|d| d.year = "2012"; d.month = "12"; d.day = "1"}
|
33
|
+
# date.value
|
34
|
+
# # => 20121201
|
35
|
+
#
|
36
|
+
# Returns a date object.
|
37
|
+
def initialize
|
38
|
+
yield self if block_given?
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# Public: Get the integer date value in partial date format.
|
43
|
+
#
|
44
|
+
# Examples
|
45
|
+
#
|
46
|
+
# date.year = "2012"
|
47
|
+
# date.value
|
48
|
+
# # => 20120000
|
49
|
+
#
|
50
|
+
# Returns an integer representation of a partial date.
|
51
|
+
def value
|
52
|
+
@value ||= 0
|
53
|
+
end
|
54
|
+
|
55
|
+
# Public: Set a date value using an interger in partial date format.
|
56
|
+
#
|
57
|
+
# Examples
|
58
|
+
#
|
59
|
+
# date.value = 20121200
|
60
|
+
#
|
61
|
+
# Returns nothing
|
62
|
+
def value=(value)
|
63
|
+
if value.is_a?(Integer) && (value >= 10000 && value <= 99991231)
|
64
|
+
@value = value
|
65
|
+
else
|
66
|
+
raise PartialDateError, "Date value must be an integer betwen 10000 and 99991231"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
# Public: Loads an 8 digit date value into a date object.
|
71
|
+
#
|
72
|
+
# value - an 8 digit value in partial date format.
|
73
|
+
#
|
74
|
+
# Examples
|
75
|
+
#
|
76
|
+
# date = PartialDate::Date.load 201212201
|
77
|
+
# date.value
|
78
|
+
# # => 20120000
|
79
|
+
# date.year
|
80
|
+
# # => 2012
|
81
|
+
# date.month
|
82
|
+
# # => 12
|
83
|
+
# date.day
|
84
|
+
# # => 0
|
85
|
+
#
|
86
|
+
# Returns date object
|
87
|
+
def self.load(value)
|
88
|
+
PartialDate::Date.new {|d| d.value = value}
|
89
|
+
end
|
90
|
+
|
91
|
+
|
92
|
+
# Public: Sets the year portion of a partial date.
|
93
|
+
#
|
94
|
+
# value - The string or integer value for a year.
|
95
|
+
#
|
96
|
+
# Examples
|
97
|
+
# date.year = "2000"
|
98
|
+
# date.value
|
99
|
+
# # => 20000000
|
100
|
+
#
|
101
|
+
# Returns nothing
|
102
|
+
def year=(value)
|
103
|
+
|
104
|
+
if value.nil?
|
105
|
+
raise PartialDateError, "Year cannot be nil"
|
106
|
+
end
|
107
|
+
|
108
|
+
if value.is_a?(String)
|
109
|
+
if value =~ /\A\d{4}\z/
|
110
|
+
value = value.to_i
|
111
|
+
else
|
112
|
+
raise PartialDateError, "Year must be a valid four digit string or integer between 1 and 9999"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
if value.is_a?(Integer) && (value <= 9999 && value > 0)
|
117
|
+
@value = (self.value - self.year) * 10000 + (value * 10000)
|
118
|
+
else
|
119
|
+
raise PartialDateError, "Year must be an integer between 1 and 9999"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
# Public: Get the year from a partial date.
|
124
|
+
def year
|
125
|
+
self.value > 9999 ? (self.value / 10000).abs : 0
|
126
|
+
end
|
127
|
+
|
128
|
+
# Public: Set the month of a partial date.
|
129
|
+
def month=(value)
|
130
|
+
|
131
|
+
raise PartialDateError, "A year must be set before a month" if year == 0
|
132
|
+
|
133
|
+
value = 0 if value.nil?
|
134
|
+
|
135
|
+
if value.is_a?(String)
|
136
|
+
if value =~ /\A\d{1,2}\z/
|
137
|
+
value = value.to_i
|
138
|
+
else
|
139
|
+
raise PartialDateError, "Month must be a valid one or two digit string or integer between 1 and 12"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
if value.is_a?(Integer) && (value <= 12 && value >= 0)
|
144
|
+
@value = self.value - (self.month * 100) + (value * 100)
|
145
|
+
else
|
146
|
+
raise PartialDateError, "Month must an be integer between 1 and 12"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# Public: Get the month from a partial date.
|
151
|
+
def month
|
152
|
+
self.value > 99 ? ((self.value - (self.value / 10000).abs * 10000) / 100).abs : 0
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
# Public: Set the day portion of a partial date. Day is optional so zero,
|
157
|
+
# nil and empty strings are allowed.
|
158
|
+
def day=(value)
|
159
|
+
|
160
|
+
raise PartialDateError, "A year and month must be set before a day" if year == 0 && month == 0
|
161
|
+
|
162
|
+
value = 0 if value.nil?
|
163
|
+
|
164
|
+
if value.is_a?(String)
|
165
|
+
if value =~ /\A\d{1,2}\z/
|
166
|
+
value = value.to_i
|
167
|
+
else
|
168
|
+
raise PartialDateError, "Day must be a valid one or two digit string or integer between 1 and 31"
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
if value.is_a?(Integer) && (value >= 0 && value <= 31)
|
173
|
+
begin
|
174
|
+
date = ::Date.civil(self.year, self.month, value) if value > 0
|
175
|
+
@value = (self.value - self.day + value)
|
176
|
+
rescue
|
177
|
+
raise PartialDateError, "Day must be a valid day for the given month"
|
178
|
+
end
|
179
|
+
else
|
180
|
+
raise PartialDateError, "Day must be an integer between 1 and 31"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
# Public: Get the day from a partial date.
|
185
|
+
def day
|
186
|
+
self.value > 0 ? self.value - (self.value / 100).abs * 100 : 0
|
187
|
+
end
|
188
|
+
|
189
|
+
# Public: Returns a formatted string representation of the partial date.
|
190
|
+
#
|
191
|
+
# Examples
|
192
|
+
#
|
193
|
+
# date = PartialDate::Date.new {|d| d.year = 2012, d.month = 12, d.day = 31}
|
194
|
+
# date.to_s
|
195
|
+
# # => "2012-12-31"
|
196
|
+
#
|
197
|
+
# Returns string representation of date.
|
198
|
+
def to_s
|
199
|
+
if self.year > 0
|
200
|
+
result = self.year.to_s
|
201
|
+
result = result + "-" + self.month.to_s if self.month > 0
|
202
|
+
result = result + "-" + self.day.to_s if self.day > 0
|
203
|
+
return result
|
204
|
+
else
|
205
|
+
return ""
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
require File.expand_path('../lib/partial-date/version', __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gem.name = "partial-date"
|
7
|
+
gem.version = PartialDate::VERSION
|
8
|
+
gem.summary = "A simple date class that can be used to store partial date values in a single column/attribute."
|
9
|
+
gem.description = "A simple date class that can be used to store partial date values in a single column/attribute. An example use case would include an archive, or catalogue entry where the complete date is unknown."
|
10
|
+
gem.license = "MIT"
|
11
|
+
gem.authors = ["Anthony Bouch"]
|
12
|
+
gem.email = ["tony@58bits.com"]
|
13
|
+
gem.homepage = "https://github.com/58bits/partial-date#readme"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rubygems-tasks", "~> 0.2"
|
21
|
+
gem.add_development_dependency "rspec", "~> 2.4"
|
22
|
+
gem.add_development_dependency "yard", "~> 0.7"
|
23
|
+
end
|
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'partial-date'
|
3
|
+
|
4
|
+
describe PartialDate::Date do
|
5
|
+
|
6
|
+
let(:date) { PartialDate::Date.new }
|
7
|
+
|
8
|
+
it "should have a VERSION constant" do
|
9
|
+
PartialDate.const_get('VERSION').should_not be_empty
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should have a readable value attribute" do
|
13
|
+
date.year = 2000
|
14
|
+
date.value.should == 20000000
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should allow construction from a block of integers" do
|
18
|
+
new_date = PartialDate::Date.new {|d| d.year = 2010; d.month = 12; d.day = 1}
|
19
|
+
new_date.value.should == 20101201
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should allow construction from a block of strings" do
|
23
|
+
new_date = PartialDate::Date.new {|d| d.year = "2010"; d.month = "12"; d.day = "1"}
|
24
|
+
new_date.value.should == 20101201
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should allow construction from the class load method" do
|
28
|
+
new_date = PartialDate::Date.load(20120000)
|
29
|
+
new_date.year.should == 2012
|
30
|
+
new_date.month.should == 0
|
31
|
+
new_date.day.should == 0
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should allow a date value in partial date format to be set in a date instance" do
|
35
|
+
new_date = PartialDate::Date.new {|d| d.value = 20120000}
|
36
|
+
new_date.year.should == 2012
|
37
|
+
new_date.month.should == 0
|
38
|
+
new_date.day.should == 0
|
39
|
+
new_date.value.should == 20120000
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not allow an invalid date value to be set in a date instance" do
|
43
|
+
expect {new_date = PartialDate::Date.new {|d| d.value = 100000000}}.to raise_error(PartialDate::PartialDateError, "Date value must be an integer betwen 10000 and 99991231")
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should return a string represntation of date in the correct format" do
|
47
|
+
new_date = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 31}
|
48
|
+
new_date.to_s.should match(/\A\d{4}-\d{2}-\d{2}\z/)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should return a string represntation of a partial date in the correct format" do
|
52
|
+
new_date = PartialDate::Date.new {|d| d.year = 2012; d.month = 12}
|
53
|
+
new_date.to_s.should match(/\A\d{4}-\d{2}\z/)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should return a string represntation of a partial date in the correct format" do
|
57
|
+
new_date = PartialDate::Date.new {|d| d.year = 2012}
|
58
|
+
new_date.to_s.should match(/\A\d{4}\z/)
|
59
|
+
end
|
60
|
+
|
61
|
+
describe "Year" do
|
62
|
+
it "should raise an error if year is set to nil" do
|
63
|
+
expect {date.year = nil}.to raise_error(PartialDate::PartialDateError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should raise an error if year is set to an invalid string" do
|
67
|
+
expect {date.year = "ABCD" }.to raise_error(PartialDate::PartialDateError, "Year must be a valid four digit string or integer between 1 and 9999")
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should raise an error if year is set to a five digit string" do
|
71
|
+
expect {date.year = "10000" }.to raise_error(PartialDate::PartialDateError, "Year must be a valid four digit string or integer between 1 and 9999")
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should raise an error if year is set to a value greater than 9999" do
|
75
|
+
expect {date.year = 10000 }.to raise_error(PartialDate::PartialDateError, "Year must be an integer between 1 and 9999")
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should raise an error if year is set to zero" do
|
79
|
+
expect {date.year = 0 }.to raise_error(PartialDate::PartialDateError, "Year must be an integer between 1 and 9999")
|
80
|
+
end
|
81
|
+
|
82
|
+
it "should raise an error if year is set to a value less than zero" do
|
83
|
+
expect {date.year = -1 }.to raise_error(PartialDate::PartialDateError, "Year must be an integer between 1 and 9999")
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should return a year when a year is set" do
|
87
|
+
date.year = 2050
|
88
|
+
date.year.should == 2050
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "Month" do
|
93
|
+
before(:each) { date.year = 2000 }
|
94
|
+
|
95
|
+
it "should raise an error if a month is set before a year" do
|
96
|
+
no_year = PartialDate::Date.new
|
97
|
+
expect {no_year.month = 10}.to raise_error(PartialDate::PartialDateError, "A year must be set before a month")
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should raise an error if month is set to an invalid string" do
|
101
|
+
expect {date.month = "AB"}.to raise_error(PartialDate::PartialDateError, "Month must be a valid one or two digit string or integer between 1 and 12")
|
102
|
+
end
|
103
|
+
|
104
|
+
it "should raise an error if month is set to a value greater than 12" do
|
105
|
+
expect {date.month = 13}.to raise_error(PartialDate::PartialDateError, "Month must an be integer between 1 and 12")
|
106
|
+
end
|
107
|
+
|
108
|
+
it "should raise an error if month is set to a value less than zero" do
|
109
|
+
expect {date.month = -1}.to raise_error(PartialDate::PartialDateError, "Month must an be integer between 1 and 12")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should allow the month to be set to zero" do
|
113
|
+
date.month = 0
|
114
|
+
date.month.should == 0
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should return zero if month is set to nil" do
|
118
|
+
date.month = nil
|
119
|
+
date.month.should == 0
|
120
|
+
end
|
121
|
+
|
122
|
+
it "should return a month when a month is set" do
|
123
|
+
date.month = 10
|
124
|
+
date.month.should == 10
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
describe "Day" do
|
129
|
+
before(:each) { date.year = 2000; date.month = 6 }
|
130
|
+
|
131
|
+
it "should raise an error if a day is set before a year and month" do
|
132
|
+
no_month = PartialDate::Date.new
|
133
|
+
expect {no_month.day = 10}.to raise_error(PartialDate::PartialDateError, "A year and month must be set before a day")
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should raise an error if day is set to an invalid string" do
|
137
|
+
expect {date.day = "AB"}.to raise_error(PartialDate::PartialDateError, "Day must be a valid one or two digit string or integer between 1 and 31")
|
138
|
+
end
|
139
|
+
|
140
|
+
it "should raise an error if day is set to a value less than zero" do
|
141
|
+
expect {date.day = -1}.to raise_error(PartialDate::PartialDateError, "Day must be an integer between 1 and 31")
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should raise an error if day is set to a value greater than 31" do
|
145
|
+
expect {date.day = 32}.to raise_error(PartialDate::PartialDateError, "Day must be an integer between 1 and 31")
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should raise an error if the day is an invalid day for the given month" do
|
149
|
+
expect {date.day = 31}.to raise_error(PartialDate::PartialDateError, "Day must be a valid day for the given month")
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should return zero when set to nil" do
|
153
|
+
date.day = nil
|
154
|
+
date.day.should == 0
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should allow the day to be set to zero" do
|
158
|
+
date.day = 0
|
159
|
+
date.day.should == 0
|
160
|
+
end
|
161
|
+
|
162
|
+
it "should return a day when a day is set" do
|
163
|
+
date.day = 10
|
164
|
+
date.day.should == 10
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: partial-date
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anthony Bouch
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-26 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rubygems-tasks
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0.2'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.4'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.4'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: yard
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.7'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.7'
|
62
|
+
description: A simple date class that can be used to store partial date values in
|
63
|
+
a single column/attribute. An example use case would include an archive, or catalogue
|
64
|
+
entry where the complete date is unknown.
|
65
|
+
email:
|
66
|
+
- tony@58bits.com
|
67
|
+
executables: []
|
68
|
+
extensions: []
|
69
|
+
extra_rdoc_files: []
|
70
|
+
files:
|
71
|
+
- .document
|
72
|
+
- .gitignore
|
73
|
+
- .rspec
|
74
|
+
- .yardopts
|
75
|
+
- ChangeLog.textile
|
76
|
+
- Guardfile
|
77
|
+
- LICENSE.txt
|
78
|
+
- README.textile
|
79
|
+
- Rakefile
|
80
|
+
- lib/partial-date.rb
|
81
|
+
- lib/partial-date/date.rb
|
82
|
+
- lib/partial-date/error.rb
|
83
|
+
- lib/partial-date/version.rb
|
84
|
+
- partial-date.gemspec
|
85
|
+
- spec/partial-date_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
87
|
+
homepage: https://github.com/58bits/partial-date#readme
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
102
|
+
requirements:
|
103
|
+
- - ! '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 1.8.23
|
109
|
+
signing_key:
|
110
|
+
specification_version: 3
|
111
|
+
summary: A simple date class that can be used to store partial date values in a single
|
112
|
+
column/attribute.
|
113
|
+
test_files:
|
114
|
+
- spec/partial-date_spec.rb
|
115
|
+
- spec/spec_helper.rb
|