partial-date 1.2.1 → 1.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/ChangeLog.markdown CHANGED
@@ -1,3 +1,6 @@
1
+ ### 1.2.2 / 2013-01-27
2
+ * Added aditional guards against empty strings for year, month, day.
3
+
1
4
  ### 1.2.1 / 2012-10-05
2
5
  * Bugfix: Merged pull request and bugfix for zero day mask. Thank you Alexander Gräfe. https://github.com/rickenharp
3
6
 
@@ -186,14 +186,16 @@ module PartialDate
186
186
  value = 0 if value.nil?
187
187
 
188
188
  if value.is_a?(String)
189
- if value =~ /\A\-?\d{1,7}\z/
189
+ if value.length == 0
190
+ value = 0
191
+ elsif value =~ /\A\-?\d{1,7}\z/
190
192
  value = value.to_i
191
193
  else
192
194
  raise YearError, "Year must be a valid string or integer from -1048576 to 1048576"
193
195
  end
194
196
  end
195
197
 
196
- if value.is_a?(Integer) && (value >= -1048576 && value <= 1048576)
198
+ if (value >= -1048576 && value <= 1048576)
197
199
  @bits = self.class.set_year(@bits, value)
198
200
  else
199
201
  raise YearError, "Year must be an integer from -1048576 to 1048576"
@@ -210,14 +212,16 @@ module PartialDate
210
212
  value = 0 if value.nil?
211
213
 
212
214
  if value.is_a?(String)
213
- if value =~ /\A\d{1,2}\z/
215
+ if value.length == 0
216
+ value = 0
217
+ elsif value =~ /\A\d{1,2}\z/
214
218
  value = value.to_i
215
219
  else
216
220
  raise MonthError, "Month must be a valid one or two digit string or integer between 0 and 12"
217
221
  end
218
222
  end
219
223
 
220
- if value.is_a?(Integer) && (value >= 0 && value <= 12)
224
+ if (value >= 0 && value <= 12)
221
225
  @bits = self.class.set_month(@bits, value)
222
226
  @bits = self.class.set_day(@bits, 0) if value == 0
223
227
  else
@@ -236,17 +240,18 @@ module PartialDate
236
240
  def day=(value)
237
241
  value = 0 if value.nil?
238
242
 
239
- raise DayError, "A month must be set before a day" if month == 0 && value !=0
240
-
241
243
  if value.is_a?(String)
242
- if value =~ /\A\d{1,2}\z/
244
+ if value.length == 0
245
+ value = 0
246
+ elsif value =~ /\A\d{1,2}\z/
243
247
  value = value.to_i
244
248
  else
245
249
  raise DayError, "Day must be a valid one or two digit string or integer between 0 and 31"
246
250
  end
247
251
  end
248
252
 
249
- if value.is_a?(Integer) && (value >= 0 && value <= 31)
253
+ if (value >= 0 && value <= 31)
254
+ raise DayError, "A month must be set before a day" if month == 0 && value !=0
250
255
  begin
251
256
  date = ::Date.civil(self.year, self.month, value) if value > 0
252
257
  @bits = self.class.set_day(@bits, value)
@@ -1,4 +1,4 @@
1
1
  module PartialDate
2
2
  # partial-date version
3
- VERSION = "1.2.1"
3
+ VERSION = "1.2.2"
4
4
  end
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.2.1
4
+ version: 1.2.2
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-10-05 00:00:00.000000000 Z
12
+ date: 2013-01-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rubygems-tasks
@@ -109,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
109
109
  version: '0'
110
110
  requirements: []
111
111
  rubyforge_project:
112
- rubygems_version: 1.8.23
112
+ rubygems_version: 1.8.25
113
113
  signing_key:
114
114
  specification_version: 3
115
115
  summary: A simple date class that can be used to store partial date values in a single