date-formats 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dba725c69bb4b79a72034f43db16c2a2d43025c9
4
- data.tar.gz: 99dbba88099d5d20104e83c214612e6b3d76f741
3
+ metadata.gz: 2c4e4577d590d899b2f5215e548913bb4d090e49
4
+ data.tar.gz: a6ad7a9d7d735f74e27f9759cb4c66463e68152c
5
5
  SHA512:
6
- metadata.gz: a7de7c61ea555693d16e49a47ab4a28b786aba93acf2c4fce6d0f04a5d5c7556a8d345310a2ee4c95f73967e837822302d97bed3fe2d12bfb9784e951ac81dd8
7
- data.tar.gz: 75c22de9d73ef57597ee3cc1fe31096e39a32ad00f45b5df1a5694804c639f89b2720b8ea8efd41bc9221c3023ce794c94ce565875565d9dfe1e5e0905132538
6
+ metadata.gz: 47922e36f4ff6414d6b776c83c446465961d127a2ae34494d78da520515b5877fd840e0862418bbdf91b70a35c8fac766f6ad806fc406783b3f5324a9c65c97f
7
+ data.tar.gz: f7c8932114c7f75b2fd8725f970a4f084bd66f914a1cdcff371bdadab8492ba236ccf70cc2a8c353b0779fa44e29bbb56efb890a6353d29b810c4902b6402b07
@@ -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
@@ -103,7 +103,7 @@ For example, the Spanish date `1 Ene` gets matched by:
103
103
  ```ruby
104
104
  /\b
105
105
  (?<day>\d{1,2})
106
- \s
106
+ [ ]
107
107
  (?<month_name>#{MONTH_ES})
108
108
  \b/x
109
109
  ```
@@ -130,10 +130,10 @@ And the French date `Lundi 1 Janvier` gets matched by:
130
130
  ```ruby
131
131
  /\b
132
132
  (?<day_name>#{DAY_FR})
133
- \s+
133
+ [ ]+
134
134
  (?<day>\d{1,2})
135
135
  \.? # note: make dot optional
136
- \s+
136
+ [ ]+
137
137
  (?<month_name>#{MONTH_FR})
138
138
  \b/x
139
139
  ```
data/Rakefile CHANGED
@@ -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'
@@ -4,17 +4,28 @@ require 'pp'
4
4
  require 'time'
5
5
  require 'date'
6
6
 
7
- ## 3rd party libs/gems
8
- require 'logutils'
9
-
10
7
 
11
8
  ###
12
9
  # our own code
13
10
  require 'date-formats/version' # let version always go first
11
+
12
+ ## todo/fix: make logging class configurable - lets you use logutils etc.
13
+ module DateFormats
14
+ module Logging
15
+ def logger() @logger ||= Logger.new; end
16
+
17
+ class Logger ## for now use quick "dummy" logger to
18
+ def debug( msg ) puts "[debug] #{msg}"; end
19
+ end # class Logger
20
+ end # module Logging
21
+ end # module DateFormats
22
+
23
+
14
24
  require 'date-formats/reader'
15
25
  require 'date-formats/names' ## month and day names (e.g. January,.. Monday,...)
16
26
 
17
27
 
28
+
18
29
  module DateFormats
19
30
 
20
31
  #############
@@ -304,6 +304,26 @@ PT__DAY_DD_MM__DATE_RE = /\b
304
304
 
305
305
 
306
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
307
327
 
308
328
  # e.g. Fr. 26.7. or Sa. 27.7.
309
329
  # or Fr 26.7. or Sa 27.7.
@@ -317,8 +337,7 @@ DE__DAY_MM_DD__DATE_RE = /\b
317
337
  \.
318
338
  (?<month>\d{1,2})
319
339
  \.
320
- (?=\s+|$|[\]])/x ## note: allow end-of-string/line too/x
321
-
340
+ (?=[ \]]|$)/x ## note: allow end-of-string/line too/x
322
341
 
323
342
 
324
343
  #############################################
@@ -363,6 +382,7 @@ FORMATS_PT = [
363
382
  ]
364
383
 
365
384
  FORMATS_DE = [
385
+ [ DE__DAY_MM_DD__DATE_TIME_RE, '[DE_DAY_MM_DD_hh_mm]' ],
366
386
  [ DE__DAY_MM_DD__DATE_RE, '[DE_DAY_MM_DD]' ],
367
387
  ]
368
388
 
@@ -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
@@ -4,7 +4,7 @@
4
4
  module DateFormats
5
5
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
6
6
  MINOR = 0
7
- PATCH = 0
7
+ PATCH = 1
8
8
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
9
 
10
10
  def self.version
@@ -17,9 +17,17 @@ class TestParseDe < MiniTest::Test
17
17
  [ 'Fr., 26.07.', '2019-07-26', '[DE_DAY_MM_DD]' ],
18
18
  [ 'Fr, 26.7.', '2019-07-26', '[DE_DAY_MM_DD]' ],
19
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]' ],
20
28
  ]
21
29
 
22
- assert_dates( data, start: Date.new( 2019, 7, 1 ), lang: 'de' )
30
+ assert_dates( data, start: Date.new( 2019, 1, 1 ), lang: 'de' )
23
31
  end
24
32
 
25
33
  end # class TestParseDe
@@ -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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-10 00:00:00.000000000 Z
11
+ date: 2020-05-16 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