date-formats 0.2.2 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cc67b4f49a89aa6bc05ab8836ed1da60e4378705
4
- data.tar.gz: 0f2e024892406fc95e7b365e41782dec1441612f
3
+ metadata.gz: 29983784dc5d76dd11c233430a3aee08701a711a
4
+ data.tar.gz: a2fb38dd99f5b98b924516dcf1c9f39c32fb6c20
5
5
  SHA512:
6
- metadata.gz: 2e75b49ee32ad7d9b0178509a70da635b388cb50496eedfc13cef9ecf87af0e9bccd0cdb8e1c154e7c25a7f62c7543f6dfccc00368bead0df940352f0a4bb135
7
- data.tar.gz: a4e71ff6484a61df679baea147d91b5e49ae5da4db169fc2e44b759109a878ac25d936ab3587aa2a79d0af35d4c1554acfa106cfbbe483e90ff8b76cae554da7
6
+ metadata.gz: 584abc31598b6d1eef8ffa87610122ef2df398b9b537d2fe33e704b6c2554e511526cdc9d337330e5ac70d09d9f1a34278d586f310acd593f8fa81c23ebf81f3
7
+ data.tar.gz: cb10a5e2c39a0d707f735214aeb5de52473b90619bf62f859b0217a8c0d8e19b6cb4448bed2442a52ef9c77559e5608bb38dbff7f1c233d68681ef0ddc954ba5
@@ -19,3 +19,4 @@ test/test_parse_fr.rb
19
19
  test/test_parse_it.rb
20
20
  test/test_parse_pt.rb
21
21
  test/test_version.rb
22
+ test/test_week.rb
data/README.md CHANGED
@@ -44,6 +44,54 @@ DateFormats.parse( 'Lundi 1 Janvier', lang: 'fr')
44
44
  #=> <Date: 2019-01-01 ((2458485j,0s,0n),+0s,2299161j)>
45
45
  ```
46
46
 
47
+ Pre-configured date formats for now include:
48
+
49
+ **Base - Work for All Languages**
50
+
51
+ - `YYYY_MM_DD_hh_mm` e.g. 2020-01-19 22:00 or 2020-1-19 22:00
52
+ - `YYYY_MM_DD` e.g. 2020-01-19 or 2020-1-19
53
+ - `DD_MM_YYYY_hh_mm` e.g. 19.01.2020 22.00 or 19.1.2020 22:00
54
+ - `DD_MM_hh_mm` e.g. 19.01. 22.00 or 19.1. 22:00
55
+ - `DD_MM_YYYY` e.g. 19.01.2020 or 19.1.2020
56
+ - `DD_MM` e.g. 19.01. or 19.1.
57
+
58
+ **English (`en`)**
59
+
60
+ - `DD_MONTH_YYYY_hh_mm` e.g. 19 Jan 2020 22:00
61
+ - `MONTH_DD_YYYY_hh_mm` e.g. Jan 19 2020 22:00 or Jan 19, 2020 22:00
62
+ - `MONTH_DD_hh_mm` e.g. Jan 19 22:00
63
+ - `MONTH_DD_YYYY` e.g. Jan 19 2020 or Jan 19, 2020 or January 19, 2020
64
+ - `DAY_MONTH_DD` e.g. Sun Jan 19 or Sun, Jan 19 or Sunday, January 19
65
+ - `MONTH_DD` e.g. Jan 19 or Jan/19
66
+ - `DD_MONTH` e.g. 19 Jan or 19/Jan
67
+
68
+ **Spanish / Español (`es`)**
69
+
70
+ - `DAY_DD_MONTH_hh_mm` e.g. Dom 19 Ene 22:00 or Dom 19 Ene 22h00
71
+ - `DAY_DD_MONTH` e.g. Dom 19 Ene or Dom 19 Enero
72
+ - `DD_MONTH` e.g. 19 Ene
73
+ - `DAY_DD_MM` e.g. Dom 19.01. or Dom 19.1.
74
+
75
+ **Portuguese / Português (`pt`)**
76
+
77
+ - `DD_MM_YYYY_DAY` e.g. 19/1/2020 Domenica
78
+ - `DAY_DD_MONTH` e.g. Dom 19 Jan or Dom 19 Janeiro
79
+ - `DAY_DD_MM` e.g. Dom 19/01 or Dom 19/1
80
+
81
+ **French / Français (`fr`)**
82
+
83
+ - `DAY_DD_MONTH` e.g. Dim. 19 Janv or Dim. 19 Janvier
84
+
85
+ **Italian / Italiano (`it`)**
86
+
87
+ - `DAY_MM_DD` e.g. Dom. 19.1.
88
+
89
+ **German / Deutsch (`de`)**
90
+
91
+ - `DAY_MM_DD` e.g. So 19.1. or So 19.01.
92
+
93
+
94
+
47
95
  How does it work?
48
96
  The `date-formats` library uses text patterns (that is, regular expressions)
49
97
  for defining and parsing new date formats.
@@ -55,7 +103,7 @@ For example, the Spanish date `1 Ene` gets matched by:
55
103
  ```ruby
56
104
  /\b
57
105
  (?<day>\d{1,2})
58
- \s
106
+ [ ]
59
107
  (?<month_name>#{MONTH_ES})
60
108
  \b/x
61
109
  ```
@@ -82,10 +130,10 @@ And the French date `Lundi 1 Janvier` gets matched by:
82
130
  ```ruby
83
131
  /\b
84
132
  (?<day_name>#{DAY_FR})
85
- \s+
133
+ [ ]+
86
134
  (?<day>\d{1,2})
87
135
  \.? # note: make dot optional
88
- \s+
136
+ [ ]+
89
137
  (?<month_name>#{MONTH_FR})
90
138
  \b/x
91
139
  ```
@@ -122,6 +170,7 @@ Décembre Déce Déc
122
170
  And so on.
123
171
 
124
172
 
173
+
125
174
  ## License
126
175
 
127
176
  The `date-formats` scripts are dedicated to the public domain.
data/Rakefile CHANGED
@@ -8,7 +8,7 @@ Hoe.spec 'date-formats' do
8
8
  self.summary = "date-formats - read / parse and print dates (and times) from around the world"
9
9
  self.description = summary
10
10
 
11
- self.urls = ['https://github.com/sportdb/sport.db']
11
+ self.urls = { home: 'https://github.com/sportdb/sport.db' }
12
12
 
13
13
  self.author = 'Gerald Bauer'
14
14
  self.email = 'opensport@googlegroups.com'
@@ -19,9 +19,7 @@ Hoe.spec 'date-formats' do
19
19
 
20
20
  self.licenses = ['Public Domain']
21
21
 
22
- self.extra_deps = [
23
- ['logutils', '>= 0.6.1'],
24
- ]
22
+ self.extra_deps = []
25
23
 
26
24
  self.spec_extras = {
27
25
  required_ruby_version: '>= 2.2.2'
@@ -1,20 +1,29 @@
1
- # encoding: utf-8
2
-
3
1
  require 'pp'
4
2
  require 'time'
5
3
  require 'date'
6
4
 
7
- ## 3rd party libs/gems
8
- require 'logutils'
9
-
10
5
 
11
6
  ###
12
7
  # our own code
13
8
  require 'date-formats/version' # let version always go first
9
+
10
+ ## todo/fix: make logging class configurable - lets you use logutils etc.
11
+ module DateFormats
12
+ module Logging
13
+ def logger() @logger ||= Logger.new; end
14
+
15
+ class Logger ## for now use quick "dummy" logger to
16
+ def debug( msg ) puts "[debug] #{msg}"; end
17
+ end # class Logger
18
+ end # module Logging
19
+ end # module DateFormats
20
+
21
+
14
22
  require 'date-formats/reader'
15
23
  require 'date-formats/names' ## month and day names (e.g. January,.. Monday,...)
16
24
 
17
25
 
26
+
18
27
  module DateFormats
19
28
 
20
29
  #############
@@ -6,6 +6,9 @@ module DateFormats
6
6
  # e.g. 2012-09-14 20:30 => YYYY-MM-DD HH:MM
7
7
  # note: allow 2012-9-3 7:30 e.g. no leading zero required
8
8
  # regex_db
9
+
10
+ ## todo/fix: add rule with allowed / separator (e.g. 2019/12/11)
11
+ ## BUT must be used in all following case too (NO mix'n'match allowed e.g. 2019-11/12)
9
12
  DB__DATE_TIME_RE = /\b
10
13
  (?<year>\d{4})
11
14
  -
@@ -14,7 +17,7 @@ DB__DATE_TIME_RE = /\b
14
17
  (?<day>\d{1,2})
15
18
  \s+
16
19
  (?<hours>\d{1,2})
17
- :
20
+ [:.hH]
18
21
  (?<minutes>\d{2})
19
22
  \b/x
20
23
 
@@ -42,7 +45,7 @@ DD_MM_YYYY__DATE_TIME_RE = /\b
42
45
  (?<year>\d{4})
43
46
  \s+
44
47
  (?<hours>\d{1,2})
45
- [:.]
48
+ [:.hH]
46
49
  (?<minutes>\d{2})
47
50
  \b/x
48
51
 
@@ -57,7 +60,7 @@ DD_MM__DATE_TIME_RE = /\b
57
60
  \.
58
61
  \s+
59
62
  (?<hours>\d{1,2})
60
- [:.]
63
+ [:.hH]
61
64
  (?<minutes>\d{2})
62
65
  \b/x
63
66
 
@@ -86,6 +89,7 @@ DD_MM__DATE_RE = /\b
86
89
 
87
90
  ##
88
91
  # e.g. 12 May 2013 14:00 => D|DD.MMM.YYYY H|HH:MM
92
+ # or 12 May 2013 14h00
89
93
  EN__DD_MONTH_YYYY__DATE_TIME_RE = /\b
90
94
  (?<day>\d{1,2})
91
95
  \s
@@ -94,7 +98,7 @@ EN__DD_MONTH_YYYY__DATE_TIME_RE = /\b
94
98
  (?<year>\d{4})
95
99
  \s+
96
100
  (?<hours>\d{1,2})
97
- :
101
+ [:hH]
98
102
  (?<minutes>\d{2})
99
103
  \b/x
100
104
 
@@ -105,44 +109,71 @@ EN__DD_MONTH__DATE_RE = /\b
105
109
  (?<month_name>#{MONTH_EN})
106
110
  \b/x
107
111
 
108
- # e.g. Fri Aug/9
112
+ # e.g. Fri Aug/9 or Fri Aug 9
113
+ # Fri, Aug/9 or Fri, Aug 9
109
114
  EN__DAY_MONTH_DD__DATE_RE = /\b
110
115
  (?<day_name>#{DAY_EN})
116
+ ,? # note: allow optional comma
111
117
  \s
112
118
  (?<month_name>#{MONTH_EN})
113
- \/
119
+ (?: \/|\s )
114
120
  (?<day>\d{1,2})
115
121
  \b/x
116
122
 
117
- # e.g. Jun/12 2011 14:00
123
+
124
+ # e.g. Fri Aug/9 18:00 or Fri Aug 9 18:00
125
+ # Fri, Aug/9 18:00 or Fri, Aug 9 18:00
126
+ EN__DAY_MONTH_DD__DATE_TIME_RE = /\b
127
+ (?<day_name>#{DAY_EN})
128
+ ,? # note: allow optional comma
129
+ \s
130
+ (?<month_name>#{MONTH_EN})
131
+ (?: \/|\s )
132
+ (?<day>\d{1,2})
133
+ \s+
134
+ (?<hours>\d{1,2})
135
+ [:hH]
136
+ (?<minutes>\d{2})
137
+ \b/x
138
+
139
+
140
+
141
+ # e.g. Jun/12 2011 14:00 or
142
+ # Jun 12, 2011 14:00 or
143
+ # Jun 12, 2011 14h00
118
144
  EN__MONTH_DD_YYYY__DATE_TIME_RE = /\b
119
145
  (?<month_name>#{MONTH_EN})
120
- \/
146
+ (?: \/|\s )
121
147
  (?<day>\d{1,2})
148
+ ,? # note: allow optional comma
122
149
  \s
123
150
  (?<year>\d{4})
124
151
  \s+
125
152
  (?<hours>\d{1,2})
126
- :
153
+ [:hH]
127
154
  (?<minutes>\d{2})
128
155
  \b/x
129
156
 
130
157
  # e.g. Jun/12 14:00 w/ implied year H|HH:MM
158
+ # or Jun 12 14h00
131
159
  EN__MONTH_DD__DATE_TIME_RE = /\b
132
160
  (?<month_name>#{MONTH_EN})
133
- \/
161
+ (?: \/|\s )
134
162
  (?<day>\d{1,2})
135
163
  \s+
136
164
  (?<hours>\d{1,2})
137
- :
165
+ [:hH]
138
166
  (?<minutes>\d{2})
139
167
  \b/x
140
168
 
141
169
  # e.g. Jun/12 2013
170
+ # or Jun 12 2013
171
+ # or Jun 12, 2013
142
172
  EN__MONTH_DD_YYYY__DATE_RE = /\b
143
173
  (?<month_name>#{MONTH_EN})
144
- \/
174
+ (?: \/|\s )
145
175
  (?<day>\d{1,2})
176
+ ,? # note: allow optional comma
146
177
  \s
147
178
  (?<year>\d{4})
148
179
  \b/x
@@ -152,14 +183,17 @@ EN__MONTH_DD_YYYY__DATE_RE = /\b
152
183
  # -- fix: might eat french weekday mar 12 is mardi (mar) !!! see FR__ pattern
153
184
  # fix: remove space again for now - and use simple en date reader or something!!!
154
185
  ## was [\/ ] changed back to \/
186
+
187
+ ## check if [\/ ] works!!!! in \x mode ??
155
188
  EN__MONTH_DD__DATE_RE = /\b
156
189
  (?<month_name>#{MONTH_EN})
157
- \/
190
+ (?: \/|\s )
158
191
  (?<day>\d{1,2})
159
192
  \b/x
160
193
 
161
194
 
162
195
 
196
+
163
197
  # e.g. 12 Ene w/ implied year
164
198
  ES__DD_MONTH__DATE_RE = /\b
165
199
  (?<day>\d{1,2})
@@ -167,9 +201,34 @@ ES__DD_MONTH__DATE_RE = /\b
167
201
  (?<month_name>#{MONTH_ES})
168
202
  \b/x
169
203
 
204
+ # e.g. Vie 12 Ene w/ implied year
205
+ ES__DAY_DD_MONTH__DATE_RE = /\b
206
+ (?<day_name>#{DAY_ES})
207
+ \.? # note: make dot optional
208
+ \s
209
+ (?<day>\d{1,2})
210
+ \s
211
+ (?<month_name>#{MONTH_ES})
212
+ \b/x
213
+
214
+ # e.g. Sáb 5 Ene 19:30
215
+ ES__DAY_DD_MONTH__DATE_TIME_RE = /\b
216
+ (?<day_name>#{DAY_ES})
217
+ \.? # note: make dot optional
218
+ \s
219
+ (?<day>\d{1,2})
220
+ \s
221
+ (?<month_name>#{MONTH_ES})
222
+ \s+
223
+ (?<hours>\d{1,2})
224
+ [:hH]
225
+ (?<minutes>\d{2})
226
+ \b/x
227
+
228
+
170
229
  # e.g. Vie. 16.8. or Sáb. 17.8.
171
230
  # or Vie 16.8. or Sáb 17.8.
172
- ES__DAY_MM_DD__DATE_RE = /\b
231
+ ES__DAY_DD_MM__DATE_RE = /\b
173
232
  (?<day_name>#{DAY_ES})
174
233
  \.? # note: make dot optional
175
234
  \s
@@ -218,19 +277,67 @@ PT__DD_MM_YYYY_DAY__DATE_RE = /\b
218
277
  (?<day_name>#{DAY_PT})
219
278
  \b/x
220
279
 
280
+ # e.g. Sáb, 13/Maio or Qui, 08/Junho
281
+ # or Sáb 13 Maio or Qui 8 Junho
282
+ PT__DAY_DD_MONTH__DATE_RE = /\b
283
+ (?<day_name>#{DAY_PT})
284
+ \.? # note: make dot optional
285
+ ,? # note: allow optional comma too
286
+ \s
287
+ (?<day>\d{1,2})
288
+ (?: \/|\s )
289
+ (?<month_name>#{MONTH_PT})
290
+ \b/x
291
+
292
+ # e.g. Sáb, 29/07 or Seg, 31/07
293
+ # Sáb 29/07 or Seg 31/07
294
+ PT__DAY_DD_MM__DATE_RE = /\b
295
+ (?<day_name>#{DAY_PT})
296
+ \.? # note: make dot optional
297
+ ,? # note: allow optional comma too
298
+ \s
299
+ (?<day>\d{1,2})
300
+ \/
301
+ (?<month>\d{1,2})
302
+ \b/x
303
+
304
+
305
+
306
+
307
+ # e.g. Sa., 16.5., 18.00 Uhr or Mo., 18.5., 20.30 Uhr
308
+ # Sa 16.5. 18.00 or Mo 18.5. 20.30
309
+ DE__DAY_MM_DD__DATE_TIME_RE = /\b
310
+ (?<day_name>#{DAY_DE})
311
+ \.? # note: make dot optional
312
+ ,? # note: allow optional comma too
313
+ [ ]*
314
+ (?<day>\d{1,2})
315
+ \.
316
+ (?<month>\d{1,2})
317
+ \.
318
+ ,? # note: allow optional comma too
319
+ [ ]*
320
+ (?<hours>\d{1,2})
321
+ \.
322
+ (?<minutes>\d{2})
323
+ (?:[ ]*
324
+ uhr
325
+ )? ## note: allow optional Uhr
326
+ (?=[ \]]|$)/ix ## note: allow end-of-string/line too/x
221
327
 
222
328
  # e.g. Fr. 26.7. or Sa. 27.7.
223
329
  # or Fr 26.7. or Sa 27.7.
330
+ # or Fr, 26.7. or Sa, 27.7.
224
331
  DE__DAY_MM_DD__DATE_RE = /\b
225
332
  (?<day_name>#{DAY_DE})
226
333
  \.? # note: make dot optional
334
+ ,? # note: allow optional comma too
227
335
  \s
228
336
  (?<day>\d{1,2})
229
337
  \.
230
338
  (?<month>\d{1,2})
231
339
  \.
232
- (?=\s+|$|[\]])/x ## note: allow end-of-string/line too/x
233
-
340
+ (?=[ \]]|$)/x ## note: allow end-of-string/line too/x
234
341
 
235
342
 
236
343
  #############################################
@@ -246,11 +353,12 @@ FORMATS_BASE = [ ### all numbers (no month names or weekday) - find a better
246
353
  ]
247
354
 
248
355
  FORMATS_EN = [
356
+ [ EN__DAY_MONTH_DD__DATE_TIME_RE, '[EN_DAY_MONTH_DD_hh_mm]' ],
249
357
  [ EN__DD_MONTH_YYYY__DATE_TIME_RE, '[EN_DD_MONTH_YYYY_hh_mm]' ],
250
358
  [ EN__MONTH_DD_YYYY__DATE_TIME_RE, '[EN_MONTH_DD_YYYY_hh_mm]' ],
251
359
  [ EN__MONTH_DD__DATE_TIME_RE, '[EN_MONTH_DD_hh_mm]' ],
252
360
  [ EN__MONTH_DD_YYYY__DATE_RE, '[EN_MONTH_DD_YYYY]' ],
253
- [ EN__DAY_MONTH_DD__DATE_RE, '[EN_DAY_MONTH_DD]', ],
361
+ [ EN__DAY_MONTH_DD__DATE_RE, '[EN_DAY_MONTH_DD]' ],
254
362
  [ EN__MONTH_DD__DATE_RE, '[EN_MONTH_DD]' ],
255
363
  [ EN__DD_MONTH__DATE_RE, '[EN_DD_MONTH]' ],
256
364
  ]
@@ -260,15 +368,21 @@ FORMATS_FR = [
260
368
  ]
261
369
 
262
370
  FORMATS_ES = [
371
+ [ ES__DAY_DD_MONTH__DATE_TIME_RE, '[ES_DAY_DD_MONTH_hh_mm]' ],
372
+ [ ES__DAY_DD_MONTH__DATE_RE, '[ES_DAY_DD_MONTH]' ],
263
373
  [ ES__DD_MONTH__DATE_RE, '[ES_DD_MONTH]' ],
264
- [ ES__DAY_MM_DD__DATE_RE, '[ES_DAY_MM_DD]' ],
374
+ [ ES__DAY_DD_MM__DATE_RE, '[ES_DAY_DD_MM]' ],
265
375
  ]
266
376
 
377
+
267
378
  FORMATS_PT = [
268
379
  [ PT__DD_MM_YYYY_DAY__DATE_RE, '[PT_DD_MM_YYYY_DAY]' ],
380
+ [ PT__DAY_DD_MONTH__DATE_RE, '[PT_DAY_DD_MONTH]' ],
381
+ [ PT__DAY_DD_MM__DATE_RE, '[PT_DAY_DD_MM]' ],
269
382
  ]
270
383
 
271
384
  FORMATS_DE = [
385
+ [ DE__DAY_MM_DD__DATE_TIME_RE, '[DE_DAY_MM_DD_hh_mm]' ],
272
386
  [ DE__DAY_MM_DD__DATE_RE, '[DE_DAY_MM_DD]' ],
273
387
  ]
274
388
 
@@ -1,5 +1,10 @@
1
1
  module DateFormats
2
2
 
3
+ ###
4
+ # sources:
5
+ ## see https://web.library.yale.edu/cataloging/months
6
+ ## and others
7
+
3
8
  # todo: make more generic for reuse
4
9
  ### fix:
5
10
  ## use date/en.txt or en.txt etc. -- why? why not?
@@ -27,13 +32,13 @@ TXT
27
32
 
28
33
 
29
34
  DAY_NAMES[:en] = <<TXT
30
- Monday Mon
31
- Tuesday Tues Tue Tu
32
- Wednesday Wed
35
+ Monday Mon Mo
36
+ Tuesday Tues Tue Tu
37
+ Wednesday Wed We
33
38
  Thursday Thurs Thur Thu Th
34
- Friday Fri
35
- Saturday Sat
36
- Sunday Sun
39
+ Friday Fri Fr
40
+ Saturday Sat Sa
41
+ Sunday Sun Su
37
42
  TXT
38
43
 
39
44
 
@@ -65,31 +70,31 @@ TXT
65
70
 
66
71
 
67
72
  MONTH_NAMES[:es] = <<TXT
68
- Enero Ene
69
- Febrero Feb
70
- Marzo Mar
71
- Abril Abr
72
- Mayo May
73
- Junio Jun
74
- Julio Jul
75
- Agosto Ago
76
- Septiembre Sept Sep Set ## check set in use??
77
- Octubre Oct
78
- Noviembre Nov
79
- Diciembre Dic
73
+ Enero Ene
74
+ Febrero Feb
75
+ Marzo Mar
76
+ Abril Abr
77
+ Mayo May
78
+ Junio Jun
79
+ Julio Jul
80
+ Agosto Ago
81
+ Septiembre Sept Sep Set ## check Set in use??
82
+ Octubre Oct
83
+ Noviembre Nov
84
+ Diciembre Dic
80
85
  TXT
81
86
 
82
87
  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
88
+ Lunes Lun Lu
89
+ Martes Mar Ma
90
+ Miércoles Mié Mie Mi # note: add unaccented variant (for abbreviation) - why? why not?
91
+ Jueves Jue Ju
92
+ Viernes Vie Vi
93
+ Sábado Sáb Sab Sa # note: add unaccented variants (for abbreviations) - why? why not?
94
+ Domingo Dom Do
90
95
  TXT
91
96
 
92
-
97
+
93
98
  MONTH_NAMES[:de] = <<TXT
94
99
  Jänner Januar Jan Jän # note: in Austria - Jänner; in Deutschland Januar allow both ??
95
100
  Feber Februar Feb
@@ -114,21 +119,21 @@ Freitag Fr
114
119
  Samstag Sa
115
120
  Sonntag So
116
121
  TXT
117
-
118
-
122
+
123
+
119
124
  MONTH_NAMES[:it] = <<TXT
120
- Gennaio
121
- Febbraio
122
- Marzo
123
- Aprile
124
- Maggio
125
+ Gennaio Genn
126
+ Febbraio Febbr
127
+ Marzo Mar
128
+ Aprile Apr
129
+ Maggio Magg
125
130
  Giugno
126
131
  Luglio
127
- Agosto
128
- Settembre
129
- Ottobre
130
- Novembre
131
- Dicembre
132
+ Agosto Ag
133
+ Settembre Sett
134
+ Ottobre Ott
135
+ Novembre Nov
136
+ Dicembre Dic
132
137
  TXT
133
138
 
134
139
  DAY_NAMES[:it] = <<TXT
@@ -140,21 +145,21 @@ Venerdì Ven
140
145
  Sabato Sab
141
146
  Domenica Dom Do
142
147
  TXT
143
-
148
+
144
149
 
145
150
  MONTH_NAMES[:pt] = <<TXT
146
- Janeiro
147
- Fevereiro
151
+ Janeiro Jan
152
+ Fevereiro Fev
148
153
  Março
149
154
  Abril
150
155
  Maio
151
156
  Junho
152
157
  Julho
153
158
  Agosto
154
- Setembro
155
- Outubro
156
- Novembro
157
- Dezembro
159
+ Setembro Set
160
+ Outubro Out
161
+ Novembro Nov
162
+ Dezembro Dez
158
163
  TXT
159
164
 
160
165
  DAY_NAMES[:pt] = <<TXT
@@ -163,11 +168,11 @@ Terça-feira Ter
163
168
  Quarta-feira Qua
164
169
  Quinta-feira Qui
165
170
  Sexta-feira Sex
166
- Sábado Sab
171
+ Sábado Sáb Sab # note: add unaccented variant (for abbreviation) - why? why not?
167
172
  Domingo Dom
168
173
  TXT
169
-
170
-
174
+
175
+
171
176
  MONTH_NAMES[:ro] = <<TXT
172
177
  Ianuarie
173
178
  Februarie
@@ -194,7 +199,7 @@ Duminică Du
194
199
  TXT
195
200
 
196
201
 
197
-
202
+
198
203
  DAY_NAMES[:nl] = <<TXT
199
204
  Maandag Ma
200
205
  Dinsdag Di
@@ -224,10 +229,10 @@ Péntek P
224
229
  Szombat Szo
225
230
  Vasárnap Vas
226
231
  TXT
227
-
228
-
229
-
230
-
232
+
233
+
234
+
235
+
231
236
  ############################################
232
237
  ## convert (unparsed) text to (parsed) lines with words
233
238
  MONTH_NAMES.each {|k,v| MONTH_NAMES[k] = parse_month(v) }
@@ -18,7 +18,7 @@ module DateFormats
18
18
 
19
19
  ## note: cache all "built-in" lang versions (e.g. formats == nil)
20
20
  @@parser ||= {}
21
- parser = @@parser[ lang ] ||= DateParser.new( lang: lang )
21
+ @@parser[ lang ] ||= DateParser.new( lang: lang )
22
22
  end
23
23
 
24
24
  def self.parse( line,
@@ -37,9 +37,11 @@ module DateFormats
37
37
 
38
38
 
39
39
 
40
+
40
41
  class DateParser
41
42
 
42
- include LogUtils::Logging
43
+ include Logging
44
+
43
45
 
44
46
  def initialize( lang:,
45
47
  formats: nil, month_names: nil, day_names: nil
@@ -2,8 +2,8 @@
2
2
 
3
3
 
4
4
  module DateFormats
5
- MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 2
5
+ MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
+ MINOR = 0
7
7
  PATCH = 2
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
@@ -1 +1,4 @@
1
- require_relative '../date-formats' ## note: allow require 'date/formats' too (in addition to require 'date-formats')
1
+ # note: allow require 'date/formats' too
2
+ # (in addition to require 'date-formats')
3
+
4
+ require_relative '../date-formats'
@@ -12,7 +12,12 @@ class TestParse < MiniTest::Test
12
12
  def test_date
13
13
  data = [
14
14
  [ '19.01.2013 22.00', '2013-01-19 22:00', '[DD_MM_YYYY_hh_mm]' ],
15
+ [ '19.01.2013 22h00', '2013-01-19 22:00', '[DD_MM_YYYY_hh_mm]' ],
16
+ [ '19.01.2013 22:00', '2013-01-19 22:00', '[DD_MM_YYYY_hh_mm]' ],
15
17
  [ '21.01.2013 21.30', '2013-01-21 21:30', '[DD_MM_YYYY_hh_mm]' ],
18
+ [ '21.01.2013 21:30', '2013-01-21 21:30', '[DD_MM_YYYY_hh_mm]' ],
19
+ [ '21.01.2013 21H30', '2013-01-21 21:30', '[DD_MM_YYYY_hh_mm]' ],
20
+
16
21
  [ '26.01.2013', '2013-01-26', '[DD_MM_YYYY]' ],
17
22
  [ '[26.01.2013]', '2013-01-26', '[[DD_MM_YYYY]]' ],
18
23
  [ '[21.1.]', '2013-01-21', '[[DD_MM]]' ]
@@ -14,10 +14,20 @@ class TestParseDe < MiniTest::Test
14
14
  [ 'Fr. 26.7.', '2019-07-26', '[DE_DAY_MM_DD]' ],
15
15
  [ 'Fr. 26.07.', '2019-07-26', '[DE_DAY_MM_DD]' ],
16
16
  [ 'Fr 26.7.', '2019-07-26', '[DE_DAY_MM_DD]' ],
17
+ [ 'Fr., 26.07.', '2019-07-26', '[DE_DAY_MM_DD]' ],
18
+ [ 'Fr, 26.7.', '2019-07-26', '[DE_DAY_MM_DD]' ],
17
19
  [ '[Fr. 26.7.]', '2019-07-26', '[[DE_DAY_MM_DD]]' ],
20
+
21
+ [ 'Sa., 16.5., 18.00 Uhr', '2019-05-16 18:00', '[DE_DAY_MM_DD_hh_mm]' ],
22
+ [ 'Sa 16.5. 18.00', '2019-05-16 18:00', '[DE_DAY_MM_DD_hh_mm]' ],
23
+ [ '[Sa., 16.5., 18.00 Uhr]', '2019-05-16 18:00', '[[DE_DAY_MM_DD_hh_mm]]' ],
24
+ [ '[Sa 16.5. 18.00]', '2019-05-16 18:00', '[[DE_DAY_MM_DD_hh_mm]]' ],
25
+
26
+ [ 'Mo., 18.5., 20.30 Uhr', '2019-05-18 20:30', '[DE_DAY_MM_DD_hh_mm]' ],
27
+ [ 'Mo 18.5. 20.30', '2019-05-18 20:30', '[DE_DAY_MM_DD_hh_mm]' ],
18
28
  ]
19
29
 
20
- assert_dates( data, start: Date.new( 2019, 7, 1 ), lang: 'de' )
30
+ assert_dates( data, start: Date.new( 2019, 1, 1 ), lang: 'de' )
21
31
  end
22
32
 
23
33
  end # class TestParseDe
@@ -11,18 +11,29 @@ class TestParseEn < MiniTest::Test
11
11
 
12
12
  def test_date
13
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]]' ],
14
+ [ 'Jun/12 2011 14:00', '2011-06-12 14:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
15
+ [ 'Jun 12 2011 14:00', '2011-06-12 14:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
16
+ [ 'Jun 12, 2011 14h00', '2011-06-12 14:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
17
+ [ 'Oct/12 2013 16:00', '2013-10-12 16:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
18
+ [ 'Oct 12, 2013 16H00', '2013-10-12 16:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
19
+
20
+ [ 'Jan/26 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
21
+ [ 'Jan/26, 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
22
+ [ 'Jan 26, 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
23
+
24
+ [ 'Jan/26', '2013-01-26', '[EN_MONTH_DD]' ],
25
+ [ 'Jan 26', '2013-01-26', '[EN_MONTH_DD]' ],
26
+ [ 'Jun/13', '2013-06-13', '[EN_MONTH_DD]' ],
27
+
28
+ [ '26 January', '2013-01-26', '[EN_DD_MONTH]' ],
29
+ [ '13 June', '2013-06-13', '[EN_DD_MONTH]' ],
30
+
31
+ [ 'Fri Aug/9', '2013-08-09', '[EN_DAY_MONTH_DD]' ],
32
+ [ 'Fri Aug 9', '2013-08-09', '[EN_DAY_MONTH_DD]' ],
33
+ [ 'Fri, Aug 9', '2013-08-09', '[EN_DAY_MONTH_DD]' ],
34
+ [ '[Fri Aug/9]', '2013-08-09', '[[EN_DAY_MONTH_DD]]' ],
35
+ [ '[Fri Aug 9]', '2013-08-09', '[[EN_DAY_MONTH_DD]]' ],
36
+ [ '[Fri, Aug 9]', '2013-08-09', '[[EN_DAY_MONTH_DD]]' ],
26
37
  ]
27
38
 
28
39
  assert_dates( data, start: Date.new( 2013, 1, 1 ), lang: 'en' )
@@ -11,13 +11,21 @@ class TestParseEs < MiniTest::Test
11
11
 
12
12
  def test_date
13
13
  data = [
14
- [ '12 Ene', '2019-01-12', '[ES_DD_MONTH]' ],
15
- [ '[12 Ene]', '2019-01-12', '[[ES_DD_MONTH]]' ],
14
+ [ '12 Ene', '2019-01-12', '[ES_DD_MONTH]' ],
15
+ [ '[12 Ene]', '2019-01-12', '[[ES_DD_MONTH]]' ],
16
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]]' ],
17
+ [ 'Sáb. 17.8.', '2019-08-17', '[ES_DAY_DD_MM]' ],
18
+ [ 'Sáb. 17.08.', '2019-08-17', '[ES_DAY_DD_MM]' ],
19
+ [ 'Sáb 17.8.', '2019-08-17', '[ES_DAY_DD_MM]' ],
20
+ [ '[Sáb 17.8.]', '2019-08-17', '[[ES_DAY_DD_MM]]' ],
21
+
22
+ [ 'Sáb 5 Ene', '2019-01-05', '[ES_DAY_DD_MONTH]'],
23
+ [ 'Sáb. 05 Ene', '2019-01-05', '[ES_DAY_DD_MONTH]'],
24
+ [ '[Sáb 5 Ene]', '2019-01-05', '[[ES_DAY_DD_MONTH]]'],
25
+
26
+ [ 'Sáb 5 Ene 19:30', '2019-01-05 19:30', '[ES_DAY_DD_MONTH_hh_mm]'],
27
+ [ 'Sáb. 05 Ene 19:30', '2019-01-05 19:30', '[ES_DAY_DD_MONTH_hh_mm]'],
28
+ [ 'Sáb. 5 Ene 19h30', '2019-01-05 19:30', '[ES_DAY_DD_MONTH_hh_mm]'],
21
29
  ]
22
30
 
23
31
  assert_dates( data, start: Date.new( 2019, 1, 1 ), lang: 'es' )
@@ -18,6 +18,18 @@ class TestParsePt < MiniTest::Test
18
18
  [ '09/04/2003 - Quarta-feira', '2003-04-09', '[PT_DD_MM_YYYY_DAY]' ],
19
19
  [ '9/4/2003 Quarta-feira', '2003-04-09', '[PT_DD_MM_YYYY_DAY]' ],
20
20
  [ '[9/4/2003 Quarta-feira]', '2003-04-09', '[[PT_DD_MM_YYYY_DAY]]' ],
21
+
22
+ [ 'Sáb, 13/Maio', '2003-05-13', '[PT_DAY_DD_MONTH]' ],
23
+ [ 'Sáb 13 Maio', '2003-05-13', '[PT_DAY_DD_MONTH]' ],
24
+
25
+ [ 'Qui, 08/Junho', '2003-06-08', '[PT_DAY_DD_MONTH]' ],
26
+ [ 'Qui 8 Junho', '2003-06-08', '[PT_DAY_DD_MONTH]' ],
27
+
28
+ [ 'Sáb, 29/07', '2003-07-29', '[PT_DAY_DD_MM]' ],
29
+ [ 'Sáb 29/7', '2003-07-29', '[PT_DAY_DD_MM]' ],
30
+
31
+ [ 'Seg, 31/07', '2003-07-31', '[PT_DAY_DD_MM]' ],
32
+ [ 'Seg 31/7', '2003-07-31', '[PT_DAY_DD_MM]' ],
21
33
  ]
22
34
 
23
35
  assert_dates( data, start: Date.new( 2003, 1, 1 ), lang: 'pt' )
@@ -0,0 +1,114 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_week.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestWeek < MiniTest::Test
11
+
12
+ def test_2016_17
13
+ assert_equal 51, Date.parse( '2016-12-25').cweek # Sun Dec 25
14
+ assert_equal 52, Date.parse( '2016-12-26').cweek # Mon Dec 26
15
+ assert_equal 52, Date.parse( '2016-12-31').cweek # Sat Dec 31
16
+
17
+ assert_equal 52, Date.parse( '2017-01-01').cweek # Sun Jan 1
18
+ assert_equal 1, Date.parse( '2017-01-02').cweek # Mon Jan 2
19
+ assert_equal 1, Date.parse( '2017-01-03').cweek # Tue Jan 3
20
+ assert_equal 1, Date.parse( '2017-01-08').cweek # Sun Jan 8
21
+ assert_equal 2, Date.parse( '2017-01-09').cweek # Mon Jan 9
22
+ end
23
+
24
+ def test_2017_18
25
+ assert_equal 51, Date.parse( '2017-12-24').cweek # Sun Dec 24
26
+ assert_equal 52, Date.parse( '2017-12-25').cweek # Mon Dec 25
27
+ assert_equal 52, Date.parse( '2017-12-31').cweek # Sun Dec 31
28
+
29
+ assert_equal 1, Date.parse( '2018-01-01').cweek # Mon Jan 1
30
+ assert_equal 1, Date.parse( '2018-01-02').cweek # Tue Jan 2
31
+ assert_equal 1, Date.parse( '2018-01-07').cweek # Sun Jan 7
32
+ assert_equal 2, Date.parse( '2018-01-09').cweek # Mon Jan 8
33
+ end
34
+
35
+ def test_2018_19
36
+ assert_equal 52, Date.parse( '2018-12-29').cweek # Sat Dec 29
37
+ assert_equal 52, Date.parse( '2018-12-30').cweek # Sun Dec 30
38
+ assert_equal 1, Date.parse( '2018-12-31').cweek # Mon Dec 31
39
+
40
+ assert_equal 1, Date.parse( '2019-01-01').cweek # Tue Jan 1
41
+ assert_equal 1, Date.parse( '2019-01-02').cweek # Wed Jan 2
42
+ assert_equal 1, Date.parse( '2019-01-06').cweek # Sun Jan 6
43
+ assert_equal 2, Date.parse( '2019-01-07').cweek # Mon Jan 7
44
+ end
45
+
46
+ def test_2019_20
47
+ assert_equal 52, Date.parse( '2019-12-29').cweek
48
+ assert_equal 1, Date.parse( '2019-12-30').cweek
49
+
50
+ assert_equal 1, Date.parse( '2020-01-01').cweek
51
+ assert_equal 1, Date.parse( '2020-01-05').cweek
52
+ assert_equal 2, Date.parse( '2020-01-06').cweek
53
+ end
54
+
55
+ def test_2020_21 ## note: 2020 has 53 (!) weeks
56
+ assert_equal 52, Date.parse( '2020-12-27').cweek
57
+ assert_equal 53, Date.parse( '2020-12-28').cweek # 1/7-Mon
58
+ assert_equal 53, Date.parse( '2020-12-29').cweek # 2/7-Tue
59
+ assert_equal 53, Date.parse( '2020-12-30').cweek # 3/7-Wed
60
+ assert_equal 53, Date.parse( '2020-12-31').cweek # 4/7-Thu
61
+
62
+ assert_equal 53, Date.parse( '2021-01-01').cweek # 5/7-Fri
63
+ assert_equal 53, Date.parse( '2021-01-02').cweek # 6/7-Sat
64
+ assert_equal 53, Date.parse( '2021-01-03').cweek # 7/7-Sun
65
+ assert_equal 1, Date.parse( '2021-01-04').cweek
66
+ assert_equal 1, Date.parse( '2021-01-10').cweek
67
+ assert_equal 2, Date.parse( '2021-01-11').cweek
68
+ end
69
+
70
+
71
+ def test_more_weeks
72
+ assert_equal 53, Date.parse('2004-12-31').cweek ## note: 2004 has 53(!) weeks
73
+ assert_equal 53, Date.parse('2005-01-01').cweek
74
+ assert_equal 53, Date.parse('2005-01-02').cweek
75
+ assert_equal 1, Date.parse('2005-01-03').cweek
76
+
77
+ assert_equal 52, Date.parse('2005-12-31').cweek
78
+ assert_equal 52, Date.parse('2006-01-01').cweek
79
+ assert_equal 1, Date.parse('2006-01-02').cweek
80
+
81
+ assert_equal 52, Date.parse('2006-12-31').cweek
82
+ assert_equal 1, Date.parse('2007-01-01').cweek
83
+
84
+ assert_equal 52, Date.parse('2007-12-30').cweek
85
+ assert_equal 1, Date.parse('2007-12-31').cweek
86
+ assert_equal 1, Date.parse('2008-01-01').cweek
87
+
88
+ assert_equal 52, Date.parse('2008-12-28').cweek
89
+ assert_equal 1, Date.parse('2008-12-29').cweek
90
+ assert_equal 1, Date.parse('2008-12-30').cweek
91
+ assert_equal 1, Date.parse('2008-12-31').cweek
92
+ assert_equal 1, Date.parse('2009-01-01').cweek
93
+
94
+ assert_equal 53, Date.parse('2009-12-31').cweek ## note: 2009 has 53(!) weeks
95
+ assert_equal 53, Date.parse('2010-01-01').cweek
96
+ assert_equal 53, Date.parse('2010-01-02').cweek
97
+ assert_equal 53, Date.parse('2010-01-03').cweek
98
+ assert_equal 1, Date.parse('2010-01-04').cweek
99
+
100
+
101
+
102
+ assert_equal 52, Date.parse('2012-01-01').cweek
103
+ assert_equal 1, Date.parse('2012-12-31').cweek
104
+ assert_equal 1, Date.parse('2014-12-29').cweek
105
+ assert_equal 53, Date.parse('2015-12-31').cweek ## note: 2015 has 53(!) weeks
106
+ end
107
+
108
+
109
+ def test_today
110
+ assert_equal 31, Date.parse('2018-07-30').cweek # Mon Jul 30
111
+ assert_equal 31, Date.parse('2018-08-01').cweek
112
+ assert_equal 31, Date.parse('2018-08-05').cweek # Sun Aug 5
113
+ end
114
+ end # class TestWeek
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date-formats
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 1.0.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-12-26 00:00:00.000000000 Z
11
+ date: 2020-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: logutils
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: 0.6.1
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: 0.6.1
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: rdoc
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -83,6 +69,7 @@ files:
83
69
  - test/test_parse_it.rb
84
70
  - test/test_parse_pt.rb
85
71
  - test/test_version.rb
72
+ - test/test_week.rb
86
73
  homepage: https://github.com/sportdb/sport.db
87
74
  licenses:
88
75
  - Public Domain