date-formats 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +5 -4
- data/lib/date-formats.rb +2 -2
- data/lib/date-formats/formats.rb +1 -0
- data/lib/date-formats/{source.rb → names.rb} +0 -0
- data/lib/date-formats/{date.rb → parser.rb} +14 -13
- data/lib/date-formats/version.rb +1 -1
- data/test/{test_date.rb → test_parse.rb} +3 -9
- data/test/test_parse_custom.rb +25 -0
- data/test/{test_formats.rb → test_version.rb} +3 -3
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1010733e087d7c58d3c5c0f9ca8ce2a3169b9c32
|
4
|
+
data.tar.gz: 9b4df62cec97cb802826beccfd6949f82f29a626
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c54b6785497270059a504664ebde54b6a978077a8f2cae242bfe59d1ea66d2bfff522c7f54ad12ca107528f061b8fc50643840b638c95db574b66f9a7eaa6494
|
7
|
+
data.tar.gz: b522cd86b0617a63f7c7fea943781601063f1bc6ac1c9be7978f134986962006f37926d38651fc66027ed2b8e6fe84f4ce54e197e27154eae3fdf859fd9dadee
|
data/Manifest.txt
CHANGED
@@ -3,12 +3,13 @@ Manifest.txt
|
|
3
3
|
README.md
|
4
4
|
Rakefile
|
5
5
|
lib/date-formats.rb
|
6
|
-
lib/date-formats/date.rb
|
7
6
|
lib/date-formats/formats.rb
|
7
|
+
lib/date-formats/names.rb
|
8
|
+
lib/date-formats/parser.rb
|
8
9
|
lib/date-formats/reader.rb
|
9
|
-
lib/date-formats/source.rb
|
10
10
|
lib/date-formats/version.rb
|
11
11
|
lib/date/formats.rb
|
12
12
|
test/helper.rb
|
13
|
-
test/
|
14
|
-
test/
|
13
|
+
test/test_parse.rb
|
14
|
+
test/test_parse_custom.rb
|
15
|
+
test/test_version.rb
|
data/lib/date-formats.rb
CHANGED
@@ -12,7 +12,7 @@ require 'logutils'
|
|
12
12
|
# our own code
|
13
13
|
require 'date-formats/version' # let version always go first
|
14
14
|
require 'date-formats/reader'
|
15
|
-
require 'date-formats/
|
15
|
+
require 'date-formats/names' ## month and day names (e.g. January,.. Monday,...)
|
16
16
|
|
17
17
|
|
18
18
|
module DateFormats
|
@@ -37,7 +37,7 @@ end # module DateFormats
|
|
37
37
|
|
38
38
|
|
39
39
|
require 'date-formats/formats'
|
40
|
-
require 'date-formats/
|
40
|
+
require 'date-formats/parser'
|
41
41
|
|
42
42
|
|
43
43
|
|
data/lib/date-formats/formats.rb
CHANGED
File without changes
|
@@ -9,6 +9,7 @@ module DateFormats
|
|
9
9
|
end
|
10
10
|
def self.lang=( value )
|
11
11
|
@@lang = value.to_sym ## note: make sure lang is always a symbol for now (NOT a string)
|
12
|
+
@@lang ## todo/check: remove =() method always returns passed in value? double check
|
12
13
|
end
|
13
14
|
|
14
15
|
|
@@ -21,14 +22,14 @@ module DateFormats
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def self.parse( line,
|
24
|
-
lang: self.class.lang,
|
25
|
+
lang: DateFormats.lang, ## todo/check: is there a "generic" like self.class.lang form? yes, module DateFormats needs to get changed to class DateFormats to work!!
|
25
26
|
start: Date.new( Date.today.year, 1, 1 ) ## note: default to current YYYY.01.01. if no start provided
|
26
27
|
)
|
27
28
|
parser( lang: lang ).parse( line, start: start )
|
28
29
|
end
|
29
30
|
|
30
31
|
def self.find!( line,
|
31
|
-
lang: self.class.lang
|
32
|
+
lang: DateFormats.lang, ## todo/check: is there a "generic" like self.class.lang form?
|
32
33
|
start: Date.new( Date.today.year, 1, 1 ) ## note: default to current YYYY.01.01. if no start provided
|
33
34
|
)
|
34
35
|
parser( lang: lang ).find!( line, start: start )
|
@@ -167,20 +168,20 @@ module DateFormats
|
|
167
168
|
day = h[:day]
|
168
169
|
year = h[:year] || calc_year( month.to_i, day.to_i, start: start ).to_s
|
169
170
|
|
170
|
-
if h[:hours] || h[:minutes] ## check time (hours or minutes) is present (otherwise asume just Date and NOT DateTime)
|
171
|
-
|
172
|
-
|
171
|
+
date = if h[:hours] || h[:minutes] ## check time (hours or minutes) is present (otherwise asume just Date and NOT DateTime)
|
172
|
+
hours = h[:hours] || '00' # default to 00:00 for HH:MM (hours:minutes)
|
173
|
+
minutes = h[:minutes] || '00'
|
173
174
|
|
174
|
-
|
175
|
-
|
175
|
+
value = '%d-%02d-%02d %02d:%02d' % [year.to_i, month.to_i, day.to_i, hours.to_i, minutes.to_i]
|
176
|
+
logger.debug " datetime: >#{value}<"
|
176
177
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
178
|
+
DateTime.strptime( value, '%Y-%m-%d %H:%M' )
|
179
|
+
else
|
180
|
+
value = '%d-%02d-%02d' % [year.to_i, month.to_i, day.to_i]
|
181
|
+
logger.debug " date: >#{value}<"
|
181
182
|
|
182
|
-
|
183
|
-
|
183
|
+
Date.strptime( value, '%Y-%m-%d' )
|
184
|
+
end
|
184
185
|
|
185
186
|
## check/assert cwday if present!!!!
|
186
187
|
date
|
data/lib/date-formats/version.rb
CHANGED
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
###
|
4
4
|
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse.rb
|
6
6
|
|
7
7
|
|
8
8
|
require 'helper'
|
9
9
|
|
10
|
-
class
|
10
|
+
class TestParse < MiniTest::Test
|
11
11
|
|
12
12
|
def test_date
|
13
13
|
data = [
|
@@ -43,17 +43,11 @@ class TestDate < MiniTest::Test
|
|
43
43
|
[ 'Oct/12 2013 16:00', '2013-10-12 16:00', '[EN_MONTH_DD_YYYY_hh_mm]' ],
|
44
44
|
|
45
45
|
[ 'Jan/26 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
|
46
|
-
[ 'Jan/26 2011', '2011-01-26', '[EN_MONTH_DD_YYYY]' ],
|
47
|
-
|
48
|
-
[ 'Jan/26', '2013-01-26', '[EN_MONTH_DD]' ],
|
49
46
|
[ 'Jan/26', '2013-01-26', '[EN_MONTH_DD]' ],
|
50
47
|
[ '26 January', '2013-01-26', '[EN_DD_MONTH]' ],
|
51
|
-
[ '26 January', '2013-01-26', '[EN_DD_MONTH]' ],
|
52
48
|
|
53
|
-
[ 'Jun/13', '2013-06-13', '[EN_MONTH_DD]' ],
|
54
49
|
[ 'Jun/13', '2013-06-13', '[EN_MONTH_DD]' ],
|
55
50
|
[ '13 June', '2013-06-13', '[EN_DD_MONTH]' ],
|
56
|
-
[ '13 June', '2013-06-13', '[EN_DD_MONTH]' ]
|
57
51
|
]
|
58
52
|
|
59
53
|
assert_dates( data, start: Date.new( 2013, 1, 1 ), lang: 'en' )
|
@@ -105,4 +99,4 @@ private
|
|
105
99
|
assert_date( exp, value )
|
106
100
|
assert_time( exp, value )
|
107
101
|
end
|
108
|
-
end # class
|
102
|
+
end # class TestParse
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_parse_custom.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestParseCustom < MiniTest::Test
|
11
|
+
|
12
|
+
def parse( line, start: )
|
13
|
+
@@parser ||= DateFormats::RsssfDateParser.new
|
14
|
+
@@parser.parse( line, start: start )
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_rsssf
|
18
|
+
year = Date.today.year
|
19
|
+
start = Date.new( year, 1, 1 )
|
20
|
+
|
21
|
+
assert_equal Date.new( year, 4, 12 ), parse( '[Apr 12]', start: start )
|
22
|
+
assert_equal Date.new( year, 4, 12 ), parse( '[April 12]', start: start )
|
23
|
+
end
|
24
|
+
|
25
|
+
end # class TestParseCustom
|
@@ -2,12 +2,12 @@
|
|
2
2
|
|
3
3
|
###
|
4
4
|
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/
|
5
|
+
# ruby -I ./lib -I ./test test/test_version.rb
|
6
6
|
|
7
7
|
|
8
8
|
require 'helper'
|
9
9
|
|
10
|
-
class
|
10
|
+
class TestVersion < MiniTest::Test
|
11
11
|
|
12
12
|
def test_version
|
13
13
|
pp DateFormats::VERSION
|
@@ -15,4 +15,4 @@ class TestFormats < MiniTest::Test
|
|
15
15
|
pp DateFormats.root
|
16
16
|
end
|
17
17
|
|
18
|
-
end # class
|
18
|
+
end # class TestVersion
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -67,15 +67,16 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
69
|
- lib/date-formats.rb
|
70
|
-
- lib/date-formats/date.rb
|
71
70
|
- lib/date-formats/formats.rb
|
71
|
+
- lib/date-formats/names.rb
|
72
|
+
- lib/date-formats/parser.rb
|
72
73
|
- lib/date-formats/reader.rb
|
73
|
-
- lib/date-formats/source.rb
|
74
74
|
- lib/date-formats/version.rb
|
75
75
|
- lib/date/formats.rb
|
76
76
|
- test/helper.rb
|
77
|
-
- test/
|
78
|
-
- test/
|
77
|
+
- test/test_parse.rb
|
78
|
+
- test/test_parse_custom.rb
|
79
|
+
- test/test_version.rb
|
79
80
|
homepage: https://github.com/sportdb/sport.db
|
80
81
|
licenses:
|
81
82
|
- Public Domain
|