fuzzy-date 0.1.6 → 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fuzzy-date.rb +1 -1
- data/lib/fuzzy-date/analyze.rb +51 -58
- data/lib/fuzzy-date/variables.rb +12 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f1c5f39aa71ab7653b430720262d166b8d42d425
|
4
|
+
data.tar.gz: 5849baad29c3d97756ea288a582e156391a3e646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc59344c1eff14a1a46e10005a224e46bce57074baab089331b9af953cfcfa34e4cdad4f1ee34e60347dc67c4e99d87775a92f864080754076d9bff8e6349f42
|
7
|
+
data.tar.gz: d265085b4dd22b916ab4d954afd9dd93a59f5ab0bb7f52a3c25a25cd5fb7afd854ef089f26cbb6f935c6854a4f36a5025d766c973f23372211ff4a908ec45a8b
|
data/lib/fuzzy-date.rb
CHANGED
data/lib/fuzzy-date/analyze.rb
CHANGED
@@ -6,15 +6,15 @@ class FuzzyDate
|
|
6
6
|
#
|
7
7
|
# Possible incoming date formats:
|
8
8
|
# * YYYY-MM-DD - starts with 3 or 4 digit year, and month and day may be 1 or 2 digits
|
9
|
-
# * YYYY-MM
|
10
|
-
# * YYYY
|
9
|
+
# * YYYY-MM - 3 or 4 digit year, then 1 or 2 digit month
|
10
|
+
# * YYYY - 3 or 4 digit year
|
11
11
|
# * MM-DD-YYYY - 1 or 2 digit month, then 1 or 2 digit day, then 1 to 4 digit year
|
12
12
|
# * DD-MM-YYYY - 1 or 2 digit day, then 1 or 2 digit month, then 1 to 4 digit year if euro is true
|
13
|
-
# * MM-YYYY
|
14
|
-
# * DD-MMM
|
15
|
-
# * DD-MMM-YYYY
|
16
|
-
# * MMM-YYYY
|
17
|
-
# * MMM-DD-YYYY
|
13
|
+
# * MM-YYYY - 1 or 2 digit month, then 1 to 4 digit year
|
14
|
+
# * DD-MMM - 1 or 2 digit day, then month name or abbreviation
|
15
|
+
# * DD-MMM-YYYY - 1 or 2 digit day, then month name or abbreviation, then 1 to 4 digit year
|
16
|
+
# * MMM-YYYY - month name or abbreviation, then 1 to 4 digit year
|
17
|
+
# * MMM-DD-YYYY - month name or abbreviation, then 1 or 2 digit day, then 1 to 4 digit year
|
18
18
|
#
|
19
19
|
# Notes:
|
20
20
|
# - Commas are optional.
|
@@ -33,56 +33,46 @@ class FuzzyDate
|
|
33
33
|
date = massage date
|
34
34
|
@date_parts[ :fixed ] = date
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
year
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
month
|
63
|
-
day
|
64
|
-
year
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
month_text
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
month = @month_names.key( @month_abbreviations[ month_text ] ).to_i.to_s
|
77
|
-
day = $2.to_i.to_s
|
78
|
-
year = $3 ? $3.to_i.to_s : nil
|
79
|
-
|
80
|
-
#- Takes care of MMM-YYYY and MMM
|
81
|
-
elsif date =~ /^(#{ @month_abbreviations.keys.join( '|' ) }).*?(?:-(\d{1,4}))?$/i
|
82
|
-
month_text = $1.to_s.capitalize
|
83
|
-
month = @month_names.key( @month_abbreviations[ month_text ] ).to_i.to_s
|
84
|
-
day = nil
|
85
|
-
year = $2 ? $2.to_i.to_s : nil
|
36
|
+
year, month, day = nil
|
37
|
+
|
38
|
+
if date =~ @date_patterns[ :yyyy ]
|
39
|
+
year = stringify $1
|
40
|
+
|
41
|
+
elsif date =~ @date_patterns[ :yyyy_mm_dd_and_yyyy_mm ]
|
42
|
+
year = stringify $1
|
43
|
+
month = stringify $2 unless $2.nil?
|
44
|
+
day = stringify $3 unless $3.nil?
|
45
|
+
|
46
|
+
elsif date =~ @date_patterns[ :dd_mm_yyyy ] and euro
|
47
|
+
day = stringify $1
|
48
|
+
month = stringify $2
|
49
|
+
year = stringify $3
|
50
|
+
|
51
|
+
elsif date =~ @date_patterns[ :mm_dd_yyyy ]
|
52
|
+
month = stringify $1
|
53
|
+
day = stringify $2
|
54
|
+
year = stringify $3
|
55
|
+
|
56
|
+
elsif date =~ @date_patterns[ :mm_yyyy ]
|
57
|
+
month = stringify $1
|
58
|
+
year = stringify $2
|
59
|
+
|
60
|
+
elsif date =~ @date_patterns[ :dd_mmm_yyyy_and_dd_mmm ]
|
61
|
+
month_text = $2.to_s.capitalize
|
62
|
+
month = stringify @month_names.key( @month_abbreviations[ month_text ] )
|
63
|
+
day = stringify $1
|
64
|
+
year = stringify $3 unless $3.nil?
|
65
|
+
|
66
|
+
elsif date =~ @date_patterns[ :mmm_dd_yyyy ]
|
67
|
+
month_text = $1.to_s.capitalize
|
68
|
+
month = stringify @month_names.key( @month_abbreviations[ month_text ] )
|
69
|
+
day = stringify $2
|
70
|
+
year = stringify $3 unless $3.nil?
|
71
|
+
|
72
|
+
elsif date =~ @date_patterns[ :mmm_yyyy_and_mmm ]
|
73
|
+
month_text = $1.to_s.capitalize
|
74
|
+
month = stringify @month_names.key( @month_abbreviations[ month_text ] )
|
75
|
+
year = stringify $2 unless $2.nil?
|
86
76
|
|
87
77
|
else
|
88
78
|
raise ArgumentError.new( 'Cannot parse date.' )
|
@@ -91,7 +81,6 @@ class FuzzyDate
|
|
91
81
|
@date_parts[ :year ] = year ? year.to_i : nil
|
92
82
|
@date_parts[ :month ] = month ? month.to_i : nil
|
93
83
|
@date_parts[ :day ] = day ? day.to_i : nil
|
94
|
-
#return { :circa => "day: #{ day }, month: #{ month }, year: #{ year }" }
|
95
84
|
|
96
85
|
#- Some error checking at this point
|
97
86
|
if month.to_i > 13
|
@@ -163,4 +152,8 @@ class FuzzyDate
|
|
163
152
|
date_in_parts.join '-'
|
164
153
|
end
|
165
154
|
|
155
|
+
def stringify( capture )
|
156
|
+
capture.to_i.to_s
|
157
|
+
end
|
158
|
+
|
166
159
|
end
|
data/lib/fuzzy-date/variables.rb
CHANGED
@@ -79,6 +79,18 @@ class FuzzyDate
|
|
79
79
|
'CE',
|
80
80
|
'BCE'
|
81
81
|
]
|
82
|
+
|
83
|
+
@date_patterns = {
|
84
|
+
yyyy: /^(\d{1,4})$/,
|
85
|
+
yyyy_mm_dd_and_yyyy_mm: /^(\d{3,4})(?:-(\d{1,2})(?:-(\d{1,2}))?)?$/,
|
86
|
+
dd_mm_yyyy: /^(\d{1,2})-(\d{1,2})-(\d{1,4})$/,
|
87
|
+
mm_dd_yyyy: /^(\d{1,2})-(\d{1,2})-(\d{1,4})$/,
|
88
|
+
mm_yyyy: /^(\d{1,2})-(\d{1,4})?$/,
|
89
|
+
dd_mmm_yyyy_and_dd_mmm: /^(\d{1,2})(?:-(#{ @month_abbreviations.keys.join( '|' ) }).*?(?:-(\d{1,4}))?)?$/i,
|
90
|
+
mmm_dd_yyyy: /^(#{ @month_abbreviations.keys.join( '|' ) }).*?-(\d{1,2})-(\d{1,4})$/i,
|
91
|
+
mmm_yyyy_and_mmm: /^(#{ @month_abbreviations.keys.join( '|' ) }).*?(?:-(\d{1,4}))?$/i
|
92
|
+
}
|
93
|
+
|
82
94
|
end
|
83
95
|
|
84
96
|
def set_up_date_parts
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fuzzy-date
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cole
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-04-
|
11
|
+
date: 2014-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: The fuzzy-date gem provides a way to parse and use incomplete dates,
|
14
14
|
like those found in history or genealogy.
|
@@ -18,13 +18,13 @@ executables: []
|
|
18
18
|
extensions: []
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
|
-
- README.md
|
22
21
|
- LICENSE
|
22
|
+
- README.md
|
23
23
|
- demo.rb
|
24
24
|
- lib/fuzzy-date.rb
|
25
|
+
- lib/fuzzy-date/analyze.rb
|
25
26
|
- lib/fuzzy-date/fuzzy-date.rb
|
26
27
|
- lib/fuzzy-date/variables.rb
|
27
|
-
- lib/fuzzy-date/analyze.rb
|
28
28
|
homepage: https://github.com/davidcole/fuzzy-date
|
29
29
|
licenses:
|
30
30
|
- MIT
|
@@ -35,17 +35,17 @@ require_paths:
|
|
35
35
|
- lib
|
36
36
|
required_ruby_version: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
42
|
requirements:
|
43
|
-
- -
|
43
|
+
- - ">="
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
requirements: []
|
47
47
|
rubyforge_project:
|
48
|
-
rubygems_version: 2.
|
48
|
+
rubygems_version: 2.2.2
|
49
49
|
signing_key:
|
50
50
|
specification_version: 4
|
51
51
|
summary: Provides a way to use partial and incomplete dates.
|