partial-date 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ChangeLog.textile +6 -0
- data/lib/partial-date/bits.rb +1 -1
- data/lib/partial-date/date.rb +26 -5
- data/lib/partial-date/version.rb +1 -1
- data/partial-date.gemspec +2 -2
- data/spec/date_spec.rb +44 -4
- data/spec/spec_helper.rb +2 -1
- metadata +2 -2
data/ChangeLog.textile
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
h3. 1.1.3 / 2012-05-28
|
2
|
+
|
3
|
+
* Bugfix: Fixed ZERO_DAY_MASK - which contained an extra bit, and was zeroing month when a day was set.
|
4
|
+
* Check that day is set to zero if month is.
|
5
|
+
* Added padding to string format for date.
|
6
|
+
|
1
7
|
h3. 1.1.2 / 2012-05-27
|
2
8
|
|
3
9
|
* Fixed syntax error in example code from README.
|
data/lib/partial-date/bits.rb
CHANGED
@@ -13,7 +13,7 @@ module PartialDate
|
|
13
13
|
|
14
14
|
ZERO_YEAR_MASK = 0b00000000000000111111111
|
15
15
|
ZERO_MONTH_MASK = 0b11111111111111000011111
|
16
|
-
ZERO_DAY_MASK =
|
16
|
+
ZERO_DAY_MASK = 0b11111111111111111000000
|
17
17
|
|
18
18
|
def self.get_date(register)
|
19
19
|
(get_year(register) * 10000) + (get_month(register) * 100) + get_day(register)
|
data/lib/partial-date/date.rb
CHANGED
@@ -145,6 +145,7 @@ module PartialDate
|
|
145
145
|
|
146
146
|
if value.is_a?(Integer) && (value <= 12 && value >= 0)
|
147
147
|
@bits = Bits.set_month(@bits, value)
|
148
|
+
@bits = Bits.set_day(@bits, 0) if value == 0
|
148
149
|
else
|
149
150
|
raise PartialDateError, "Month must an be integer between 1 and 12"
|
150
151
|
end
|
@@ -200,20 +201,40 @@ module PartialDate
|
|
200
201
|
# Returns string representation of date.
|
201
202
|
def to_s
|
202
203
|
if self.year > 0
|
203
|
-
result = self.year.to_s
|
204
|
-
result = result + "-" + self.month.to_s if self.month > 0
|
205
|
-
result = result + "-" + self.day.to_s if self.day > 0
|
204
|
+
result = self.year.to_s.rjust(4, '0')
|
205
|
+
result = result + "-" + self.month.to_s.rjust(2, '0') if self.month > 0
|
206
|
+
result = result + "-" + self.day.to_s.rjust(2, '0') if self.day > 0
|
206
207
|
return result
|
207
208
|
else
|
208
209
|
return ""
|
209
210
|
end
|
210
211
|
end
|
211
212
|
|
212
|
-
# Public: Spaceship operator for date comparisons.
|
213
|
+
# Public: Spaceship operator for date comparisons. Comparisons start
|
214
|
+
# with year, then month, then day - which are bitmask functions and
|
215
|
+
# faster than 'self.value' which requires math to produce the integer.
|
213
216
|
#
|
214
217
|
# Returns -1, 1, or 0
|
215
218
|
def <=>(other_date)
|
216
|
-
self.
|
219
|
+
if self.year < other_date.year
|
220
|
+
-1
|
221
|
+
elsif self.year > other_date.year
|
222
|
+
1
|
223
|
+
else
|
224
|
+
if self.month < other_date.month
|
225
|
+
-1
|
226
|
+
elsif self.month > other_date.month
|
227
|
+
1
|
228
|
+
else
|
229
|
+
if self.day < other_date.day
|
230
|
+
-1
|
231
|
+
elsif self.day > other_date.day
|
232
|
+
1
|
233
|
+
else
|
234
|
+
0
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
217
238
|
end
|
218
239
|
end
|
219
240
|
end
|
data/lib/partial-date/version.rb
CHANGED
data/partial-date.gemspec
CHANGED
@@ -5,8 +5,8 @@ require File.expand_path('../lib/partial-date/version', __FILE__)
|
|
5
5
|
Gem::Specification.new do |gem|
|
6
6
|
gem.name = "partial-date"
|
7
7
|
gem.version = PartialDate::VERSION
|
8
|
-
gem.summary =
|
9
|
-
gem.description =
|
8
|
+
gem.summary = %q{A simple date class that can be used to store partial date values in a single column/attribute.}
|
9
|
+
gem.description = %q{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
10
|
gem.license = "MIT"
|
11
11
|
gem.authors = ["Anthony Bouch"]
|
12
12
|
gem.email = ["tony@58bits.com"]
|
data/spec/date_spec.rb
CHANGED
@@ -9,6 +9,10 @@ describe PartialDate::Date do
|
|
9
9
|
PartialDate.const_get('VERSION').should_not be_empty
|
10
10
|
end
|
11
11
|
|
12
|
+
it "should return an empty string for an empty date" do
|
13
|
+
date.to_s.should == ""
|
14
|
+
end
|
15
|
+
|
12
16
|
it "should have a readable value attribute" do
|
13
17
|
date.year = 2000
|
14
18
|
date.value.should == 20000000
|
@@ -166,19 +170,55 @@ describe PartialDate::Date do
|
|
166
170
|
end
|
167
171
|
|
168
172
|
describe "Comparisons" do
|
169
|
-
it "should determine if one date is greater than another" do
|
173
|
+
it "should determine if one date is greater than another based on year" do
|
174
|
+
a = PartialDate::Date.new {|d| d.year = 2013; }
|
175
|
+
b = PartialDate::Date.new {|d| d.year = 2012; }
|
176
|
+
a.should be > b
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should determine if one date is less than another based on year" do
|
180
|
+
a = PartialDate::Date.new {|d| d.year = 2011; }
|
181
|
+
b = PartialDate::Date.new {|d| d.year = 2012; }
|
182
|
+
a.should be < b
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should determine if one date is equal to another based on year" do
|
186
|
+
a = PartialDate::Date.new {|d| d.year = 2012; }
|
187
|
+
b = PartialDate::Date.new {|d| d.year = 2012; }
|
188
|
+
a.should be == b
|
189
|
+
end
|
190
|
+
|
191
|
+
it "should determine if one date is greater than another based on month" do
|
192
|
+
a = PartialDate::Date.new {|d| d.year = 2012; d.month = 11; }
|
193
|
+
b = PartialDate::Date.new {|d| d.year = 2012; d.month = 10 }
|
194
|
+
a.should be > b
|
195
|
+
end
|
196
|
+
|
197
|
+
it "should determine if one date is less than another based on month" do
|
198
|
+
a = PartialDate::Date.new {|d| d.year = 2012; d.month = 9; }
|
199
|
+
b = PartialDate::Date.new {|d| d.year = 2012; d.month = 10 }
|
200
|
+
a.should be < b
|
201
|
+
end
|
202
|
+
|
203
|
+
it "should determine if one date is equal to another based on month" do
|
204
|
+
a = PartialDate::Date.new {|d| d.year = 2012; d.month = 10; }
|
205
|
+
b = PartialDate::Date.new {|d| d.year = 2012; d.month = 10 }
|
206
|
+
a.should be == b
|
207
|
+
end
|
208
|
+
|
209
|
+
it "should determine if one date is greater than another based on day" do
|
170
210
|
a = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 31}
|
171
211
|
b = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 30}
|
172
212
|
a.should be > b
|
173
213
|
end
|
174
214
|
|
175
|
-
it "should determine if one date is less than another" do
|
176
|
-
a = PartialDate::Date.new {|d| d.year = 2012; d.month =
|
215
|
+
it "should determine if one date is less than another based on day" do
|
216
|
+
a = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 29}
|
177
217
|
b = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 30}
|
178
218
|
a.should be < b
|
179
219
|
end
|
180
220
|
|
181
|
-
it "should determine if one date is equal to another" do
|
221
|
+
it "should determine if one date is equal to another based on day" do
|
182
222
|
a = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 30}
|
183
223
|
b = PartialDate::Date.new {|d| d.year = 2012; d.month = 12; d.day = 30}
|
184
224
|
a.should be == b
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: partial-date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubygems-tasks
|