partial-date 1.1.5 → 1.1.6

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.textile CHANGED
@@ -1,3 +1,8 @@
1
+ h3. 1.1.6 / 2012-05-30
2
+
3
+ * Bugfix: Checked that sign is switched off when a postive year is set after a negative year.
4
+ * Bugfix: Fixed to_s again (before formatters are implemented).
5
+
1
6
  h3. 1.1.5 / 2012-05-30
2
7
 
3
8
  * Allow negative years and year range from -1048576 to 1048576 (20 bits).
@@ -133,13 +133,12 @@ module PartialDate
133
133
  #
134
134
  # Returns nothing
135
135
  def year=(value)
136
-
137
136
  if value.nil?
138
137
  raise YearError, "Year cannot be nil"
139
138
  end
140
139
 
141
140
  if value.is_a?(String)
142
- if value =~ /\A\d{1,7}\z/
141
+ if value =~ /\A\-?\d{1,7}\z/
143
142
  value = value.to_i
144
143
  else
145
144
  raise YearError, "Year must be a valid string or integer from -1048576 to 1048576"
@@ -149,7 +148,7 @@ module PartialDate
149
148
  if value.is_a?(Integer) && (value >= -1048576 && value <= 1048576)
150
149
  @bits = self.class.set_year(@bits, value)
151
150
  else
152
- raise YearError, "Year must be an integer integer from -1048576 to 1048576"
151
+ raise YearError, "Year must be an integer from -1048576 to 1048576"
153
152
  end
154
153
  end
155
154
 
@@ -160,7 +159,6 @@ module PartialDate
160
159
 
161
160
  # Public: Set the month of a partial date.
162
161
  def month=(value)
163
-
164
162
  value = 0 if value.nil?
165
163
 
166
164
  if value.is_a?(String)
@@ -188,7 +186,6 @@ module PartialDate
188
186
  # Public: Set the day portion of a partial date. Day is optional so zero,
189
187
  # nil and empty strings are allowed.
190
188
  def day=(value)
191
-
192
189
  raise DayError, "A month must be set before a day" if month == 0
193
190
 
194
191
  value = 0 if value.nil?
@@ -228,14 +225,15 @@ module PartialDate
228
225
  #
229
226
  # Returns string representation of date.
230
227
  def to_s
231
- if year > 0
232
- result = year.to_s.rjust(4, '0')
233
- result = result + "-" + month.to_s.rjust(2, '0') if month > 0
228
+ result = ""
229
+ if value != 0
230
+ result = year.to_s.rjust(4, '0') if year != 0
231
+ result = result + "-" if result.length > 3
232
+ result = result + month.to_s.rjust(2, '0') if month > 0
234
233
  result = result + "-" + day.to_s.rjust(2, '0') if day > 0
235
234
  return result
236
- else
237
- return ""
238
235
  end
236
+ result
239
237
  end
240
238
 
241
239
  # Public: Spaceship operator for date comparisons. Comparisons are
@@ -283,6 +281,7 @@ module PartialDate
283
281
 
284
282
  def self.set_year(register, value)
285
283
  register = set_sign(register, 1) if value < 0
284
+ register = set_sign(register, 0) if value >= 0
286
285
  register = (register & ZERO_YEAR_MASK) | (value.abs << YEAR_SHIFT)
287
286
  end
288
287
 
@@ -1,4 +1,4 @@
1
1
  module PartialDate
2
2
  # partial-date version
3
- VERSION = "1.1.5"
3
+ VERSION = "1.1.6"
4
4
  end
data/spec/date_spec.rb CHANGED
@@ -92,7 +92,7 @@ describe PartialDate::Date do
92
92
  end
93
93
 
94
94
  it "should raise an error if year is set to a value greater than 1048576" do
95
- expect {date.year = 1048577 }.to raise_error(PartialDate::YearError, "Year must be an integer integer from -1048576 to 1048576")
95
+ expect {date.year = 1048577 }.to raise_error(PartialDate::YearError, "Year must be an integer from -1048576 to 1048576")
96
96
  end
97
97
 
98
98
  it "should return a postive year when a positive year is set" do
@@ -104,6 +104,16 @@ describe PartialDate::Date do
104
104
  date.year = -9999
105
105
  date.year.should == -9999
106
106
  end
107
+
108
+ it "should allow a valid string value" do
109
+ date.year = "2010"
110
+ date.year.should == 2010
111
+ end
112
+
113
+ it "should allow a negative value in a string" do
114
+ date.year = "-2010"
115
+ date.year.should == -2010
116
+ end
107
117
  end
108
118
 
109
119
  describe "Month" do
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.5
4
+ version: 1.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: