quandl_babelfish 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +7 -7
- data/.travis.yml +12 -12
- data/Gemfile +1 -1
- data/LICENSE +7 -7
- data/README.md +18 -18
- data/UPGRADE.md +38 -31
- data/lib/quandl/babelfish.rb +28 -28
- data/lib/quandl/babelfish/chronometer.rb +43 -43
- data/lib/quandl/babelfish/cleaner.rb +33 -32
- data/lib/quandl/babelfish/date_maid.rb +237 -237
- data/lib/quandl/babelfish/helper.rb +8 -8
- data/lib/quandl/babelfish/number_maid.rb +79 -79
- data/lib/quandl/babelfish/version.rb +4 -4
- data/lib/quandl/error/guess_date_format.rb +4 -4
- data/lib/quandl/error/invalid_date.rb +4 -4
- data/lib/quandl/error/standard.rb +26 -26
- data/lib/quandl/error/unknown_date_format.rb +4 -4
- data/quandl_babelfish.gemspec +21 -21
- data/spec/lib/quandl/babelfish/chronometer_spec.rb +50 -50
- data/spec/lib/quandl/babelfish/cleaner_spec.rb +70 -70
- data/spec/lib/quandl/babelfish/date_maid_spec.rb +528 -528
- data/spec/lib/quandl/babelfish/helper_spec.rb +44 -44
- data/spec/lib/quandl/babelfish/number_maid_spec.rb +126 -126
- data/spec/lib/quandl/babelfish_spec.rb +15 -15
- data/spec/spec_helper.rb +12 -12
- data/spec/support/matchers/be_eq_at_index.rb +31 -31
- metadata +12 -4
@@ -1,529 +1,529 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
include Quandl::Babelfish
|
4
|
-
describe NumberMaid do
|
5
|
-
|
6
|
-
it 'should return an exception because month and day are ambiguous YYYY' do
|
7
|
-
dates = ['01/01/2011','1/2/2011','2/3/2011','11/1/2011']
|
8
|
-
lambda {DateMaid::sweep(dates)}.should raise_error(Error::GuessDateFormat)
|
9
|
-
end
|
10
|
-
|
11
|
-
it 'should return an exception because month and day are ambiguous YY' do
|
12
|
-
dates = ['01/01/11','1/2/11','1/3/11','11/1/11']
|
13
|
-
lambda {DateMaid::sweep(dates)}.should raise_error(Error::GuessDateFormat)
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should remove unwanted characters from dates (eg. )' do
|
17
|
-
a=194.chr+160.chr
|
18
|
-
dates = ["2005#{a}","#{a}2006",'2007','2008']
|
19
|
-
dates = DateMaid::sweep(dates)
|
20
|
-
dates[0].should == Date.new(2005,12,31)
|
21
|
-
dates[1].should == Date.new(2006,12,31)
|
22
|
-
dates[2].should == Date.new(2007,12,31)
|
23
|
-
dates[3].should == Date.new(2008,12,31)
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'should transform a parseable date into valid data (US) YYYY year' do
|
27
|
-
dates = ['01/10/2011','1/11/2011','1/12/2011','1/13/2011']
|
28
|
-
|
29
|
-
dates = DateMaid::sweep(dates)
|
30
|
-
dates[0].should == Date.new(2011,1,10)
|
31
|
-
dates[1].should == Date.new(2011,1,11)
|
32
|
-
dates[2].should == Date.new(2011,1,12)
|
33
|
-
dates[3].should == Date.new(2011,1,13)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should calculate dates from UNIX timestamps (to UTC)' do
|
37
|
-
dates = [1279324800,1279411200,1279497600,1279584000]
|
38
|
-
|
39
|
-
dates = DateMaid::sweep(dates)
|
40
|
-
dates[0].should == Date.new(2010,7,17)
|
41
|
-
dates[1].should == Date.new(2010,7,18)
|
42
|
-
dates[2].should == Date.new(2010,7,19)
|
43
|
-
dates[3].should == Date.new(2010,7,20)
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'should transform a parseable date into valid data (US) YY year' do
|
47
|
-
dates = ['01/10/11','1/11/11','1/12/11','1/13/11,4']
|
48
|
-
dates = DateMaid::sweep(dates)
|
49
|
-
dates[0].should == Date.new(2011,1,10)
|
50
|
-
dates[1].should == Date.new(2011,1,11)
|
51
|
-
dates[2].should == Date.new(2011,1,12)
|
52
|
-
dates[3].should == Date.new(2011,1,13)
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'should throw error when 1 of the dates is invalid' do
|
56
|
-
# It ain't a leap year
|
57
|
-
dates = ['2/29/2011','01/01/2011','1/2/2011','1/3/2011','12/1/2011']
|
58
|
-
lambda {DateMaid::sweep(dates)}.should raise_error(Error::InvalidDate)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'should strip invalid parseable dates (US)' do
|
62
|
-
dates = ['01/01/2011','1/2/2011','1/3/2011','12/17/2011']
|
63
|
-
dates = DateMaid::sweep(dates)
|
64
|
-
dates[0].should == Date.new(2011,1,1)
|
65
|
-
dates[1].should == Date.new(2011,1,2)
|
66
|
-
dates[2].should == Date.new(2011,1,3)
|
67
|
-
dates[3].should == Date.new(2011,12,17)
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'should transform a parseable date into valid data (ISO)' do
|
71
|
-
dates = ['2011-01-01','2011-01-02','2011-01-03','2011-02-04']
|
72
|
-
dates = DateMaid::sweep(dates)
|
73
|
-
dates[0].should == Date.new(2011,1,1)
|
74
|
-
dates[1].should == Date.new(2011,1,2)
|
75
|
-
dates[2].should == Date.new(2011,1,3)
|
76
|
-
dates[3].should == Date.new(2011,2,4)
|
77
|
-
end
|
78
|
-
|
79
|
-
it 'should parse ISO dates' do
|
80
|
-
# It ain't a leap year
|
81
|
-
dates = ['2011-01-01','2011-01-02','2011-01-03','2011-02-04']
|
82
|
-
dates = DateMaid::sweep(dates)
|
83
|
-
dates[0].should == Date.new(2011,1,1)
|
84
|
-
dates[1].should == Date.new(2011,1,2)
|
85
|
-
dates[2].should == Date.new(2011,1,3)
|
86
|
-
dates[3].should == Date.new(2011,2,4)
|
87
|
-
end
|
88
|
-
|
89
|
-
it 'should handle JP dates YYYY/MM/DD' do
|
90
|
-
dates = ['2011/01/01','2011/01/2','2011/1/03','2011/2/4']
|
91
|
-
dates = DateMaid::sweep(dates)
|
92
|
-
dates[0].should == Date.new(2011,1,1)
|
93
|
-
dates[1].should == Date.new(2011,1,2)
|
94
|
-
dates[2].should == Date.new(2011,1,3)
|
95
|
-
dates[3].should == Date.new(2011,2,4)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should handle manually formatted dates (EU)' do
|
99
|
-
dates = ['01/01/2011','2/1/2011','3/1/2011','1/12/2011']
|
100
|
-
DateMaid::init(:format => '%d/%m/%Y')
|
101
|
-
dates = DateMaid::sweep(dates)
|
102
|
-
dates[0].should == Date.new(2011,1,1)
|
103
|
-
dates[1].should == Date.new(2011,1,2)
|
104
|
-
dates[2].should == Date.new(2011,1,3)
|
105
|
-
dates[3].should == Date.new(2011,12,1)
|
106
|
-
DateMaid::init({})
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should handle manually formatted dates (EU, strip)' do
|
110
|
-
dates = ['01/01/2011','2/1/2011','3/1/2011','1/12/2011']
|
111
|
-
DateMaid::init(:format => '%d/%m/%Y')
|
112
|
-
dates = DateMaid::sweep(dates)
|
113
|
-
dates[0].should == Date.new(2011,1,1)
|
114
|
-
dates[1].should == Date.new(2011,1,2)
|
115
|
-
dates[2].should == Date.new(2011,1,3)
|
116
|
-
dates[3].should == Date.new(2011,12,1)
|
117
|
-
DateMaid::init({})
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'should transform a year into an end of year date' do
|
121
|
-
dates = ['2011','2010','2009','2008','2007','2006']
|
122
|
-
|
123
|
-
DateMaid::init({:frequency => 'annual'})
|
124
|
-
dates = DateMaid::sweep(dates)
|
125
|
-
dates[0].should == Date.new(2011,12,31)
|
126
|
-
dates[1].should == Date.new(2010,12,31)
|
127
|
-
dates[2].should == Date.new(2009,12,31)
|
128
|
-
dates[3].should == Date.new(2008,12,31)
|
129
|
-
DateMaid::init({})
|
130
|
-
end
|
131
|
-
|
132
|
-
it 'should transform a year into an end of year date with gaps' do
|
133
|
-
dates = ['2011','2010','2009','2008','2007','2006']
|
134
|
-
DateMaid::init({:frequency => 'annual'})
|
135
|
-
dates = DateMaid::sweep(dates)
|
136
|
-
dates[0].should == Date.new(2011,12,31)
|
137
|
-
dates[1].should == Date.new(2010,12,31)
|
138
|
-
dates[2].should == Date.new(2009,12,31)
|
139
|
-
dates[3].should == Date.new(2008,12,31)
|
140
|
-
DateMaid::init({})
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'should transform a YYYY.0 into an end of year date' do
|
144
|
-
dates = ['2011.0','2010.0','2009.0','2008.0','2007.0','2006.0']
|
145
|
-
DateMaid::init({:frequency => 'annual'})
|
146
|
-
dates = DateMaid::sweep(dates)
|
147
|
-
dates[0].should == Date.new(2011,12,31)
|
148
|
-
dates[1].should == Date.new(2010,12,31)
|
149
|
-
dates[2].should == Date.new(2009,12,31)
|
150
|
-
dates[3].should == Date.new(2008,12,31)
|
151
|
-
DateMaid::init({})
|
152
|
-
end
|
153
|
-
|
154
|
-
it 'should transform a YYYY.1 into an end of month date' do
|
155
|
-
dates = ['2011.1','2010.2','2009.3','2008.10','2007.11','2006.12']
|
156
|
-
dates = DateMaid::sweep(dates)
|
157
|
-
dates[0].should == Date.new(2011,01,31)
|
158
|
-
dates[1].should == Date.new(2010,02,28)
|
159
|
-
dates[2].should == Date.new(2009,03,31)
|
160
|
-
dates[3].should == Date.new(2008,10,31)
|
161
|
-
dates[4].should == Date.new(2007,11,30)
|
162
|
-
dates[5].should == Date.new(2006,12,31)
|
163
|
-
end
|
164
|
-
|
165
|
-
|
166
|
-
it 'should transform yyyy-mm to end of month' do
|
167
|
-
dates = ['2011-01','2011-02','2011-03','2011-04']
|
168
|
-
dates = DateMaid::sweep(dates)
|
169
|
-
dates[0].should == Date.new(2011,1,31)
|
170
|
-
dates[1].should == Date.new(2011,2,28)
|
171
|
-
dates[2].should == Date.new(2011,3,31)
|
172
|
-
dates[3].should == Date.new(2011,4,30)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'should transform yyyy/mm to end of month' do
|
176
|
-
dates = ['2011/01','2011/02','2011/03','2011/04,4']
|
177
|
-
dates = DateMaid::sweep(dates)
|
178
|
-
dates[0].should == Date.new(2011,1,31)
|
179
|
-
dates[1].should == Date.new(2011,2,28)
|
180
|
-
dates[2].should == Date.new(2011,3,31)
|
181
|
-
dates[3].should == Date.new(2011,4,30)
|
182
|
-
end
|
183
|
-
|
184
|
-
it 'should transform yyyyMmm to end of month' do
|
185
|
-
dates = ['2011M01','2011M02','2011M03','2011M04']
|
186
|
-
dates = DateMaid::sweep(dates)
|
187
|
-
dates[0].should == Date.new(2011,1,31)
|
188
|
-
dates[1].should == Date.new(2011,2,28)
|
189
|
-
dates[2].should == Date.new(2011,3,31)
|
190
|
-
dates[3].should == Date.new(2011,4,30)
|
191
|
-
end
|
192
|
-
|
193
|
-
it 'should transform yyyyWww to the first Friday of the week of the year' do
|
194
|
-
dates = ['1998W52','1998W53','1999W01']
|
195
|
-
dates = DateMaid::sweep(dates)
|
196
|
-
dates[0].should == Date.new(1998,12,25)
|
197
|
-
dates[1].should == Date.new(1999,1,1)
|
198
|
-
dates[2].should == Date.new(1999,1,8)
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'should fail on invalid YYYY-MM formats' do
|
202
|
-
dates = ['2011-13','2011-AA','2011-01','2011-02','2011-03','2011-04']
|
203
|
-
lambda {DateMaid::sweep(dates)}.should raise_error(Error::InvalidDate)
|
204
|
-
end
|
205
|
-
|
206
|
-
it 'should parse YYYY-MM formats' do
|
207
|
-
dates = ['2011-01','2011-02','2011-03','2011-04']
|
208
|
-
dates = DateMaid::sweep(dates)
|
209
|
-
dates[0].should == Date.new(2011,1,31)
|
210
|
-
dates[1].should == Date.new(2011,2,28)
|
211
|
-
dates[2].should == Date.new(2011,3,31)
|
212
|
-
dates[3].should == Date.new(2011,4,30)
|
213
|
-
end
|
214
|
-
|
215
|
-
it 'should transform mm-yyyy to end of month' do
|
216
|
-
dates = ['01-2011','02-2011','3-2011','4-2011']
|
217
|
-
dates = DateMaid::sweep(dates)
|
218
|
-
dates[0].should == Date.new(2011,1,31)
|
219
|
-
dates[1].should == Date.new(2011,2,28)
|
220
|
-
dates[2].should == Date.new(2011,3,31)
|
221
|
-
dates[3].should == Date.new(2011,4,30)
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'should transform mm/yyyy to end of month' do
|
225
|
-
dates = ['01/2011','02/2011','3/2011','4/2011']
|
226
|
-
dates = DateMaid::sweep(dates)
|
227
|
-
dates[0].should == Date.new(2011,1,31)
|
228
|
-
dates[1].should == Date.new(2011,2,28)
|
229
|
-
dates[2].should == Date.new(2011,3,31)
|
230
|
-
dates[3].should == Date.new(2011,4,30)
|
231
|
-
end
|
232
|
-
|
233
|
-
it 'should transform yyyymm (no delimiter) to end of month' do
|
234
|
-
dates = ['201101','201102','201103','201104']
|
235
|
-
dates = DateMaid::sweep(dates)
|
236
|
-
dates[0].should == Date.new(2011,1,31)
|
237
|
-
dates[1].should == Date.new(2011,2,28)
|
238
|
-
dates[2].should == Date.new(2011,3,31)
|
239
|
-
dates[3].should == Date.new(2011,4,30)
|
240
|
-
end
|
241
|
-
|
242
|
-
it 'should transform yyyymm (no delimiter) to end of month' do
|
243
|
-
# Only 5 digits
|
244
|
-
dates = ['201101','201102','201103','201104']
|
245
|
-
dates = DateMaid::sweep(dates)
|
246
|
-
dates[0].should == Date.new(2011,1,31)
|
247
|
-
dates[1].should == Date.new(2011,2,28)
|
248
|
-
dates[2].should == Date.new(2011,3,31)
|
249
|
-
dates[3].should == Date.new(2011,4,30)
|
250
|
-
end
|
251
|
-
|
252
|
-
it 'should transform YYYY-MMM to end of month' do
|
253
|
-
dates = ['2011-jan','2011-feb','2011-mar','2011-apr']
|
254
|
-
dates = DateMaid::sweep(dates)
|
255
|
-
dates[0].should == Date.new(2011,1,31)
|
256
|
-
dates[1].should == Date.new(2011,2,28)
|
257
|
-
dates[2].should == Date.new(2011,3,31)
|
258
|
-
dates[3].should == Date.new(2011,4,30)
|
259
|
-
end
|
260
|
-
|
261
|
-
it 'should transform YYYY MMM to end of month' do
|
262
|
-
dates = ['2011 jan','2011 feb','2011 mar','2011 apr']
|
263
|
-
dates = DateMaid::sweep(dates)
|
264
|
-
dates[0].should == Date.new(2011,1,31)
|
265
|
-
dates[1].should == Date.new(2011,2,28)
|
266
|
-
dates[2].should == Date.new(2011,3,31)
|
267
|
-
dates[3].should == Date.new(2011,4,30)
|
268
|
-
end
|
269
|
-
|
270
|
-
it 'should transform YYYY MMM to end of month (CAPS)' do
|
271
|
-
dates = ['2011 JAN','2011 FEB','2011 MAR','2011 APR']
|
272
|
-
dates = DateMaid::sweep(dates)
|
273
|
-
dates[0].should == Date.new(2011,1,31)
|
274
|
-
dates[1].should == Date.new(2011,2,28)
|
275
|
-
dates[2].should == Date.new(2011,3,31)
|
276
|
-
dates[3].should == Date.new(2011,4,30)
|
277
|
-
end
|
278
|
-
|
279
|
-
it 'should transform YYYY MMM to end of month (Camel)' do
|
280
|
-
dates = ['2011 Jan','2011 Feb','2011 Mar','2011 Apr,4']
|
281
|
-
dates = DateMaid::sweep(dates)
|
282
|
-
dates[0].should == Date.new(2011,1,31)
|
283
|
-
dates[1].should == Date.new(2011,2,28)
|
284
|
-
dates[2].should == Date.new(2011,3,31)
|
285
|
-
dates[3].should == Date.new(2011,4,30)
|
286
|
-
end
|
287
|
-
|
288
|
-
it 'should transform MMM-YYYY to end of month' do
|
289
|
-
dates = ['jan-2011','feb-2011','mar-2011','apr-2011,4']
|
290
|
-
dates = DateMaid::sweep(dates)
|
291
|
-
dates[0].should == Date.new(2011,1,31)
|
292
|
-
dates[1].should == Date.new(2011,2,28)
|
293
|
-
dates[2].should == Date.new(2011,3,31)
|
294
|
-
dates[3].should == Date.new(2011,4,30)
|
295
|
-
end
|
296
|
-
|
297
|
-
it 'should transform MMM-YYYY to end of month (strip)' do
|
298
|
-
dates = ['jan-2011','feb-2011','mar-2011','apr-2011']
|
299
|
-
dates = DateMaid::sweep(dates)
|
300
|
-
dates[0].should == Date.new(2011,1,31)
|
301
|
-
dates[1].should == Date.new(2011,2,28)
|
302
|
-
dates[2].should == Date.new(2011,3,31)
|
303
|
-
dates[3].should == Date.new(2011,4,30)
|
304
|
-
end
|
305
|
-
|
306
|
-
it 'should transform MMMYYYY to end of month (No delimiter)' do
|
307
|
-
dates = ['jan2011','feb2011','mar2011','apr2011']
|
308
|
-
dates = DateMaid::sweep(dates)
|
309
|
-
dates[0].should == Date.new(2011,1,31)
|
310
|
-
dates[1].should == Date.new(2011,2,28)
|
311
|
-
dates[2].should == Date.new(2011,3,31)
|
312
|
-
dates[3].should == Date.new(2011,4,30)
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'should transform MMMYYYY to end of month (No delimiter, strip)' do
|
316
|
-
dates = ['jan2011','feb2011','mar2011','apr2011']
|
317
|
-
dates = DateMaid::sweep(dates)
|
318
|
-
dates[0].should == Date.new(2011,1,31)
|
319
|
-
dates[1].should == Date.new(2011,2,28)
|
320
|
-
dates[2].should == Date.new(2011,3,31)
|
321
|
-
dates[3].should == Date.new(2011,4,30)
|
322
|
-
end
|
323
|
-
|
324
|
-
|
325
|
-
it 'should transform YYYYMMM to end of month (No delimiter) even if one date is partially valid' do
|
326
|
-
dates = ['2011JAN','2011FEB','2011MAR','2011APR,4']
|
327
|
-
dates = DateMaid::sweep(dates)
|
328
|
-
dates[0].should == Date.new(2011,1,31)
|
329
|
-
dates[1].should == Date.new(2011,2,28)
|
330
|
-
dates[2].should == Date.new(2011,3,31)
|
331
|
-
dates[3].should == Date.new(2011,4,30)
|
332
|
-
end
|
333
|
-
|
334
|
-
it 'should transform YYYYMMM to end of month (No delimiter)' do
|
335
|
-
dates = ['2011JAN','2011FEB','2011MAR','2011APR,4']
|
336
|
-
dates = DateMaid::sweep(dates)
|
337
|
-
dates[0].should == Date.new(2011,1,31)
|
338
|
-
dates[1].should == Date.new(2011,2,28)
|
339
|
-
dates[2].should == Date.new(2011,3,31)
|
340
|
-
dates[3].should == Date.new(2011,4,30)
|
341
|
-
end
|
342
|
-
|
343
|
-
it 'should transform YYYY-MMM-DD to date' do
|
344
|
-
dates = ['2011-jan-01','2011-feb-01','2011-mar-3','2011-apr-4']
|
345
|
-
dates = DateMaid::sweep(dates)
|
346
|
-
dates[0].should == Date.new(2011,1,1)
|
347
|
-
dates[1].should == Date.new(2011,2,1)
|
348
|
-
dates[2].should == Date.new(2011,3,3)
|
349
|
-
dates[3].should == Date.new(2011,4,4)
|
350
|
-
end
|
351
|
-
|
352
|
-
it 'should transform YYYY-MMM-DD to date (strip)' do
|
353
|
-
dates = ['2011-jan-01','2011-feb-01','2011-mar-3','2011-apr-4']
|
354
|
-
dates = DateMaid::sweep(dates)
|
355
|
-
dates[0].should == Date.new(2011,1,1)
|
356
|
-
dates[1].should == Date.new(2011,2,1)
|
357
|
-
dates[2].should == Date.new(2011,3,3)
|
358
|
-
dates[3].should == Date.new(2011,4,4)
|
359
|
-
end
|
360
|
-
|
361
|
-
|
362
|
-
it 'should transform DD-MMM-YYYY to date' do
|
363
|
-
dates = ['01-jan-2011','01-feb-2011','3-mar-2011','4-apr-2011']
|
364
|
-
dates = DateMaid::sweep(dates)
|
365
|
-
dates[0].should == Date.new(2011,1,1)
|
366
|
-
dates[1].should == Date.new(2011,2,1)
|
367
|
-
dates[2].should == Date.new(2011,3,3)
|
368
|
-
dates[3].should == Date.new(2011,4,4)
|
369
|
-
end
|
370
|
-
|
371
|
-
it 'should transform DD-MMM-YYYY to date (strip)' do
|
372
|
-
dates = ['01-jan-2011','01-feb-2011','3-mar-2011','4-apr-2011']
|
373
|
-
dates = DateMaid::sweep(dates)
|
374
|
-
dates[0].should == Date.new(2011,1,1)
|
375
|
-
dates[1].should == Date.new(2011,2,1)
|
376
|
-
dates[2].should == Date.new(2011,3,3)
|
377
|
-
dates[3].should == Date.new(2011,4,4)
|
378
|
-
end
|
379
|
-
|
380
|
-
it 'should transform YYYYMMMDD to date (no delimiters)' do
|
381
|
-
dates = ['2011jan01','2011feb01','2011mar3','2011apr4']
|
382
|
-
dates = DateMaid::sweep(dates)
|
383
|
-
dates[0].should == Date.new(2011,1,1)
|
384
|
-
dates[1].should == Date.new(2011,2,1)
|
385
|
-
dates[2].should == Date.new(2011,3,3)
|
386
|
-
dates[3].should == Date.new(2011,4,4)
|
387
|
-
end
|
388
|
-
|
389
|
-
it 'should transform YYYYMMMDD to date (no delimiters, strip)' do
|
390
|
-
dates = ['2011jan01','2011feb01','2011mar3','2011apr4']
|
391
|
-
dates = DateMaid::sweep(dates)
|
392
|
-
dates[0].should == Date.new(2011,1,1)
|
393
|
-
dates[1].should == Date.new(2011,2,1)
|
394
|
-
dates[2].should == Date.new(2011,3,3)
|
395
|
-
dates[3].should == Date.new(2011,4,4)
|
396
|
-
end
|
397
|
-
|
398
|
-
it 'should transform DD-MMM-YYYY to date (no delimiters)' do
|
399
|
-
dates = ['01jan2011','01feb2011','3mar2011','4apr2011']
|
400
|
-
dates = DateMaid::sweep(dates)
|
401
|
-
dates[0].should == Date.new(2011,1,1)
|
402
|
-
dates[1].should == Date.new(2011,2,1)
|
403
|
-
dates[2].should == Date.new(2011,3,3)
|
404
|
-
dates[3].should == Date.new(2011,4,4)
|
405
|
-
end
|
406
|
-
|
407
|
-
it 'should transform DD-MMM-YYYY to date (no delimiters, strip)' do
|
408
|
-
dates = ['01jan2011','01feb2011','3mar2011','4apr2011']
|
409
|
-
dates = DateMaid::sweep(dates)
|
410
|
-
dates[0].should == Date.new(2011,1,1)
|
411
|
-
dates[1].should == Date.new(2011,2,1)
|
412
|
-
dates[2].should == Date.new(2011,3,3)
|
413
|
-
dates[3].should == Date.new(2011,4,4)
|
414
|
-
end
|
415
|
-
|
416
|
-
it 'should transform yyyy-Qq to end of quarter' do
|
417
|
-
dates = ['2011-Q1','2011-Q2','2011-Q3','2011-Q4']
|
418
|
-
dates = DateMaid::sweep(dates)
|
419
|
-
dates[0].should == Date.new(2011,3,31)
|
420
|
-
dates[1].should == Date.new(2011,6,30)
|
421
|
-
dates[2].should == Date.new(2011,9,30)
|
422
|
-
dates[3].should == Date.new(2011,12,31)
|
423
|
-
end
|
424
|
-
|
425
|
-
it 'should transform yyyy-Qq to end of quarter (strip)' do
|
426
|
-
dates = ['2011-Q1','2011-Q2','2011-Q3','2011-Q4']
|
427
|
-
dates = DateMaid::sweep(dates)
|
428
|
-
dates[0].should == Date.new(2011,3,31)
|
429
|
-
dates[1].should == Date.new(2011,6,30)
|
430
|
-
dates[2].should == Date.new(2011,9,30)
|
431
|
-
dates[3].should == Date.new(2011,12,31)
|
432
|
-
end
|
433
|
-
|
434
|
-
it 'should transform yyyyQq to end of quarter (no delimiter)' do
|
435
|
-
dates = ['2011q1','2011Q2','2011q3','2011Q4,4']
|
436
|
-
dates = DateMaid::sweep(dates)
|
437
|
-
dates[0].should == Date.new(2011,3,31)
|
438
|
-
dates[1].should == Date.new(2011,6,30)
|
439
|
-
dates[2].should == Date.new(2011,9,30)
|
440
|
-
dates[3].should == Date.new(2011,12,31)
|
441
|
-
end
|
442
|
-
|
443
|
-
it 'should handle white space at front and back of dates' do
|
444
|
-
dates = [' 2012q2 ']
|
445
|
-
dates = DateMaid::sweep(dates)
|
446
|
-
dates[0].should == Date.new(2012,6,30)
|
447
|
-
end
|
448
|
-
|
449
|
-
it 'should handle white space at front and back of dates (2)' do
|
450
|
-
dates = [' 2012 ']
|
451
|
-
dates = DateMaid::sweep(dates)
|
452
|
-
dates[0].should == Date.new(2012,12,31)
|
453
|
-
end
|
454
|
-
|
455
|
-
it 'should know 1871.10 is October' do
|
456
|
-
dates = ['1871.10']
|
457
|
-
dates = DateMaid::sweep(dates)
|
458
|
-
dates[0].should == Date.new(1871,10,31)
|
459
|
-
end
|
460
|
-
|
461
|
-
it 'should handle 1990' do
|
462
|
-
dates = ['1990']
|
463
|
-
dates = DateMaid::sweep(dates)
|
464
|
-
dates[0].should == Date.new(1990,12,31)
|
465
|
-
end
|
466
|
-
|
467
|
-
it 'should handle 1990 - 1995' do
|
468
|
-
dates = ['1990 - 1995']
|
469
|
-
dates = DateMaid::sweep(dates)
|
470
|
-
dates[0].should == Date.new(1990,12,31)
|
471
|
-
end
|
472
|
-
|
473
|
-
it 'should transform YYYYMMDD to date' do
|
474
|
-
dates = ['20010101','20110518','19701111','19770208','19900531']
|
475
|
-
dates = DateMaid::sweep(dates)
|
476
|
-
dates[0].should == Date.new(2001,1,1)
|
477
|
-
dates[1].should == Date.new(2011,5,18)
|
478
|
-
dates[2].should == Date.new(1970,11,11)
|
479
|
-
dates[3].should == Date.new(1977,2,8)
|
480
|
-
dates[4].should == Date.new(1990,5,31)
|
481
|
-
end
|
482
|
-
|
483
|
-
it 'should transform Jan 30, 1955' do
|
484
|
-
dates = ['Jan 30, 1955']
|
485
|
-
dates = DateMaid::sweep(dates)
|
486
|
-
dates[0].should == Date.new(1955,1,30)
|
487
|
-
end
|
488
|
-
|
489
|
-
it 'should transform Jan-68' do
|
490
|
-
dates = ['Dec-68','Jan-69']
|
491
|
-
dates = DateMaid::sweep(dates)
|
492
|
-
dates[0].should == Date.new(1968,12,31)
|
493
|
-
dates[1].should == Date.new(1969,1,31)
|
494
|
-
end
|
495
|
-
|
496
|
-
|
497
|
-
it 'should transform Jul-01' do
|
498
|
-
dates = ['Jul-01','Aug-01']
|
499
|
-
dates = DateMaid::sweep(dates)
|
500
|
-
dates[1].should == Date.new(2001,8,31)
|
501
|
-
dates[0].should == Date.new(2001,7,31)
|
502
|
-
end
|
503
|
-
|
504
|
-
it 'should transform Dec-31-12' do
|
505
|
-
dates = ['Dec-31-12']
|
506
|
-
dates = DateMaid::sweep(dates)
|
507
|
-
dates[0].should == Date.new(2012,12,31)
|
508
|
-
end
|
509
|
-
|
510
|
-
it 'should format YYYY/MM/DD' do
|
511
|
-
dates = ['20010101','20110518','19701111','19770208','19900531']
|
512
|
-
dates = DateMaid::sweep(dates)
|
513
|
-
dates[0].should == Date.new(2001,1,1)
|
514
|
-
dates[1].should == Date.new(2011,5,18)
|
515
|
-
dates[2].should == Date.new(1970,11,11)
|
516
|
-
dates[3].should == Date.new(1977,2,8)
|
517
|
-
dates[4].should == Date.new(1990,5,31)
|
518
|
-
end
|
519
|
-
|
520
|
-
it 'should strip days of the week' do
|
521
|
-
pending "Not implemented yet"
|
522
|
-
dates = ["Tuesday, April 30, 2013","Mon april 29, 2012"]
|
523
|
-
dates = DateMaid::sweep(dates)
|
524
|
-
dates[0].should == Date.new(2013,04,30)
|
525
|
-
dates[1].should == Date.new(2012,04,29)
|
526
|
-
end
|
527
|
-
|
528
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
include Quandl::Babelfish
|
4
|
+
describe NumberMaid do
|
5
|
+
|
6
|
+
it 'should return an exception because month and day are ambiguous YYYY' do
|
7
|
+
dates = ['01/01/2011','1/2/2011','2/3/2011','11/1/2011']
|
8
|
+
lambda {DateMaid::sweep(dates)}.should raise_error(Error::GuessDateFormat)
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should return an exception because month and day are ambiguous YY' do
|
12
|
+
dates = ['01/01/11','1/2/11','1/3/11','11/1/11']
|
13
|
+
lambda {DateMaid::sweep(dates)}.should raise_error(Error::GuessDateFormat)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should remove unwanted characters from dates (eg. )' do
|
17
|
+
a=194.chr+160.chr
|
18
|
+
dates = ["2005#{a}","#{a}2006",'2007','2008']
|
19
|
+
dates = DateMaid::sweep(dates)
|
20
|
+
dates[0].should == Date.new(2005,12,31)
|
21
|
+
dates[1].should == Date.new(2006,12,31)
|
22
|
+
dates[2].should == Date.new(2007,12,31)
|
23
|
+
dates[3].should == Date.new(2008,12,31)
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should transform a parseable date into valid data (US) YYYY year' do
|
27
|
+
dates = ['01/10/2011','1/11/2011','1/12/2011','1/13/2011']
|
28
|
+
|
29
|
+
dates = DateMaid::sweep(dates)
|
30
|
+
dates[0].should == Date.new(2011,1,10)
|
31
|
+
dates[1].should == Date.new(2011,1,11)
|
32
|
+
dates[2].should == Date.new(2011,1,12)
|
33
|
+
dates[3].should == Date.new(2011,1,13)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should calculate dates from UNIX timestamps (to UTC)' do
|
37
|
+
dates = [1279324800,1279411200,1279497600,1279584000]
|
38
|
+
|
39
|
+
dates = DateMaid::sweep(dates)
|
40
|
+
dates[0].should == Date.new(2010,7,17)
|
41
|
+
dates[1].should == Date.new(2010,7,18)
|
42
|
+
dates[2].should == Date.new(2010,7,19)
|
43
|
+
dates[3].should == Date.new(2010,7,20)
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should transform a parseable date into valid data (US) YY year' do
|
47
|
+
dates = ['01/10/11','1/11/11','1/12/11','1/13/11,4']
|
48
|
+
dates = DateMaid::sweep(dates)
|
49
|
+
dates[0].should == Date.new(2011,1,10)
|
50
|
+
dates[1].should == Date.new(2011,1,11)
|
51
|
+
dates[2].should == Date.new(2011,1,12)
|
52
|
+
dates[3].should == Date.new(2011,1,13)
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should throw error when 1 of the dates is invalid' do
|
56
|
+
# It ain't a leap year
|
57
|
+
dates = ['2/29/2011','01/01/2011','1/2/2011','1/3/2011','12/1/2011']
|
58
|
+
lambda {DateMaid::sweep(dates)}.should raise_error(Error::InvalidDate)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should strip invalid parseable dates (US)' do
|
62
|
+
dates = ['01/01/2011','1/2/2011','1/3/2011','12/17/2011']
|
63
|
+
dates = DateMaid::sweep(dates)
|
64
|
+
dates[0].should == Date.new(2011,1,1)
|
65
|
+
dates[1].should == Date.new(2011,1,2)
|
66
|
+
dates[2].should == Date.new(2011,1,3)
|
67
|
+
dates[3].should == Date.new(2011,12,17)
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should transform a parseable date into valid data (ISO)' do
|
71
|
+
dates = ['2011-01-01','2011-01-02','2011-01-03','2011-02-04']
|
72
|
+
dates = DateMaid::sweep(dates)
|
73
|
+
dates[0].should == Date.new(2011,1,1)
|
74
|
+
dates[1].should == Date.new(2011,1,2)
|
75
|
+
dates[2].should == Date.new(2011,1,3)
|
76
|
+
dates[3].should == Date.new(2011,2,4)
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should parse ISO dates' do
|
80
|
+
# It ain't a leap year
|
81
|
+
dates = ['2011-01-01','2011-01-02','2011-01-03','2011-02-04']
|
82
|
+
dates = DateMaid::sweep(dates)
|
83
|
+
dates[0].should == Date.new(2011,1,1)
|
84
|
+
dates[1].should == Date.new(2011,1,2)
|
85
|
+
dates[2].should == Date.new(2011,1,3)
|
86
|
+
dates[3].should == Date.new(2011,2,4)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should handle JP dates YYYY/MM/DD' do
|
90
|
+
dates = ['2011/01/01','2011/01/2','2011/1/03','2011/2/4']
|
91
|
+
dates = DateMaid::sweep(dates)
|
92
|
+
dates[0].should == Date.new(2011,1,1)
|
93
|
+
dates[1].should == Date.new(2011,1,2)
|
94
|
+
dates[2].should == Date.new(2011,1,3)
|
95
|
+
dates[3].should == Date.new(2011,2,4)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should handle manually formatted dates (EU)' do
|
99
|
+
dates = ['01/01/2011','2/1/2011','3/1/2011','1/12/2011']
|
100
|
+
DateMaid::init(:format => '%d/%m/%Y')
|
101
|
+
dates = DateMaid::sweep(dates)
|
102
|
+
dates[0].should == Date.new(2011,1,1)
|
103
|
+
dates[1].should == Date.new(2011,1,2)
|
104
|
+
dates[2].should == Date.new(2011,1,3)
|
105
|
+
dates[3].should == Date.new(2011,12,1)
|
106
|
+
DateMaid::init({})
|
107
|
+
end
|
108
|
+
|
109
|
+
it 'should handle manually formatted dates (EU, strip)' do
|
110
|
+
dates = ['01/01/2011','2/1/2011','3/1/2011','1/12/2011']
|
111
|
+
DateMaid::init(:format => '%d/%m/%Y')
|
112
|
+
dates = DateMaid::sweep(dates)
|
113
|
+
dates[0].should == Date.new(2011,1,1)
|
114
|
+
dates[1].should == Date.new(2011,1,2)
|
115
|
+
dates[2].should == Date.new(2011,1,3)
|
116
|
+
dates[3].should == Date.new(2011,12,1)
|
117
|
+
DateMaid::init({})
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should transform a year into an end of year date' do
|
121
|
+
dates = ['2011','2010','2009','2008','2007','2006']
|
122
|
+
|
123
|
+
DateMaid::init({:frequency => 'annual'})
|
124
|
+
dates = DateMaid::sweep(dates)
|
125
|
+
dates[0].should == Date.new(2011,12,31)
|
126
|
+
dates[1].should == Date.new(2010,12,31)
|
127
|
+
dates[2].should == Date.new(2009,12,31)
|
128
|
+
dates[3].should == Date.new(2008,12,31)
|
129
|
+
DateMaid::init({})
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should transform a year into an end of year date with gaps' do
|
133
|
+
dates = ['2011','2010','2009','2008','2007','2006']
|
134
|
+
DateMaid::init({:frequency => 'annual'})
|
135
|
+
dates = DateMaid::sweep(dates)
|
136
|
+
dates[0].should == Date.new(2011,12,31)
|
137
|
+
dates[1].should == Date.new(2010,12,31)
|
138
|
+
dates[2].should == Date.new(2009,12,31)
|
139
|
+
dates[3].should == Date.new(2008,12,31)
|
140
|
+
DateMaid::init({})
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should transform a YYYY.0 into an end of year date' do
|
144
|
+
dates = ['2011.0','2010.0','2009.0','2008.0','2007.0','2006.0']
|
145
|
+
DateMaid::init({:frequency => 'annual'})
|
146
|
+
dates = DateMaid::sweep(dates)
|
147
|
+
dates[0].should == Date.new(2011,12,31)
|
148
|
+
dates[1].should == Date.new(2010,12,31)
|
149
|
+
dates[2].should == Date.new(2009,12,31)
|
150
|
+
dates[3].should == Date.new(2008,12,31)
|
151
|
+
DateMaid::init({})
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should transform a YYYY.1 into an end of month date' do
|
155
|
+
dates = ['2011.1','2010.2','2009.3','2008.10','2007.11','2006.12']
|
156
|
+
dates = DateMaid::sweep(dates)
|
157
|
+
dates[0].should == Date.new(2011,01,31)
|
158
|
+
dates[1].should == Date.new(2010,02,28)
|
159
|
+
dates[2].should == Date.new(2009,03,31)
|
160
|
+
dates[3].should == Date.new(2008,10,31)
|
161
|
+
dates[4].should == Date.new(2007,11,30)
|
162
|
+
dates[5].should == Date.new(2006,12,31)
|
163
|
+
end
|
164
|
+
|
165
|
+
|
166
|
+
it 'should transform yyyy-mm to end of month' do
|
167
|
+
dates = ['2011-01','2011-02','2011-03','2011-04']
|
168
|
+
dates = DateMaid::sweep(dates)
|
169
|
+
dates[0].should == Date.new(2011,1,31)
|
170
|
+
dates[1].should == Date.new(2011,2,28)
|
171
|
+
dates[2].should == Date.new(2011,3,31)
|
172
|
+
dates[3].should == Date.new(2011,4,30)
|
173
|
+
end
|
174
|
+
|
175
|
+
it 'should transform yyyy/mm to end of month' do
|
176
|
+
dates = ['2011/01','2011/02','2011/03','2011/04,4']
|
177
|
+
dates = DateMaid::sweep(dates)
|
178
|
+
dates[0].should == Date.new(2011,1,31)
|
179
|
+
dates[1].should == Date.new(2011,2,28)
|
180
|
+
dates[2].should == Date.new(2011,3,31)
|
181
|
+
dates[3].should == Date.new(2011,4,30)
|
182
|
+
end
|
183
|
+
|
184
|
+
it 'should transform yyyyMmm to end of month' do
|
185
|
+
dates = ['2011M01','2011M02','2011M03','2011M04']
|
186
|
+
dates = DateMaid::sweep(dates)
|
187
|
+
dates[0].should == Date.new(2011,1,31)
|
188
|
+
dates[1].should == Date.new(2011,2,28)
|
189
|
+
dates[2].should == Date.new(2011,3,31)
|
190
|
+
dates[3].should == Date.new(2011,4,30)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should transform yyyyWww to the first Friday of the week of the year' do
|
194
|
+
dates = ['1998W52','1998W53','1999W01']
|
195
|
+
dates = DateMaid::sweep(dates)
|
196
|
+
dates[0].should == Date.new(1998,12,25)
|
197
|
+
dates[1].should == Date.new(1999,1,1)
|
198
|
+
dates[2].should == Date.new(1999,1,8)
|
199
|
+
end
|
200
|
+
|
201
|
+
it 'should fail on invalid YYYY-MM formats' do
|
202
|
+
dates = ['2011-13','2011-AA','2011-01','2011-02','2011-03','2011-04']
|
203
|
+
lambda {DateMaid::sweep(dates)}.should raise_error(Error::InvalidDate)
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should parse YYYY-MM formats' do
|
207
|
+
dates = ['2011-01','2011-02','2011-03','2011-04']
|
208
|
+
dates = DateMaid::sweep(dates)
|
209
|
+
dates[0].should == Date.new(2011,1,31)
|
210
|
+
dates[1].should == Date.new(2011,2,28)
|
211
|
+
dates[2].should == Date.new(2011,3,31)
|
212
|
+
dates[3].should == Date.new(2011,4,30)
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should transform mm-yyyy to end of month' do
|
216
|
+
dates = ['01-2011','02-2011','3-2011','4-2011']
|
217
|
+
dates = DateMaid::sweep(dates)
|
218
|
+
dates[0].should == Date.new(2011,1,31)
|
219
|
+
dates[1].should == Date.new(2011,2,28)
|
220
|
+
dates[2].should == Date.new(2011,3,31)
|
221
|
+
dates[3].should == Date.new(2011,4,30)
|
222
|
+
end
|
223
|
+
|
224
|
+
it 'should transform mm/yyyy to end of month' do
|
225
|
+
dates = ['01/2011','02/2011','3/2011','4/2011']
|
226
|
+
dates = DateMaid::sweep(dates)
|
227
|
+
dates[0].should == Date.new(2011,1,31)
|
228
|
+
dates[1].should == Date.new(2011,2,28)
|
229
|
+
dates[2].should == Date.new(2011,3,31)
|
230
|
+
dates[3].should == Date.new(2011,4,30)
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should transform yyyymm (no delimiter) to end of month' do
|
234
|
+
dates = ['201101','201102','201103','201104']
|
235
|
+
dates = DateMaid::sweep(dates)
|
236
|
+
dates[0].should == Date.new(2011,1,31)
|
237
|
+
dates[1].should == Date.new(2011,2,28)
|
238
|
+
dates[2].should == Date.new(2011,3,31)
|
239
|
+
dates[3].should == Date.new(2011,4,30)
|
240
|
+
end
|
241
|
+
|
242
|
+
it 'should transform yyyymm (no delimiter) to end of month' do
|
243
|
+
# Only 5 digits
|
244
|
+
dates = ['201101','201102','201103','201104']
|
245
|
+
dates = DateMaid::sweep(dates)
|
246
|
+
dates[0].should == Date.new(2011,1,31)
|
247
|
+
dates[1].should == Date.new(2011,2,28)
|
248
|
+
dates[2].should == Date.new(2011,3,31)
|
249
|
+
dates[3].should == Date.new(2011,4,30)
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'should transform YYYY-MMM to end of month' do
|
253
|
+
dates = ['2011-jan','2011-feb','2011-mar','2011-apr']
|
254
|
+
dates = DateMaid::sweep(dates)
|
255
|
+
dates[0].should == Date.new(2011,1,31)
|
256
|
+
dates[1].should == Date.new(2011,2,28)
|
257
|
+
dates[2].should == Date.new(2011,3,31)
|
258
|
+
dates[3].should == Date.new(2011,4,30)
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'should transform YYYY MMM to end of month' do
|
262
|
+
dates = ['2011 jan','2011 feb','2011 mar','2011 apr']
|
263
|
+
dates = DateMaid::sweep(dates)
|
264
|
+
dates[0].should == Date.new(2011,1,31)
|
265
|
+
dates[1].should == Date.new(2011,2,28)
|
266
|
+
dates[2].should == Date.new(2011,3,31)
|
267
|
+
dates[3].should == Date.new(2011,4,30)
|
268
|
+
end
|
269
|
+
|
270
|
+
it 'should transform YYYY MMM to end of month (CAPS)' do
|
271
|
+
dates = ['2011 JAN','2011 FEB','2011 MAR','2011 APR']
|
272
|
+
dates = DateMaid::sweep(dates)
|
273
|
+
dates[0].should == Date.new(2011,1,31)
|
274
|
+
dates[1].should == Date.new(2011,2,28)
|
275
|
+
dates[2].should == Date.new(2011,3,31)
|
276
|
+
dates[3].should == Date.new(2011,4,30)
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'should transform YYYY MMM to end of month (Camel)' do
|
280
|
+
dates = ['2011 Jan','2011 Feb','2011 Mar','2011 Apr,4']
|
281
|
+
dates = DateMaid::sweep(dates)
|
282
|
+
dates[0].should == Date.new(2011,1,31)
|
283
|
+
dates[1].should == Date.new(2011,2,28)
|
284
|
+
dates[2].should == Date.new(2011,3,31)
|
285
|
+
dates[3].should == Date.new(2011,4,30)
|
286
|
+
end
|
287
|
+
|
288
|
+
it 'should transform MMM-YYYY to end of month' do
|
289
|
+
dates = ['jan-2011','feb-2011','mar-2011','apr-2011,4']
|
290
|
+
dates = DateMaid::sweep(dates)
|
291
|
+
dates[0].should == Date.new(2011,1,31)
|
292
|
+
dates[1].should == Date.new(2011,2,28)
|
293
|
+
dates[2].should == Date.new(2011,3,31)
|
294
|
+
dates[3].should == Date.new(2011,4,30)
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should transform MMM-YYYY to end of month (strip)' do
|
298
|
+
dates = ['jan-2011','feb-2011','mar-2011','apr-2011']
|
299
|
+
dates = DateMaid::sweep(dates)
|
300
|
+
dates[0].should == Date.new(2011,1,31)
|
301
|
+
dates[1].should == Date.new(2011,2,28)
|
302
|
+
dates[2].should == Date.new(2011,3,31)
|
303
|
+
dates[3].should == Date.new(2011,4,30)
|
304
|
+
end
|
305
|
+
|
306
|
+
it 'should transform MMMYYYY to end of month (No delimiter)' do
|
307
|
+
dates = ['jan2011','feb2011','mar2011','apr2011']
|
308
|
+
dates = DateMaid::sweep(dates)
|
309
|
+
dates[0].should == Date.new(2011,1,31)
|
310
|
+
dates[1].should == Date.new(2011,2,28)
|
311
|
+
dates[2].should == Date.new(2011,3,31)
|
312
|
+
dates[3].should == Date.new(2011,4,30)
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'should transform MMMYYYY to end of month (No delimiter, strip)' do
|
316
|
+
dates = ['jan2011','feb2011','mar2011','apr2011']
|
317
|
+
dates = DateMaid::sweep(dates)
|
318
|
+
dates[0].should == Date.new(2011,1,31)
|
319
|
+
dates[1].should == Date.new(2011,2,28)
|
320
|
+
dates[2].should == Date.new(2011,3,31)
|
321
|
+
dates[3].should == Date.new(2011,4,30)
|
322
|
+
end
|
323
|
+
|
324
|
+
|
325
|
+
it 'should transform YYYYMMM to end of month (No delimiter) even if one date is partially valid' do
|
326
|
+
dates = ['2011JAN','2011FEB','2011MAR','2011APR,4']
|
327
|
+
dates = DateMaid::sweep(dates)
|
328
|
+
dates[0].should == Date.new(2011,1,31)
|
329
|
+
dates[1].should == Date.new(2011,2,28)
|
330
|
+
dates[2].should == Date.new(2011,3,31)
|
331
|
+
dates[3].should == Date.new(2011,4,30)
|
332
|
+
end
|
333
|
+
|
334
|
+
it 'should transform YYYYMMM to end of month (No delimiter)' do
|
335
|
+
dates = ['2011JAN','2011FEB','2011MAR','2011APR,4']
|
336
|
+
dates = DateMaid::sweep(dates)
|
337
|
+
dates[0].should == Date.new(2011,1,31)
|
338
|
+
dates[1].should == Date.new(2011,2,28)
|
339
|
+
dates[2].should == Date.new(2011,3,31)
|
340
|
+
dates[3].should == Date.new(2011,4,30)
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should transform YYYY-MMM-DD to date' do
|
344
|
+
dates = ['2011-jan-01','2011-feb-01','2011-mar-3','2011-apr-4']
|
345
|
+
dates = DateMaid::sweep(dates)
|
346
|
+
dates[0].should == Date.new(2011,1,1)
|
347
|
+
dates[1].should == Date.new(2011,2,1)
|
348
|
+
dates[2].should == Date.new(2011,3,3)
|
349
|
+
dates[3].should == Date.new(2011,4,4)
|
350
|
+
end
|
351
|
+
|
352
|
+
it 'should transform YYYY-MMM-DD to date (strip)' do
|
353
|
+
dates = ['2011-jan-01','2011-feb-01','2011-mar-3','2011-apr-4']
|
354
|
+
dates = DateMaid::sweep(dates)
|
355
|
+
dates[0].should == Date.new(2011,1,1)
|
356
|
+
dates[1].should == Date.new(2011,2,1)
|
357
|
+
dates[2].should == Date.new(2011,3,3)
|
358
|
+
dates[3].should == Date.new(2011,4,4)
|
359
|
+
end
|
360
|
+
|
361
|
+
|
362
|
+
it 'should transform DD-MMM-YYYY to date' do
|
363
|
+
dates = ['01-jan-2011','01-feb-2011','3-mar-2011','4-apr-2011']
|
364
|
+
dates = DateMaid::sweep(dates)
|
365
|
+
dates[0].should == Date.new(2011,1,1)
|
366
|
+
dates[1].should == Date.new(2011,2,1)
|
367
|
+
dates[2].should == Date.new(2011,3,3)
|
368
|
+
dates[3].should == Date.new(2011,4,4)
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'should transform DD-MMM-YYYY to date (strip)' do
|
372
|
+
dates = ['01-jan-2011','01-feb-2011','3-mar-2011','4-apr-2011']
|
373
|
+
dates = DateMaid::sweep(dates)
|
374
|
+
dates[0].should == Date.new(2011,1,1)
|
375
|
+
dates[1].should == Date.new(2011,2,1)
|
376
|
+
dates[2].should == Date.new(2011,3,3)
|
377
|
+
dates[3].should == Date.new(2011,4,4)
|
378
|
+
end
|
379
|
+
|
380
|
+
it 'should transform YYYYMMMDD to date (no delimiters)' do
|
381
|
+
dates = ['2011jan01','2011feb01','2011mar3','2011apr4']
|
382
|
+
dates = DateMaid::sweep(dates)
|
383
|
+
dates[0].should == Date.new(2011,1,1)
|
384
|
+
dates[1].should == Date.new(2011,2,1)
|
385
|
+
dates[2].should == Date.new(2011,3,3)
|
386
|
+
dates[3].should == Date.new(2011,4,4)
|
387
|
+
end
|
388
|
+
|
389
|
+
it 'should transform YYYYMMMDD to date (no delimiters, strip)' do
|
390
|
+
dates = ['2011jan01','2011feb01','2011mar3','2011apr4']
|
391
|
+
dates = DateMaid::sweep(dates)
|
392
|
+
dates[0].should == Date.new(2011,1,1)
|
393
|
+
dates[1].should == Date.new(2011,2,1)
|
394
|
+
dates[2].should == Date.new(2011,3,3)
|
395
|
+
dates[3].should == Date.new(2011,4,4)
|
396
|
+
end
|
397
|
+
|
398
|
+
it 'should transform DD-MMM-YYYY to date (no delimiters)' do
|
399
|
+
dates = ['01jan2011','01feb2011','3mar2011','4apr2011']
|
400
|
+
dates = DateMaid::sweep(dates)
|
401
|
+
dates[0].should == Date.new(2011,1,1)
|
402
|
+
dates[1].should == Date.new(2011,2,1)
|
403
|
+
dates[2].should == Date.new(2011,3,3)
|
404
|
+
dates[3].should == Date.new(2011,4,4)
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'should transform DD-MMM-YYYY to date (no delimiters, strip)' do
|
408
|
+
dates = ['01jan2011','01feb2011','3mar2011','4apr2011']
|
409
|
+
dates = DateMaid::sweep(dates)
|
410
|
+
dates[0].should == Date.new(2011,1,1)
|
411
|
+
dates[1].should == Date.new(2011,2,1)
|
412
|
+
dates[2].should == Date.new(2011,3,3)
|
413
|
+
dates[3].should == Date.new(2011,4,4)
|
414
|
+
end
|
415
|
+
|
416
|
+
it 'should transform yyyy-Qq to end of quarter' do
|
417
|
+
dates = ['2011-Q1','2011-Q2','2011-Q3','2011-Q4']
|
418
|
+
dates = DateMaid::sweep(dates)
|
419
|
+
dates[0].should == Date.new(2011,3,31)
|
420
|
+
dates[1].should == Date.new(2011,6,30)
|
421
|
+
dates[2].should == Date.new(2011,9,30)
|
422
|
+
dates[3].should == Date.new(2011,12,31)
|
423
|
+
end
|
424
|
+
|
425
|
+
it 'should transform yyyy-Qq to end of quarter (strip)' do
|
426
|
+
dates = ['2011-Q1','2011-Q2','2011-Q3','2011-Q4']
|
427
|
+
dates = DateMaid::sweep(dates)
|
428
|
+
dates[0].should == Date.new(2011,3,31)
|
429
|
+
dates[1].should == Date.new(2011,6,30)
|
430
|
+
dates[2].should == Date.new(2011,9,30)
|
431
|
+
dates[3].should == Date.new(2011,12,31)
|
432
|
+
end
|
433
|
+
|
434
|
+
it 'should transform yyyyQq to end of quarter (no delimiter)' do
|
435
|
+
dates = ['2011q1','2011Q2','2011q3','2011Q4,4']
|
436
|
+
dates = DateMaid::sweep(dates)
|
437
|
+
dates[0].should == Date.new(2011,3,31)
|
438
|
+
dates[1].should == Date.new(2011,6,30)
|
439
|
+
dates[2].should == Date.new(2011,9,30)
|
440
|
+
dates[3].should == Date.new(2011,12,31)
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'should handle white space at front and back of dates' do
|
444
|
+
dates = [' 2012q2 ']
|
445
|
+
dates = DateMaid::sweep(dates)
|
446
|
+
dates[0].should == Date.new(2012,6,30)
|
447
|
+
end
|
448
|
+
|
449
|
+
it 'should handle white space at front and back of dates (2)' do
|
450
|
+
dates = [' 2012 ']
|
451
|
+
dates = DateMaid::sweep(dates)
|
452
|
+
dates[0].should == Date.new(2012,12,31)
|
453
|
+
end
|
454
|
+
|
455
|
+
it 'should know 1871.10 is October' do
|
456
|
+
dates = ['1871.10']
|
457
|
+
dates = DateMaid::sweep(dates)
|
458
|
+
dates[0].should == Date.new(1871,10,31)
|
459
|
+
end
|
460
|
+
|
461
|
+
it 'should handle 1990' do
|
462
|
+
dates = ['1990']
|
463
|
+
dates = DateMaid::sweep(dates)
|
464
|
+
dates[0].should == Date.new(1990,12,31)
|
465
|
+
end
|
466
|
+
|
467
|
+
it 'should handle 1990 - 1995' do
|
468
|
+
dates = ['1990 - 1995']
|
469
|
+
dates = DateMaid::sweep(dates)
|
470
|
+
dates[0].should == Date.new(1990,12,31)
|
471
|
+
end
|
472
|
+
|
473
|
+
it 'should transform YYYYMMDD to date' do
|
474
|
+
dates = ['20010101','20110518','19701111','19770208','19900531']
|
475
|
+
dates = DateMaid::sweep(dates)
|
476
|
+
dates[0].should == Date.new(2001,1,1)
|
477
|
+
dates[1].should == Date.new(2011,5,18)
|
478
|
+
dates[2].should == Date.new(1970,11,11)
|
479
|
+
dates[3].should == Date.new(1977,2,8)
|
480
|
+
dates[4].should == Date.new(1990,5,31)
|
481
|
+
end
|
482
|
+
|
483
|
+
it 'should transform Jan 30, 1955' do
|
484
|
+
dates = ['Jan 30, 1955']
|
485
|
+
dates = DateMaid::sweep(dates)
|
486
|
+
dates[0].should == Date.new(1955,1,30)
|
487
|
+
end
|
488
|
+
|
489
|
+
it 'should transform Jan-68' do
|
490
|
+
dates = ['Dec-68','Jan-69']
|
491
|
+
dates = DateMaid::sweep(dates)
|
492
|
+
dates[0].should == Date.new(1968,12,31)
|
493
|
+
dates[1].should == Date.new(1969,1,31)
|
494
|
+
end
|
495
|
+
|
496
|
+
|
497
|
+
it 'should transform Jul-01' do
|
498
|
+
dates = ['Jul-01','Aug-01']
|
499
|
+
dates = DateMaid::sweep(dates)
|
500
|
+
dates[1].should == Date.new(2001,8,31)
|
501
|
+
dates[0].should == Date.new(2001,7,31)
|
502
|
+
end
|
503
|
+
|
504
|
+
it 'should transform Dec-31-12' do
|
505
|
+
dates = ['Dec-31-12']
|
506
|
+
dates = DateMaid::sweep(dates)
|
507
|
+
dates[0].should == Date.new(2012,12,31)
|
508
|
+
end
|
509
|
+
|
510
|
+
it 'should format YYYY/MM/DD' do
|
511
|
+
dates = ['20010101','20110518','19701111','19770208','19900531']
|
512
|
+
dates = DateMaid::sweep(dates)
|
513
|
+
dates[0].should == Date.new(2001,1,1)
|
514
|
+
dates[1].should == Date.new(2011,5,18)
|
515
|
+
dates[2].should == Date.new(1970,11,11)
|
516
|
+
dates[3].should == Date.new(1977,2,8)
|
517
|
+
dates[4].should == Date.new(1990,5,31)
|
518
|
+
end
|
519
|
+
|
520
|
+
it 'should strip days of the week' do
|
521
|
+
pending "Not implemented yet"
|
522
|
+
dates = ["Tuesday, April 30, 2013","Mon april 29, 2012"]
|
523
|
+
dates = DateMaid::sweep(dates)
|
524
|
+
dates[0].should == Date.new(2013,04,30)
|
525
|
+
dates[1].should == Date.new(2012,04,29)
|
526
|
+
end
|
527
|
+
|
528
|
+
|
529
529
|
end
|