fuzzy_date 0.8.3 → 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README +20 -33
- data/lib/fuzzy_date.rb +151 -132
- data/test/test_fuzzy_date.rb +10 -10
- metadata +26 -41
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d8e21583d0f942c6c5528a5a265e70b0ab2c07c67b25574e37588c8a6f48b8dd
|
4
|
+
data.tar.gz: e188f5303312dd8f097e1755540a0854caaa87cb01ad20c7ebf706bfc4296a55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 675b22fd8f9693427c47a2dd451b88b2b2cfc005ff1e80463f3c8cf5de7fd72f17d0b75a21a63f27a80f3551b07c333c2a63d639751978db0c4bfafbd52eb4c6
|
7
|
+
data.tar.gz: 0c2ecc1bcb5377e7964f8b6f9948451ad7169386d184eb20da3471c67dec371384a927e91813f90a505e728e7e95232a495fce87b0add127689470247951f281
|
data/README
CHANGED
@@ -1,57 +1,44 @@
|
|
1
|
-
Routines to manage the FuzzyDate Class. There is also an extension to the
|
1
|
+
Routines to manage the FuzzyDate Class. There is also an extension to the
|
2
2
|
ActiveRecord::Base class to provide an 'acts_as_fuzzy_date' class method.
|
3
|
-
|
4
|
-
Historical dates are often incomplete or approximate and this class allows
|
3
|
+
|
4
|
+
Historical dates are often incomplete or approximate and this class allows
|
5
5
|
such dates to be worked with and stored on a database.
|
6
|
-
|
6
|
+
|
7
7
|
construct a new object with FuzzyDate.new( year,month,day,wday,circa)
|
8
8
|
year: optional..is the year number 0 .. big as you like, -ve for BCE
|
9
9
|
month: optional.. is month number 1..12, or nil
|
10
10
|
day: optional.. is day number 1-31 or nil
|
11
11
|
wday: optional.. day of the week - 0=Sunday .. 6=Saturday
|
12
|
-
circa: true =
|
13
|
-
|
12
|
+
circa: true = day is approx, or nil/false
|
13
|
+
|
14
14
|
note that if you supply the weekday and a year/month/day the system will
|
15
15
|
use your weekday as supplied even if this does not actually correspond
|
16
16
|
in reality to the date supplied.
|
17
|
-
|
17
|
+
|
18
18
|
construct a new object with FuzzyDate.parse("date_string")
|
19
19
|
date_string = eg: "tuesday"
|
20
20
|
"12 nov 1012"
|
21
21
|
"circa 412 bc"
|
22
|
-
|
22
|
+
|
23
23
|
Use in a database table by storing in an integer field of a format large
|
24
24
|
enough to hold the digits of your maximum year + 8. Eg. a BIGNUM field
|
25
25
|
stores 19 useful characters allowing the year to go to 99,999,999,999.
|
26
26
|
ie 99 billion years.
|
27
|
-
|
27
|
+
|
28
28
|
Use with an ActiveRecord class ..
|
29
|
-
|
29
|
+
|
30
30
|
require 'fuzzy_date'
|
31
31
|
|
32
32
|
class HistoricalPerson < ActiveRecord::Base
|
33
33
|
acts_as_fuzzy_date : birth_date, death_date
|
34
34
|
end
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
permit persons to whom the Software is furnished to do so, subject to
|
46
|
-
the following conditions:
|
47
|
-
|
48
|
-
The above copyright notice and this permission notice shall be
|
49
|
-
included in all copies or substantial portions of the Software.
|
50
|
-
|
51
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
52
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
54
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
55
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
56
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
57
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
Copyright (c) Clive Andrews / Reality Bites 2008, 2009, 2010, 2020
|
39
|
+
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
41
|
+
|
42
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
43
|
+
|
44
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/fuzzy_date.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
################################################################################
|
2
4
|
#
|
3
|
-
# Routines to manage the FuzzyDate Class. There is also an extension to the
|
5
|
+
# Routines to manage the FuzzyDate Class. There is also an extension to the
|
4
6
|
# ActiveRecord::Base class to provide an 'acts_as_fuzzy_date' class method.
|
5
7
|
#--
|
6
|
-
# Copyright (c) Clive Andrews / Reality Bites 2008, 2009, 2010
|
8
|
+
# Copyright (c) Clive Andrews / Reality Bites 2008, 2009, 2010, 2020
|
7
9
|
#
|
8
10
|
# Permission is hereby granted, free of charge, to any person obtaining
|
9
11
|
# a copy of this software and associated documentation files (the
|
@@ -26,105 +28,92 @@
|
|
26
28
|
#
|
27
29
|
# version 20100224-1
|
28
30
|
# ++
|
29
|
-
#
|
31
|
+
#
|
30
32
|
################################################################################
|
31
33
|
require 'date'
|
32
34
|
|
33
|
-
|
34
35
|
# A fuzzy date is a representation of a date which may well be incomplete
|
35
36
|
# or imprecise. You can enter the exact date or for example just the day of
|
36
37
|
# the week or the year or a combination thereof. One can also add the Circa
|
37
|
-
# prefix to any date. The FuzzyDate object is immutable so if you wish to
|
38
|
+
# prefix to any date. The FuzzyDate object is immutable so if you wish to
|
38
39
|
# change a FuzzyDate value it is neccessary to create a new FuzzyDate.
|
39
40
|
class FuzzyDate
|
40
|
-
|
41
|
+
|
41
42
|
include Comparable
|
42
|
-
|
43
|
-
#
|
44
|
-
#
|
45
|
-
class FDate < Date # :nodoc:
|
46
|
-
def self._parse_year(str, e)
|
47
|
-
if str.sub!(/(\d{3,})\b/in, ' ')
|
48
|
-
e.year = $1.to_i
|
49
|
-
true
|
50
|
-
else
|
51
|
-
super(str,e)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end # FDate
|
55
|
-
|
56
|
-
# create a new FuzzyDate object. There are no checks here to
|
57
|
-
# validate if the date is valid or not.. eg there is no check
|
43
|
+
|
44
|
+
# create a new FuzzyDate object. There are no checks here to
|
45
|
+
# validate if the date is valid or not.. eg there is no check
|
58
46
|
# that the day of the week actually corresponds to the actual
|
59
47
|
# date if completely specified.
|
60
|
-
def initialize(year=nil,month=nil,day=nil,wday=nil,circa=nil)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
48
|
+
def initialize(year = nil, month = nil, day = nil, wday = nil, circa = nil)
|
49
|
+
|
50
|
+
year = year && Integer(year)
|
51
|
+
month = month && Integer(month)
|
52
|
+
day = day && Integer(day)
|
53
|
+
wday = wday && Integer(wday)
|
54
|
+
|
55
|
+
raise ArgumentError, 'invalid month' if month && ((month > 12) || (month < 1))
|
56
|
+
raise ArgumentError, 'invalid day' if day && ((day > 31) || (day < 1))
|
57
|
+
raise ArgumentError, 'invalid weekday' if wday && ((wday > 6) || (wday < 0))
|
58
|
+
raise ArgumentError, 'year too big !' if year && (year.abs > 99_999_999_999)
|
59
|
+
|
60
|
+
@year = year&.abs
|
66
61
|
@month = month
|
67
62
|
@day = day
|
68
63
|
@wday = wday
|
69
64
|
@circa = circa
|
70
|
-
@bce = year && (year
|
65
|
+
@bce = year && (year < 0)
|
71
66
|
end
|
72
|
-
|
67
|
+
|
73
68
|
# returns an integer representing the day of the week, 0..6
|
74
|
-
# with Sunday=0. returns nil if not known.
|
75
|
-
def wday
|
76
|
-
if !@wday && complete? &&
|
69
|
+
# with Sunday=0. returns nil if not known.
|
70
|
+
def wday
|
71
|
+
if !@wday && complete? && !bce?
|
77
72
|
to_date.wday
|
78
73
|
else
|
79
74
|
@wday
|
80
75
|
end
|
81
76
|
end
|
82
|
-
|
77
|
+
|
83
78
|
# returns the day of the month ( 1..n ). returns nil if not known.
|
84
|
-
|
85
|
-
|
86
|
-
end
|
87
|
-
|
79
|
+
attr_reader :day
|
80
|
+
|
88
81
|
# returns the month number (1..12). returns nil if not known.
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
|
82
|
+
attr_reader :month
|
83
|
+
|
93
84
|
# returns the year number (including century)
|
94
|
-
|
95
|
-
|
96
|
-
end
|
97
|
-
|
85
|
+
attr_reader :year
|
86
|
+
|
98
87
|
# is the date approximate ?
|
99
88
|
def circa?
|
100
|
-
|
89
|
+
!!@circa
|
101
90
|
end
|
102
|
-
|
91
|
+
|
103
92
|
# is the date before the year zero.
|
104
93
|
def bce?
|
105
|
-
|
94
|
+
!!@bce
|
106
95
|
end
|
107
|
-
|
96
|
+
|
108
97
|
# return an integer representing only the month and day
|
109
98
|
def birthday
|
110
99
|
month * 100 + day if month && day
|
111
100
|
end
|
112
|
-
|
101
|
+
|
113
102
|
# is the date complete
|
114
103
|
def complete?
|
115
|
-
year && (month
|
104
|
+
!!(year && (month && month < 13) && (day && day < 32))
|
116
105
|
end
|
117
|
-
|
106
|
+
|
118
107
|
# is the date completely unknown
|
119
108
|
def unknown?
|
120
109
|
!@year && !@month && !@day && !@wday
|
121
110
|
end
|
122
|
-
|
111
|
+
|
123
112
|
# convert to integer format
|
124
113
|
def to_i
|
125
114
|
to_db
|
126
115
|
end
|
127
|
-
|
116
|
+
|
128
117
|
# convert the fuzzy date into a format which can be stored in a database. The
|
129
118
|
# storage format is integer format (BIGINT) with digits having the following positional
|
130
119
|
# significance:
|
@@ -144,127 +133,153 @@ class FuzzyDate
|
|
144
133
|
# this wierd format has been chosen to allow sorting within the database and to
|
145
134
|
# avoid leading zeros containing information from being stripped from the representation.
|
146
135
|
#
|
147
|
-
# save in a mysql database in format BIGINT
|
136
|
+
# save in a mysql database in format BIGINT
|
148
137
|
#
|
149
138
|
def to_db
|
150
|
-
str =
|
151
|
-
str
|
152
|
-
str
|
153
|
-
str
|
154
|
-
str
|
155
|
-
str
|
156
|
-
str
|
139
|
+
str = String.new
|
140
|
+
str += (@year > 0 ? @year.to_s : '') if @year
|
141
|
+
str += (@month ? '%02d' % @month.to_s : '13')
|
142
|
+
str += (@day ? '%02d' % @day.to_s : '32')
|
143
|
+
str += (@wday ? (@wday + 1).to_s : '8')
|
144
|
+
str += (@year ? '0' : '1')
|
145
|
+
str += (@circa ? '1' : '0')
|
157
146
|
i = str.to_i
|
158
147
|
i = -i if @bce
|
159
148
|
i
|
160
149
|
end
|
161
|
-
|
150
|
+
|
162
151
|
# create a new FuzzyDate object from the database formatted
|
163
152
|
# integer.
|
164
153
|
def self.new_from_db(i)
|
165
154
|
return nil unless i
|
155
|
+
|
166
156
|
str = i.to_s
|
167
157
|
return nil if str == '0'
|
158
|
+
|
168
159
|
bce = false
|
169
|
-
raise "Invalid Fuzzy Time String - #{str}" unless str
|
170
|
-
|
171
|
-
str
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
160
|
+
raise "Invalid Fuzzy Time String - #{str}" unless str =~ /^[+-]?\d{6,}$/
|
161
|
+
|
162
|
+
str.sub!(/^-/) { |_m| bce = true; '' }
|
163
|
+
str = ('000000' + str)[-7, 7] if str.length < 7
|
164
|
+
circa = (str[-1, 1] == '1')
|
165
|
+
year = (str[-2, 1] == '1' ? nil : 0)
|
166
|
+
wday = str[-3, 1].to_i - 1
|
167
|
+
day = str[-5, 2].to_i
|
168
|
+
month = str[-7, 2].to_i
|
169
|
+
wday = nil if (wday < 0) || (wday > 6)
|
170
|
+
day = nil if (day == 0) || (day > 31)
|
171
|
+
month = nil if (month == 0) || (month > 12)
|
172
|
+
year = (str[0..-8].to_i > 0 ? str[0..-8].to_i : year)
|
181
173
|
year = -year if year && bce
|
182
|
-
new(year,month,day,wday,circa)
|
174
|
+
new(year, month, day, wday, circa)
|
183
175
|
end
|
184
|
-
|
176
|
+
|
185
177
|
# convert to a human readable string
|
186
178
|
def to_s
|
187
179
|
if unknown?
|
188
|
-
str =
|
180
|
+
str = 'unknown'
|
189
181
|
else
|
190
|
-
str =
|
191
|
-
str =
|
192
|
-
str+=
|
193
|
-
str+= day.to_s +
|
194
|
-
str+=
|
195
|
-
str+= year.to_s if year
|
196
|
-
str +=
|
182
|
+
str = ''
|
183
|
+
str = 'circa ' if circa?
|
184
|
+
str += Date::DAYNAMES[wday] + ' ' if wday
|
185
|
+
str += day.to_s + ' ' if day
|
186
|
+
str += Date::MONTHNAMES[month] + ' ' if month
|
187
|
+
str += year.to_s if year
|
188
|
+
str += ' bce' if bce?
|
197
189
|
str.strip
|
198
190
|
end
|
199
191
|
end
|
200
|
-
|
192
|
+
|
201
193
|
# if the date is complete then return a regular
|
202
194
|
# Date object
|
203
195
|
def to_date
|
204
|
-
|
205
|
-
Date.new(@year,@month,@day)
|
196
|
+
Date.new(@year, @month, @day) if complete?
|
206
197
|
end
|
207
|
-
|
198
|
+
|
208
199
|
# create a FuzzyDate object from a Date object
|
209
|
-
def self.new_from_date(
|
210
|
-
new(date.year,date.month,date.day)
|
200
|
+
def self.new_from_date(date)
|
201
|
+
new(date.year, date.month, date.day)
|
211
202
|
end
|
212
|
-
|
203
|
+
|
213
204
|
# create a new date object by parsing a string
|
214
|
-
def self.parse(
|
215
|
-
|
216
|
-
|
217
|
-
|
205
|
+
def self.parse(str)
|
206
|
+
return unless str # && str.length > 0
|
207
|
+
|
208
|
+
str = str.strip
|
209
|
+
|
210
|
+
return new if str == ''
|
211
|
+
|
218
212
|
continue = true
|
219
213
|
circa = false
|
220
214
|
bce = false
|
221
215
|
unknown = false
|
222
|
-
|
223
|
-
#filter out 'c' or 'circa'
|
224
|
-
str.sub!(/CIRCA/i){|
|
225
|
-
str.sub!(/^CA /i){|
|
226
|
-
str.sub!(/^C /i){|
|
227
|
-
str.sub!(/ABOUT/i){|
|
228
|
-
str.sub!(/AROUND/i){|
|
229
|
-
str.sub!(/ROUND/i){|
|
230
|
-
str.sub!(/APPROX/i){|
|
231
|
-
str.sub!(/APPROXIMATELY/i){|
|
232
|
-
|
233
|
-
#filter out 'bc' 'bce'
|
216
|
+
|
217
|
+
# filter out 'c' or 'circa'
|
218
|
+
str.sub!(/CIRCA/i) { |_m| circa = true; continue = nil } if continue
|
219
|
+
str.sub!(/^CA /i) { |_m| circa = true; continue = nil } if continue
|
220
|
+
str.sub!(/^C /i) { |_m| circa = true; continue = nil } if continue
|
221
|
+
str.sub!(/ABOUT/i) { |_m| circa = true; continue = nil } if continue
|
222
|
+
str.sub!(/AROUND/i) { |_m| circa = true; continue = nil } if continue
|
223
|
+
str.sub!(/ROUND/i) { |_m| circa = true; continue = nil } if continue
|
224
|
+
str.sub!(/APPROX/i) { |_m| circa = true; continue = nil } if continue
|
225
|
+
str.sub!(/APPROXIMATELY/i) { |_m| circa = true; continue = nil } if continue
|
226
|
+
|
227
|
+
# filter out 'bc' 'bce'
|
234
228
|
continue = true
|
235
|
-
str.sub!(/BCE/i){|
|
236
|
-
str.sub!(/BC/i){|
|
237
|
-
|
238
|
-
#filter out 'unknown'
|
229
|
+
str.sub!(/BCE/i) { |_m| bce = true; continue = nil }
|
230
|
+
str.sub!(/BC/i) { |_m| bce = true; continue = nil } if continue
|
231
|
+
|
232
|
+
# filter out 'unknown'
|
239
233
|
continue = true
|
240
|
-
str.sub!(/UNKNOWN/i){|
|
241
|
-
|
234
|
+
str.sub!(/UNKNOWN/i) { |_m| unknown = true; continue = nil }
|
235
|
+
|
242
236
|
# if date is unknown then return an empty FuzzyDate
|
243
|
-
return
|
244
|
-
|
237
|
+
return new if unknown
|
238
|
+
|
245
239
|
# now try to parse the remaining string with the Date parse
|
246
240
|
# method.
|
247
|
-
|
248
|
-
components=
|
249
|
-
|
241
|
+
|
242
|
+
components = case str
|
243
|
+
when /^(\d+)$/ then {:year=>Integer($1)}
|
244
|
+
when /^(\w+)\s+(\d+)$/
|
245
|
+
if Integer($2) > 31
|
246
|
+
Date._parse($1, false).merge( :year=>Integer($2) )
|
247
|
+
else
|
248
|
+
Date._parse(str, false)
|
249
|
+
end
|
250
|
+
else
|
251
|
+
Date._parse(str, false)
|
252
|
+
end
|
253
|
+
|
254
|
+
year = components[:year]
|
250
255
|
month = components[:mon]
|
251
256
|
day = components[:mday]
|
252
257
|
wday = components[:wday]
|
253
|
-
|
258
|
+
|
254
259
|
# fudge the results a bit
|
255
|
-
|
256
|
-
|
260
|
+
if (day && !month && !year) || (!year && (day.to_i > 31))
|
261
|
+
year = day
|
262
|
+
day = nil
|
263
|
+
end
|
264
|
+
if year && year < 0
|
257
265
|
year = year.abs
|
258
266
|
bce = true
|
259
267
|
end
|
260
|
-
|
268
|
+
|
261
269
|
year = -year if bce
|
262
|
-
|
270
|
+
new(year, month, day, wday, circa)
|
271
|
+
end
|
272
|
+
|
273
|
+
def _dump
|
274
|
+
p self
|
275
|
+
self
|
263
276
|
end
|
264
|
-
|
265
|
-
def <=>(other)
|
266
|
-
|
267
|
-
end
|
277
|
+
|
278
|
+
def <=>(other)
|
279
|
+
to_db <=> other.to_db
|
280
|
+
end
|
281
|
+
|
282
|
+
end # class FuzzyDate
|
268
283
|
|
269
284
|
# add an acts_as_fuzzy_date helper to ActiveRecord to define
|
270
285
|
# a table field as a FuzzyDate.
|
@@ -279,14 +294,16 @@ end #class FuzzyDate
|
|
279
294
|
#
|
280
295
|
if defined? ActiveRecord::Base
|
281
296
|
class ActiveRecord::Base
|
297
|
+
|
282
298
|
class << self
|
299
|
+
|
283
300
|
def acts_as_fuzzy_date(*args)
|
284
301
|
args.each do |name|
|
285
|
-
str
|
302
|
+
str = <<-EOF
|
286
303
|
def #{name}
|
287
304
|
FuzzyDate.new_from_db(self['#{name}'])
|
288
305
|
end
|
289
|
-
|
306
|
+
|
290
307
|
def #{name}=(s)
|
291
308
|
if s.kind_of? String
|
292
309
|
self['#{name}'] = FuzzyDate.parse(s).to_db unless s.strip.empty?
|
@@ -296,10 +313,12 @@ if defined? ActiveRecord::Base
|
|
296
313
|
self['#{name}'] = nil
|
297
314
|
end
|
298
315
|
end
|
299
|
-
EOF
|
316
|
+
EOF
|
300
317
|
class_eval str
|
301
318
|
end
|
302
319
|
end
|
320
|
+
|
303
321
|
end
|
322
|
+
|
304
323
|
end
|
305
324
|
end
|
data/test/test_fuzzy_date.rb
CHANGED
@@ -77,18 +77,18 @@ class TestItem < Test::Unit::TestCase
|
|
77
77
|
assert ( !d1.circa?)
|
78
78
|
assert ( !d1.unknown?)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
def test_database
|
82
|
-
10000.times do
|
82
|
+
10000.times do
|
83
83
|
d = make_fuzzy_date
|
84
|
-
puts d.to_s
|
84
|
+
#puts d.to_s
|
85
85
|
i = d.to_i
|
86
86
|
i = i * 1 # reformat ?
|
87
87
|
d2 = FuzzyDate.new_from_db( i )
|
88
88
|
assert_equal( d.to_i, d2.to_i)
|
89
89
|
end
|
90
90
|
end
|
91
|
-
|
91
|
+
|
92
92
|
def test_compare
|
93
93
|
assert( FuzzyDate.parse("23 april 2000") == FuzzyDate.parse("23 april 2000") )
|
94
94
|
assert( FuzzyDate.parse("24 april 2000") > FuzzyDate.parse("23 april 2000") )
|
@@ -96,7 +96,7 @@ class TestItem < Test::Unit::TestCase
|
|
96
96
|
assert( FuzzyDate.parse("jan 2001") > FuzzyDate.parse("dec 2000") )
|
97
97
|
assert( FuzzyDate.parse("sept") > FuzzyDate.parse("july") )
|
98
98
|
end
|
99
|
-
|
99
|
+
|
100
100
|
# generate a random fuzzy date
|
101
101
|
def make_fuzzy_date
|
102
102
|
# 1 2 3 4 5 6 7 8 9 10 11 12
|
@@ -107,11 +107,11 @@ class TestItem < Test::Unit::TestCase
|
|
107
107
|
day = rand(tab[month-1]) + 1
|
108
108
|
circa = rand(4) == 0
|
109
109
|
bce = rand(2) == 0
|
110
|
-
do_year = rand(3) > 0
|
111
|
-
do_month = rand(3) > 0
|
112
|
-
do_day = rand(3) > 0
|
113
|
-
do_wday = rand(3) > 0
|
114
|
-
|
110
|
+
do_year = true if rand(3) > 0
|
111
|
+
do_month = true if rand(3) > 0
|
112
|
+
do_day = true if rand(3) > 0
|
113
|
+
do_wday = true if rand(3) > 0
|
114
|
+
|
115
115
|
year = - year if bce
|
116
116
|
FuzzyDate.new( do_year && year,
|
117
117
|
do_month && month,
|
metadata
CHANGED
@@ -1,63 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuzzy_date
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
segments:
|
6
|
-
- 0
|
7
|
-
- 8
|
8
|
-
- 3
|
9
|
-
version: 0.8.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.1
|
10
5
|
platform: ruby
|
11
|
-
authors:
|
6
|
+
authors:
|
12
7
|
- Clive Andrews
|
13
8
|
autorequire:
|
14
9
|
bindir: bin
|
15
10
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2010-02-24 00:00:00 +01:00
|
18
|
-
default_executable:
|
11
|
+
date: 2010-02-24 00:00:00.000000000 Z
|
19
12
|
dependencies: []
|
20
|
-
|
21
13
|
description: FuzzyDate is a Ruby class for working with incomplete dates.
|
22
14
|
email: pacman@realitybites.eu
|
23
15
|
executables: []
|
24
|
-
|
25
16
|
extensions: []
|
26
|
-
|
27
17
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
18
|
+
files:
|
30
19
|
- README
|
31
20
|
- lib/fuzzy_date.rb
|
32
|
-
|
21
|
+
- test/test_fuzzy_date.rb
|
33
22
|
homepage: http://site.realitybites.eu/content/fuzzy_date
|
34
|
-
licenses:
|
35
|
-
|
23
|
+
licenses:
|
24
|
+
- MIT
|
25
|
+
metadata: {}
|
36
26
|
post_install_message:
|
37
|
-
rdoc_options:
|
38
|
-
- --charset=UTF-8
|
39
|
-
require_paths:
|
27
|
+
rdoc_options:
|
28
|
+
- "--charset=UTF-8"
|
29
|
+
require_paths:
|
40
30
|
- lib
|
41
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
-
requirements:
|
31
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
43
33
|
- - ">="
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
-
requirements:
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
50
38
|
- - ">="
|
51
|
-
- !ruby/object:Gem::Version
|
52
|
-
|
53
|
-
- 0
|
54
|
-
version: "0"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
55
41
|
requirements: []
|
56
|
-
|
57
|
-
rubyforge_project: fuzzy_date
|
58
|
-
rubygems_version: 1.3.6
|
42
|
+
rubygems_version: 3.0.4
|
59
43
|
signing_key:
|
60
|
-
specification_version:
|
61
|
-
summary: FuzzyDate is a Ruby class for working with incomplete dates.Can be used in
|
62
|
-
|
44
|
+
specification_version: 4
|
45
|
+
summary: FuzzyDate is a Ruby class for working with incomplete dates.Can be used in
|
46
|
+
Combination with ActiveRecord.
|
47
|
+
test_files:
|
63
48
|
- test/test_fuzzy_date.rb
|