date-formats 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +6 -0
- data/README.md +110 -1
- data/lib/date-formats.rb +8 -3
- data/lib/date-formats/formats.rb +83 -4
- data/lib/date-formats/names.rb +94 -6
- data/lib/date-formats/version.rb +1 -1
- data/test/helper.rb +49 -0
- data/test/test_parse.rb +0 -79
- data/test/test_parse_de.rb +23 -0
- data/test/test_parse_en.rb +30 -0
- data/test/test_parse_es.rb +26 -0
- data/test/test_parse_fr.rb +28 -0
- data/test/test_parse_it.rb +23 -0
- data/test/test_parse_pt.rb +26 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc67b4f49a89aa6bc05ab8836ed1da60e4378705
|
4
|
+
data.tar.gz: 0f2e024892406fc95e7b365e41782dec1441612f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2e75b49ee32ad7d9b0178509a70da635b388cb50496eedfc13cef9ecf87af0e9bccd0cdb8e1c154e7c25a7f62c7543f6dfccc00368bead0df940352f0a4bb135
|
7
|
+
data.tar.gz: a4e71ff6484a61df679baea147d91b5e49ae5da4db169fc2e44b759109a878ac25d936ab3587aa2a79d0af35d4c1554acfa106cfbbe483e90ff8b76cae554da7
|
data/Manifest.txt
CHANGED
@@ -12,4 +12,10 @@ lib/date/formats.rb
|
|
12
12
|
test/helper.rb
|
13
13
|
test/test_parse.rb
|
14
14
|
test/test_parse_custom.rb
|
15
|
+
test/test_parse_de.rb
|
16
|
+
test/test_parse_en.rb
|
17
|
+
test/test_parse_es.rb
|
18
|
+
test/test_parse_fr.rb
|
19
|
+
test/test_parse_it.rb
|
20
|
+
test/test_parse_pt.rb
|
15
21
|
test/test_version.rb
|
data/README.md
CHANGED
@@ -10,7 +10,116 @@
|
|
10
10
|
|
11
11
|
## Usage
|
12
12
|
|
13
|
-
|
13
|
+
Did you know?
|
14
|
+
Ruby's built-in standard date parser (that is, `Date.parse`)
|
15
|
+
only supports English month and day names.
|
16
|
+
Example:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
Date.parse( '1 Jan' )
|
20
|
+
#=> <Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)>
|
21
|
+
```
|
22
|
+
|
23
|
+
Let's try Spanish:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
Date.parse( '1 Ene' )
|
27
|
+
#=> invalid date (ArgumentError) in `parse`
|
28
|
+
```
|
29
|
+
|
30
|
+
What to do? Let's welcome the `date-formats` library
|
31
|
+
that lets you parse dates in foreign languages.
|
32
|
+
Example:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require `date/formats`
|
36
|
+
DateFormats.parse( '1 Ene', lang: 'es' )
|
37
|
+
#=> <Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)>
|
38
|
+
```
|
39
|
+
|
40
|
+
Or in French:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
DateFormats.parse( 'Lundi 1 Janvier', lang: 'fr')
|
44
|
+
#=> <Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)>
|
45
|
+
```
|
46
|
+
|
47
|
+
How does it work?
|
48
|
+
The `date-formats` library uses text patterns (that is, regular expressions)
|
49
|
+
for defining and parsing new date formats.
|
50
|
+
See the [`formats.rb`](lib/date-formats/formats.rb) script for all
|
51
|
+
current supported formats and languages.
|
52
|
+
|
53
|
+
For example, the Spanish date `1 Ene` gets matched by:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
/\b
|
57
|
+
(?<day>\d{1,2})
|
58
|
+
\s
|
59
|
+
(?<month_name>#{MONTH_ES})
|
60
|
+
\b/x
|
61
|
+
```
|
62
|
+
|
63
|
+
Where `MONTH_ES` is any of:
|
64
|
+
|
65
|
+
```
|
66
|
+
Enero Ene
|
67
|
+
Febrero Feb
|
68
|
+
Marzo Mar
|
69
|
+
Abril Abr
|
70
|
+
Mayo May
|
71
|
+
Junio Jun
|
72
|
+
Julio Jul
|
73
|
+
Agosto Ago
|
74
|
+
Septiembre Sept Sep Set
|
75
|
+
Octubre Oct
|
76
|
+
Noviembre Nov
|
77
|
+
Diciembre Dic
|
78
|
+
```
|
79
|
+
|
80
|
+
And the French date `Lundi 1 Janvier` gets matched by:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
/\b
|
84
|
+
(?<day_name>#{DAY_FR})
|
85
|
+
\s+
|
86
|
+
(?<day>\d{1,2})
|
87
|
+
\.? # note: make dot optional
|
88
|
+
\s+
|
89
|
+
(?<month_name>#{MONTH_FR})
|
90
|
+
\b/x
|
91
|
+
```
|
92
|
+
|
93
|
+
Where `DAY_FR` is any of:
|
94
|
+
|
95
|
+
```
|
96
|
+
Lundi Lun L
|
97
|
+
Mardi Mar Ma
|
98
|
+
Mercredi Mer Me
|
99
|
+
Jeudi Jeu J
|
100
|
+
Vendredi Ven V
|
101
|
+
Samedi Sam S
|
102
|
+
Dimanche Dim D
|
103
|
+
```
|
104
|
+
|
105
|
+
And `MONTH_FR` is any of:
|
106
|
+
|
107
|
+
```
|
108
|
+
Janvier Janv Jan
|
109
|
+
Février Févr Fév
|
110
|
+
Mars Mar
|
111
|
+
Avril Avri Avr
|
112
|
+
Mai
|
113
|
+
Juin
|
114
|
+
Juillet Juil
|
115
|
+
Août
|
116
|
+
Septembre Sept
|
117
|
+
Octobre Octo Oct
|
118
|
+
Novembre Nove Nov
|
119
|
+
Décembre Déce Déc
|
120
|
+
```
|
121
|
+
|
122
|
+
And so on.
|
14
123
|
|
15
124
|
|
16
125
|
## License
|
data/lib/date-formats.rb
CHANGED
@@ -19,18 +19,23 @@ module DateFormats
|
|
19
19
|
|
20
20
|
#############
|
21
21
|
# helpers for building format regex patterns
|
22
|
-
MONTH_EN = build_names( MONTH_NAMES[:en] )
|
23
|
-
# e.g. Jan|Feb|March|Mar|April|Apr|May|June|Jun|...
|
22
|
+
MONTH_EN = build_names( MONTH_NAMES[:en] ) # e.g. Jan|Feb|March|Mar|April|Apr|May|June|Jun|...
|
24
23
|
DAY_EN = build_names( DAY_NAMES[:en] )
|
25
|
-
# e.g.
|
26
24
|
|
27
25
|
MONTH_FR = build_names( MONTH_NAMES[:fr] )
|
28
26
|
DAY_FR = build_names( DAY_NAMES[:fr] )
|
29
27
|
|
30
28
|
MONTH_ES = build_names( MONTH_NAMES[:es] )
|
29
|
+
DAY_ES = build_names( DAY_NAMES[:es] )
|
30
|
+
|
31
31
|
MONTH_PT = build_names( MONTH_NAMES[:pt] )
|
32
|
+
DAY_PT = build_names( DAY_NAMES[:pt] )
|
33
|
+
|
32
34
|
MONTH_DE = build_names( MONTH_NAMES[:de] )
|
35
|
+
DAY_DE = build_names( DAY_NAMES[:de] )
|
36
|
+
|
33
37
|
MONTH_IT = build_names( MONTH_NAMES[:it] )
|
38
|
+
DAY_IT = build_names( DAY_NAMES[:it] )
|
34
39
|
|
35
40
|
end # module DateFormats
|
36
41
|
|
data/lib/date-formats/formats.rb
CHANGED
@@ -105,6 +105,15 @@ EN__DD_MONTH__DATE_RE = /\b
|
|
105
105
|
(?<month_name>#{MONTH_EN})
|
106
106
|
\b/x
|
107
107
|
|
108
|
+
# e.g. Fri Aug/9
|
109
|
+
EN__DAY_MONTH_DD__DATE_RE = /\b
|
110
|
+
(?<day_name>#{DAY_EN})
|
111
|
+
\s
|
112
|
+
(?<month_name>#{MONTH_EN})
|
113
|
+
\/
|
114
|
+
(?<day>\d{1,2})
|
115
|
+
\b/x
|
116
|
+
|
108
117
|
# e.g. Jun/12 2011 14:00
|
109
118
|
EN__MONTH_DD_YYYY__DATE_TIME_RE = /\b
|
110
119
|
(?<month_name>#{MONTH_EN})
|
@@ -158,6 +167,32 @@ ES__DD_MONTH__DATE_RE = /\b
|
|
158
167
|
(?<month_name>#{MONTH_ES})
|
159
168
|
\b/x
|
160
169
|
|
170
|
+
# e.g. Vie. 16.8. or Sáb. 17.8.
|
171
|
+
# or Vie 16.8. or Sáb 17.8.
|
172
|
+
ES__DAY_MM_DD__DATE_RE = /\b
|
173
|
+
(?<day_name>#{DAY_ES})
|
174
|
+
\.? # note: make dot optional
|
175
|
+
\s
|
176
|
+
(?<day>\d{1,2})
|
177
|
+
\.
|
178
|
+
(?<month>\d{1,2})
|
179
|
+
\.
|
180
|
+
(?=\s+|$|[\]])/x ## note: allow end-of-string/line too/x
|
181
|
+
|
182
|
+
|
183
|
+
# e.g. Sab. 24.8. or Dom. 25.8.
|
184
|
+
# or Sab 24.8. or Dom 25.8.
|
185
|
+
IT__DAY_MM_DD__DATE_RE = /\b
|
186
|
+
(?<day_name>#{DAY_IT})
|
187
|
+
\.? # note: make dot optional
|
188
|
+
\s
|
189
|
+
(?<day>\d{1,2})
|
190
|
+
\.
|
191
|
+
(?<month>\d{1,2})
|
192
|
+
\.
|
193
|
+
(?=\s+|$|[\]])/x ## note: allow end-of-string/line too/x
|
194
|
+
|
195
|
+
|
161
196
|
# e.g. Ven 8 Août or [Ven 8 Août] or Ven 8. Août or [Ven 8. Août]
|
162
197
|
### note: do NOT consume [] in regex (use lookahead assert)
|
163
198
|
FR__DAY_DD_MONTH__DATE_RE = /\b
|
@@ -167,7 +202,34 @@ FR__DAY_DD_MONTH__DATE_RE = /\b
|
|
167
202
|
\.? # note: make dot optional
|
168
203
|
\s+
|
169
204
|
(?<month_name>#{MONTH_FR})
|
170
|
-
|
205
|
+
\b/x
|
206
|
+
|
207
|
+
|
208
|
+
# e.g. 29/03/2003 - Sábado or
|
209
|
+
# 29/3/2003 Sábado
|
210
|
+
PT__DD_MM_YYYY_DAY__DATE_RE = /\b
|
211
|
+
(?<day>\d{1,2})
|
212
|
+
\/
|
213
|
+
(?<month>\d{1,2})
|
214
|
+
\/
|
215
|
+
(?<year>\d{4})
|
216
|
+
\s+
|
217
|
+
(?: -\s+ )? # note: make dash separator (-) optional
|
218
|
+
(?<day_name>#{DAY_PT})
|
219
|
+
\b/x
|
220
|
+
|
221
|
+
|
222
|
+
# e.g. Fr. 26.7. or Sa. 27.7.
|
223
|
+
# or Fr 26.7. or Sa 27.7.
|
224
|
+
DE__DAY_MM_DD__DATE_RE = /\b
|
225
|
+
(?<day_name>#{DAY_DE})
|
226
|
+
\.? # note: make dot optional
|
227
|
+
\s
|
228
|
+
(?<day>\d{1,2})
|
229
|
+
\.
|
230
|
+
(?<month>\d{1,2})
|
231
|
+
\.
|
232
|
+
(?=\s+|$|[\]])/x ## note: allow end-of-string/line too/x
|
171
233
|
|
172
234
|
|
173
235
|
|
@@ -188,6 +250,7 @@ FORMATS_EN = [
|
|
188
250
|
[ EN__MONTH_DD_YYYY__DATE_TIME_RE, '[EN_MONTH_DD_YYYY_hh_mm]' ],
|
189
251
|
[ EN__MONTH_DD__DATE_TIME_RE, '[EN_MONTH_DD_hh_mm]' ],
|
190
252
|
[ EN__MONTH_DD_YYYY__DATE_RE, '[EN_MONTH_DD_YYYY]' ],
|
253
|
+
[ EN__DAY_MONTH_DD__DATE_RE, '[EN_DAY_MONTH_DD]', ],
|
191
254
|
[ EN__MONTH_DD__DATE_RE, '[EN_MONTH_DD]' ],
|
192
255
|
[ EN__DD_MONTH__DATE_RE, '[EN_DD_MONTH]' ],
|
193
256
|
]
|
@@ -198,13 +261,29 @@ FORMATS_FR = [
|
|
198
261
|
|
199
262
|
FORMATS_ES = [
|
200
263
|
[ ES__DD_MONTH__DATE_RE, '[ES_DD_MONTH]' ],
|
264
|
+
[ ES__DAY_MM_DD__DATE_RE, '[ES_DAY_MM_DD]' ],
|
265
|
+
]
|
266
|
+
|
267
|
+
FORMATS_PT = [
|
268
|
+
[ PT__DD_MM_YYYY_DAY__DATE_RE, '[PT_DD_MM_YYYY_DAY]' ],
|
269
|
+
]
|
270
|
+
|
271
|
+
FORMATS_DE = [
|
272
|
+
[ DE__DAY_MM_DD__DATE_RE, '[DE_DAY_MM_DD]' ],
|
273
|
+
]
|
274
|
+
|
275
|
+
FORMATS_IT = [
|
276
|
+
[ IT__DAY_MM_DD__DATE_RE, '[IT_DAY_MM_DD]' ],
|
201
277
|
]
|
202
278
|
|
203
279
|
|
204
280
|
FORMATS = {
|
205
|
-
en: FORMATS_BASE
|
206
|
-
fr: FORMATS_BASE
|
207
|
-
es: FORMATS_BASE
|
281
|
+
en: FORMATS_EN + FORMATS_BASE,
|
282
|
+
fr: FORMATS_FR + FORMATS_BASE,
|
283
|
+
es: FORMATS_ES + FORMATS_BASE,
|
284
|
+
pt: FORMATS_PT + FORMATS_BASE,
|
285
|
+
de: FORMATS_DE + FORMATS_BASE,
|
286
|
+
it: FORMATS_IT + FORMATS_BASE,
|
208
287
|
}
|
209
288
|
|
210
289
|
end # module DateFormats
|
data/lib/date-formats/names.rb
CHANGED
@@ -54,17 +54,16 @@ Décembre Déce Déc ## check dece in use??
|
|
54
54
|
TXT
|
55
55
|
|
56
56
|
DAY_NAMES[:fr] = <<TXT
|
57
|
-
Lundi Lun L
|
57
|
+
Lundi Lun Lu L
|
58
58
|
Mardi Mar Ma
|
59
59
|
Mercredi Mer Me
|
60
|
-
Jeudi Jeu J
|
61
|
-
Vendredi Ven V
|
62
|
-
Samedi Sam S
|
63
|
-
Dimanche Dim D
|
60
|
+
Jeudi Jeu Je J
|
61
|
+
Vendredi Ven Ve V
|
62
|
+
Samedi Sam Sa S
|
63
|
+
Dimanche Dim Di D
|
64
64
|
TXT
|
65
65
|
|
66
66
|
|
67
|
-
|
68
67
|
MONTH_NAMES[:es] = <<TXT
|
69
68
|
Enero Ene
|
70
69
|
Febrero Feb
|
@@ -80,6 +79,17 @@ Noviembre Nov
|
|
80
79
|
Diciembre Dic
|
81
80
|
TXT
|
82
81
|
|
82
|
+
DAY_NAMES[:es] = <<TXT
|
83
|
+
Lunes Lun Lu
|
84
|
+
Martes Mar Ma
|
85
|
+
Miércoles Mié Mi
|
86
|
+
Jueves Jue Ju
|
87
|
+
Viernes Vie Vi
|
88
|
+
Sábado Sáb Sá
|
89
|
+
Domingo Dom Do
|
90
|
+
TXT
|
91
|
+
|
92
|
+
|
83
93
|
MONTH_NAMES[:de] = <<TXT
|
84
94
|
Jänner Januar Jan Jän # note: in Austria - Jänner; in Deutschland Januar allow both ??
|
85
95
|
Feber Februar Feb
|
@@ -95,6 +105,17 @@ November Nov
|
|
95
105
|
Dezember Dez
|
96
106
|
TXT
|
97
107
|
|
108
|
+
DAY_NAMES[:de] = <<TXT
|
109
|
+
Montag Mo
|
110
|
+
Dienstag Di
|
111
|
+
Mittwoch Mi
|
112
|
+
Donnerstag Do
|
113
|
+
Freitag Fr
|
114
|
+
Samstag Sa
|
115
|
+
Sonntag So
|
116
|
+
TXT
|
117
|
+
|
118
|
+
|
98
119
|
MONTH_NAMES[:it] = <<TXT
|
99
120
|
Gennaio
|
100
121
|
Febbraio
|
@@ -110,6 +131,17 @@ Novembre
|
|
110
131
|
Dicembre
|
111
132
|
TXT
|
112
133
|
|
134
|
+
DAY_NAMES[:it] = <<TXT
|
135
|
+
Lunedì Lun
|
136
|
+
Martedì Mar
|
137
|
+
Mercoledì Mer
|
138
|
+
Giovedì Gio
|
139
|
+
Venerdì Ven
|
140
|
+
Sabato Sab
|
141
|
+
Domenica Dom Do
|
142
|
+
TXT
|
143
|
+
|
144
|
+
|
113
145
|
MONTH_NAMES[:pt] = <<TXT
|
114
146
|
Janeiro
|
115
147
|
Fevereiro
|
@@ -125,6 +157,17 @@ Novembro
|
|
125
157
|
Dezembro
|
126
158
|
TXT
|
127
159
|
|
160
|
+
DAY_NAMES[:pt] = <<TXT
|
161
|
+
Segunda-feira Seg
|
162
|
+
Terça-feira Ter
|
163
|
+
Quarta-feira Qua
|
164
|
+
Quinta-feira Qui
|
165
|
+
Sexta-feira Sex
|
166
|
+
Sábado Sab
|
167
|
+
Domingo Dom
|
168
|
+
TXT
|
169
|
+
|
170
|
+
|
128
171
|
MONTH_NAMES[:ro] = <<TXT
|
129
172
|
Ianuarie
|
130
173
|
Februarie
|
@@ -140,6 +183,51 @@ Noiembrie
|
|
140
183
|
Decembrie
|
141
184
|
TXT
|
142
185
|
|
186
|
+
DAY_NAMES[:ro] = <<TXT
|
187
|
+
Luni Lu
|
188
|
+
Marți Ma
|
189
|
+
Miercuri Mi
|
190
|
+
Joi Jo
|
191
|
+
Vineri Vi
|
192
|
+
Sâmbătă Sb
|
193
|
+
Duminică Du
|
194
|
+
TXT
|
195
|
+
|
196
|
+
|
197
|
+
|
198
|
+
DAY_NAMES[:nl] = <<TXT
|
199
|
+
Maandag Ma
|
200
|
+
Dinsdag Di
|
201
|
+
Woensdag Woe Wo
|
202
|
+
Donderdag Don Do
|
203
|
+
Vrijdag Vrij Vr
|
204
|
+
Zaterdag Zat Za
|
205
|
+
Zondag Zon Zo
|
206
|
+
TXT
|
207
|
+
|
208
|
+
DAY_NAMES[:cz] = <<TXT
|
209
|
+
Pondělí Po
|
210
|
+
Úterý Út
|
211
|
+
Středa St
|
212
|
+
Čtvrtek Čt
|
213
|
+
Pátek Pá
|
214
|
+
Sobota So
|
215
|
+
Neděle Ne
|
216
|
+
TXT
|
217
|
+
|
218
|
+
DAY_NAMES[:hu] = <<TXT
|
219
|
+
Hétfő H
|
220
|
+
Kedd K
|
221
|
+
Szerda Sze
|
222
|
+
Csütörtök Csüt
|
223
|
+
Péntek P
|
224
|
+
Szombat Szo
|
225
|
+
Vasárnap Vas
|
226
|
+
TXT
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
|
143
231
|
############################################
|
144
232
|
## convert (unparsed) text to (parsed) lines with words
|
145
233
|
MONTH_NAMES.each {|k,v| MONTH_NAMES[k] = parse_month(v) }
|
data/lib/date-formats/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -8,3 +8,52 @@ require 'minitest/autorun'
|
|
8
8
|
## our own code
|
9
9
|
|
10
10
|
require 'date/formats' ## or require 'date-formats'
|
11
|
+
|
12
|
+
|
13
|
+
#####################
|
14
|
+
## add assert helpers for dates
|
15
|
+
class MiniTest::Test
|
16
|
+
def assert_dates( data, start:, lang: 'en' )
|
17
|
+
data.each do |rec|
|
18
|
+
line = rec[0]
|
19
|
+
str = rec[1]
|
20
|
+
|
21
|
+
## note: test / use parse and find! -- parse MUST go first
|
22
|
+
values = []
|
23
|
+
values << DateFormats.parse( line, start: start, lang: lang )
|
24
|
+
values << DateFormats.find!( line, start: start, lang: lang )
|
25
|
+
|
26
|
+
tagged_line = rec[2] ## optinal tagged line
|
27
|
+
if tagged_line ## note: line gets tagged inplace!!! (no new string)
|
28
|
+
assert_equal line, tagged_line
|
29
|
+
puts "#{line} == #{tagged_line}"
|
30
|
+
end
|
31
|
+
|
32
|
+
values.each do |value|
|
33
|
+
if str.index( ':' )
|
34
|
+
assert_datetime( DateTime.strptime( str, '%Y-%m-%d %H:%M' ), value )
|
35
|
+
else
|
36
|
+
assert_date( Date.strptime( str, '%Y-%m-%d' ), value )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
## todo: check if assert_datetime or assert_date exist already? what is the best practice to check dates ???
|
44
|
+
def assert_date( exp, value )
|
45
|
+
assert_equal exp.year, value.year
|
46
|
+
assert_equal exp.month, value.month
|
47
|
+
assert_equal exp.day, value.day
|
48
|
+
end
|
49
|
+
|
50
|
+
def assert_time( exp, value )
|
51
|
+
assert_equal exp.hour, value.hour
|
52
|
+
assert_equal exp.min, value.min
|
53
|
+
end
|
54
|
+
|
55
|
+
def assert_datetime( exp, value )
|
56
|
+
assert_date( exp, value )
|
57
|
+
assert_time( exp, value )
|
58
|
+
end
|
59
|
+
end
|
data/test/test_parse.rb
CHANGED
@@ -20,83 +20,4 @@ class TestParse < MiniTest::Test
|
|
20
20
|
|
21
21
|
assert_dates( data, start: Date.new( 2013, 1, 1 ) )
|
22
22
|
end
|
23
|
-
|
24
|
-
def test_date_fr
|
25
|
-
data = [
|
26
|
-
[ '[Ven 08. Août]', '2014-08-08', '[[FR_DAY_DD_MONTH]]' ],
|
27
|
-
[ 'Ven 08. Août', '2014-08-08', '[FR_DAY_DD_MONTH]' ],
|
28
|
-
[ 'Ven 8. Août', '2014-08-08', '[FR_DAY_DD_MONTH]' ],
|
29
|
-
[ '[Sam 9. Août]', '2014-08-09', '[[FR_DAY_DD_MONTH]]' ],
|
30
|
-
[ '[Dim 10. Août]', '2014-08-10', '[[FR_DAY_DD_MONTH]]' ],
|
31
|
-
[ '[Sam 31. Janv]', '2015-01-31', '[[FR_DAY_DD_MONTH]]' ],
|
32
|
-
[ '[Sam 7. Févr]', '2015-02-07', '[[FR_DAY_DD_MONTH]]' ],
|
33
|
-
[ '[Sam 31. Jan]', '2015-01-31', '[[FR_DAY_DD_MONTH]]' ],
|
34
|
-
[ '[Sam 7. Fév]', '2015-02-07', '[[FR_DAY_DD_MONTH]]' ],
|
35
|
-
]
|
36
|
-
|
37
|
-
assert_dates( data, start: Date.new( 2014, 8, 1 ), lang: 'fr' )
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_date_en
|
41
|
-
data = [
|
42
|
-
[ 'Jun/12 2011 14:00', '2011-06-12 14:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
|
43
|
-
[ 'Oct/12 2013 16:00', '2013-10-12 16:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
|
44
|
-
|
45
|
-
[ 'Jan/26 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
|
46
|
-
[ 'Jan/26', '2013-01-26', '[EN_MONTH_DD]' ],
|
47
|
-
[ '26 January', '2013-01-26', '[EN_DD_MONTH]' ],
|
48
|
-
|
49
|
-
[ 'Jun/13', '2013-06-13', '[EN_MONTH_DD]' ],
|
50
|
-
[ '13 June', '2013-06-13', '[EN_DD_MONTH]' ],
|
51
|
-
]
|
52
|
-
|
53
|
-
assert_dates( data, start: Date.new( 2013, 1, 1 ), lang: 'en' )
|
54
|
-
end
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
private
|
59
|
-
def assert_dates( data, start:, lang: 'en' )
|
60
|
-
data.each do |rec|
|
61
|
-
line = rec[0]
|
62
|
-
str = rec[1]
|
63
|
-
|
64
|
-
## note: test / use parse and find! -- parse MUST go first
|
65
|
-
values = []
|
66
|
-
values << DateFormats.parse( line, start: start, lang: lang )
|
67
|
-
values << DateFormats.find!( line, start: start, lang: lang )
|
68
|
-
|
69
|
-
tagged_line = rec[2] ## optinal tagged line
|
70
|
-
if tagged_line ## note: line gets tagged inplace!!! (no new string)
|
71
|
-
assert_equal line, tagged_line
|
72
|
-
puts "#{line} == #{tagged_line}"
|
73
|
-
end
|
74
|
-
|
75
|
-
values.each do |value|
|
76
|
-
if str.index( ':' )
|
77
|
-
assert_datetime( DateTime.strptime( str, '%Y-%m-%d %H:%M' ), value )
|
78
|
-
else
|
79
|
-
assert_date( Date.strptime( str, '%Y-%m-%d' ), value )
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
|
86
|
-
## todo: check if assert_datetime or assert_date exist already? what is the best practice to check dates ???
|
87
|
-
def assert_date( exp, value )
|
88
|
-
assert_equal exp.year, value.year
|
89
|
-
assert_equal exp.month, value.month
|
90
|
-
assert_equal exp.day, value.day
|
91
|
-
end
|
92
|
-
|
93
|
-
def assert_time( exp, value )
|
94
|
-
assert_equal exp.hour, value.hour
|
95
|
-
assert_equal exp.min, value.min
|
96
|
-
end
|
97
|
-
|
98
|
-
def assert_datetime( exp, value )
|
99
|
-
assert_date( exp, value )
|
100
|
-
assert_time( exp, value )
|
101
|
-
end
|
102
23
|
end # class TestParse
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_de.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParseDe < MiniTest::Test
|
11
|
+
|
12
|
+
def test_date
|
13
|
+
data = [
|
14
|
+
[ 'Fr. 26.7.', '2019-07-26', '[DE_DAY_MM_DD]' ],
|
15
|
+
[ 'Fr. 26.07.', '2019-07-26', '[DE_DAY_MM_DD]' ],
|
16
|
+
[ 'Fr 26.7.', '2019-07-26', '[DE_DAY_MM_DD]' ],
|
17
|
+
[ '[Fr. 26.7.]', '2019-07-26', '[[DE_DAY_MM_DD]]' ],
|
18
|
+
]
|
19
|
+
|
20
|
+
assert_dates( data, start: Date.new( 2019, 7, 1 ), lang: 'de' )
|
21
|
+
end
|
22
|
+
|
23
|
+
end # class TestParseDe
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_en.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParseEn < MiniTest::Test
|
11
|
+
|
12
|
+
def test_date
|
13
|
+
data = [
|
14
|
+
[ 'Jun/12 2011 14:00', '2011-06-12 14:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
|
15
|
+
[ 'Oct/12 2013 16:00', '2013-10-12 16:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
|
16
|
+
|
17
|
+
[ 'Jan/26 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
|
18
|
+
[ 'Jan/26', '2013-01-26', '[EN_MONTH_DD]' ],
|
19
|
+
[ '26 January', '2013-01-26', '[EN_DD_MONTH]' ],
|
20
|
+
|
21
|
+
[ 'Jun/13', '2013-06-13', '[EN_MONTH_DD]' ],
|
22
|
+
[ '13 June', '2013-06-13', '[EN_DD_MONTH]' ],
|
23
|
+
|
24
|
+
[ 'Fri Aug/9', '2013-08-09', '[EN_DAY_MONTH_DD]' ],
|
25
|
+
[ '[Fri Aug/9]', '2013-08-09', '[[EN_DAY_MONTH_DD]]' ],
|
26
|
+
]
|
27
|
+
|
28
|
+
assert_dates( data, start: Date.new( 2013, 1, 1 ), lang: 'en' )
|
29
|
+
end
|
30
|
+
end # class TestParseEn
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_es.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParseEs < MiniTest::Test
|
11
|
+
|
12
|
+
def test_date
|
13
|
+
data = [
|
14
|
+
[ '12 Ene', '2019-01-12', '[ES_DD_MONTH]' ],
|
15
|
+
[ '[12 Ene]', '2019-01-12', '[[ES_DD_MONTH]]' ],
|
16
|
+
|
17
|
+
[ 'Sáb. 17.8.', '2019-08-17', '[ES_DAY_MM_DD]' ],
|
18
|
+
[ 'Sáb. 17.08.', '2019-08-17', '[ES_DAY_MM_DD]' ],
|
19
|
+
[ 'Sáb 17.8.', '2019-08-17', '[ES_DAY_MM_DD]' ],
|
20
|
+
[ '[Sáb 17.8.]', '2019-08-17', '[[ES_DAY_MM_DD]]' ],
|
21
|
+
]
|
22
|
+
|
23
|
+
assert_dates( data, start: Date.new( 2019, 1, 1 ), lang: 'es' )
|
24
|
+
end
|
25
|
+
|
26
|
+
end # class TestParseEs
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_fr.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParseFr < MiniTest::Test
|
11
|
+
|
12
|
+
def test_date
|
13
|
+
data = [
|
14
|
+
[ '[Ven 08. Août]', '2014-08-08', '[[FR_DAY_DD_MONTH]]' ],
|
15
|
+
[ 'Ven 08. Août', '2014-08-08', '[FR_DAY_DD_MONTH]' ],
|
16
|
+
[ 'Ven 8. Août', '2014-08-08', '[FR_DAY_DD_MONTH]' ],
|
17
|
+
[ '[Sam 9. Août]', '2014-08-09', '[[FR_DAY_DD_MONTH]]' ],
|
18
|
+
[ '[Dim 10. Août]', '2014-08-10', '[[FR_DAY_DD_MONTH]]' ],
|
19
|
+
[ '[Sam 31. Janv]', '2015-01-31', '[[FR_DAY_DD_MONTH]]' ],
|
20
|
+
[ '[Sam 7. Févr]', '2015-02-07', '[[FR_DAY_DD_MONTH]]' ],
|
21
|
+
[ '[Sam 31. Jan]', '2015-01-31', '[[FR_DAY_DD_MONTH]]' ],
|
22
|
+
[ '[Sam 7. Fév]', '2015-02-07', '[[FR_DAY_DD_MONTH]]' ],
|
23
|
+
]
|
24
|
+
|
25
|
+
assert_dates( data, start: Date.new( 2014, 8, 1 ), lang: 'fr' )
|
26
|
+
end
|
27
|
+
|
28
|
+
end # class TestParseFr
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_it.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParseIt < MiniTest::Test
|
11
|
+
|
12
|
+
def test_date
|
13
|
+
data = [
|
14
|
+
[ 'Sab. 24.8.', '2019-08-24', '[IT_DAY_MM_DD]' ],
|
15
|
+
[ 'Sab. 24.08.', '2019-08-24', '[IT_DAY_MM_DD]' ],
|
16
|
+
[ 'Sab 24.8.', '2019-08-24', '[IT_DAY_MM_DD]' ],
|
17
|
+
[ '[Sab. 24.8.]', '2019-08-24', '[[IT_DAY_MM_DD]]' ],
|
18
|
+
]
|
19
|
+
|
20
|
+
assert_dates( data, start: Date.new( 2019, 1, 1 ), lang: 'it' )
|
21
|
+
end
|
22
|
+
|
23
|
+
end # class TestParseIt
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_pt.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParsePt < MiniTest::Test
|
11
|
+
|
12
|
+
def test_date
|
13
|
+
data = [
|
14
|
+
[ '29/03/2003 - Sábado', '2003-03-29', '[PT_DD_MM_YYYY_DAY]' ],
|
15
|
+
[ '29/3/2003 Sábado', '2003-03-29', '[PT_DD_MM_YYYY_DAY]' ],
|
16
|
+
[ '[29/3/2003 Sábado]', '2003-03-29', '[[PT_DD_MM_YYYY_DAY]]' ],
|
17
|
+
|
18
|
+
[ '09/04/2003 - Quarta-feira', '2003-04-09', '[PT_DD_MM_YYYY_DAY]' ],
|
19
|
+
[ '9/4/2003 Quarta-feira', '2003-04-09', '[PT_DD_MM_YYYY_DAY]' ],
|
20
|
+
[ '[9/4/2003 Quarta-feira]', '2003-04-09', '[[PT_DD_MM_YYYY_DAY]]' ],
|
21
|
+
]
|
22
|
+
|
23
|
+
assert_dates( data, start: Date.new( 2003, 1, 1 ), lang: 'pt' )
|
24
|
+
end
|
25
|
+
|
26
|
+
end # class TestParsePt
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: date-formats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-12-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: logutils
|
@@ -76,6 +76,12 @@ files:
|
|
76
76
|
- test/helper.rb
|
77
77
|
- test/test_parse.rb
|
78
78
|
- test/test_parse_custom.rb
|
79
|
+
- test/test_parse_de.rb
|
80
|
+
- test/test_parse_en.rb
|
81
|
+
- test/test_parse_es.rb
|
82
|
+
- test/test_parse_fr.rb
|
83
|
+
- test/test_parse_it.rb
|
84
|
+
- test/test_parse_pt.rb
|
79
85
|
- test/test_version.rb
|
80
86
|
homepage: https://github.com/sportdb/sport.db
|
81
87
|
licenses:
|