timetwister 0.1.0 → 0.2.0
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 +8 -8
- data/.travis.yml +6 -0
- data/Gemfile +5 -0
- data/README.md +3 -0
- data/lib/timetwister/parser.rb +101 -1
- data/lib/timetwister/version.rb +1 -1
- data/lib/timetwister.rb +49 -13
- data/spec/dates_spec.rb +650 -0
- data/spec/spec_helper.rb +91 -0
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzliZWQ4YjI5MDA3MDZmZGQ2ZTg4MTI0NDhhZWM4M2ZlYTAxYzQzMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MjdhYmMwNWExY2JlM2U1OTE5ZDU3MjRmYTBjNzBmMTM3MmM3NDJiOQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmQ0NzkzMmJlYjA3NGFmZmVkNjJhOTAyNTllZTFhZjBlM2FhMTI5ZmJlN2Iw
|
10
|
+
MjBiZjQ5YzViN2ZmMzM3YWMwNDIzNGI4M2FjY2M1OWU4YTcwYzE1MDQ3YTVm
|
11
|
+
ZTZmNmM4MGQzN2NkM2EzY2NhZDI3ZWQyNTRhOGU0OGRjMWI3NDQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NzY5MjE1NmMyYzAyZWQxOTUyYjVlOTgxNTUxMDRmZjViY2JhMzE2YjYzNGNl
|
14
|
+
NjNiNTBhYzJiZWMyZDEzMzMxZGQ4YWI2Yjk1YmFjNGFkNTgyNjI3Y2NkZjVl
|
15
|
+
ZWExMGE5ZTk1M2FmMzM3YjQ3YmRiYzFmYjVhNjg0NWQ5MmQxNjM=
|
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[](https://travis-ci.org/alexduryee/timetwister)
|
2
|
+
|
1
3
|
# Timetwister
|
2
4
|
|
3
5
|
A Chronic wrapper with improved date format parsing and fewer surprises.
|
@@ -53,4 +55,5 @@ Output explanation:
|
|
53
55
|
- [Alex Duryee](https://github.com/alexduryee/)
|
54
56
|
- [Trevor Thornton](https://github.com/trevorthornton/)
|
55
57
|
- [Matt Miller](https://github.com/thisismattmiller/)
|
58
|
+
- [Kristopher Kelly](https://github.com/emu47)
|
56
59
|
- [Stephen Schor](https://github.com/nodanaonlyzuul/)
|
data/lib/timetwister/parser.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
1
3
|
require 'chronic'
|
2
4
|
|
3
5
|
class Parser
|
4
6
|
|
5
7
|
def self.string_to_dates(str, options)
|
6
|
-
@string = str
|
8
|
+
@string = str.clone
|
7
9
|
@options = options
|
8
10
|
|
9
11
|
@dates = { :original_string => str, :index_dates => [], :date_start => nil, :date_end => nil,
|
@@ -19,7 +21,12 @@ class Parser
|
|
19
21
|
# perform this here, before the string gets purged of certainty indicators
|
20
22
|
@dates[:certainty] = return_certainty(@string)
|
21
23
|
|
24
|
+
# normalize the string into the parser's preferred form
|
22
25
|
@string = clean_string(@string)
|
26
|
+
@string = language_to_english(@string)
|
27
|
+
@string = replace_ordinals(@string)
|
28
|
+
|
29
|
+
# parse!
|
23
30
|
self.match_replace
|
24
31
|
|
25
32
|
# if there are any future dates, return an empty hash
|
@@ -1089,4 +1096,97 @@ class Parser
|
|
1089
1096
|
|
1090
1097
|
return nil
|
1091
1098
|
end
|
1099
|
+
|
1100
|
+
def self.replace_ordinals(str)
|
1101
|
+
|
1102
|
+
work_str = str.clone
|
1103
|
+
|
1104
|
+
ordinals = {
|
1105
|
+
# replace fulltext ordinals with numbers
|
1106
|
+
'first' => '1',
|
1107
|
+
'second' => '2',
|
1108
|
+
'third' => '3',
|
1109
|
+
'fourth' => '4',
|
1110
|
+
'fifth' => '5',
|
1111
|
+
'sixth' => '6',
|
1112
|
+
'seventh' => '7',
|
1113
|
+
'eighth' => '8',
|
1114
|
+
'ninth' => '9',
|
1115
|
+
'tenth' => '10',
|
1116
|
+
'eleventh' => '11',
|
1117
|
+
'twelfth' => '12',
|
1118
|
+
'thirteenth' => '13',
|
1119
|
+
'fourteenth' => '14',
|
1120
|
+
'fifteenth' => '15',
|
1121
|
+
'sixteenth' => '16',
|
1122
|
+
'seventeenth' => '17',
|
1123
|
+
'eighteenth' => '18',
|
1124
|
+
'nineteenth' => '19',
|
1125
|
+
'twentieth' => '20',
|
1126
|
+
'twenty-' => '2',
|
1127
|
+
'thirtieth' => '30',
|
1128
|
+
'thirty-' => '3',
|
1129
|
+
|
1130
|
+
# replace numeric ordinals with plain numbers
|
1131
|
+
'1st' => '1',
|
1132
|
+
'2nd' => '2',
|
1133
|
+
'3rd' => '3',
|
1134
|
+
'3d' => '3',
|
1135
|
+
'4th' => '4',
|
1136
|
+
'5th' => '5',
|
1137
|
+
'6th' => '6',
|
1138
|
+
'7th' => '7',
|
1139
|
+
'8th' => '8',
|
1140
|
+
'9th' => '9',
|
1141
|
+
'0th' => '0'
|
1142
|
+
}
|
1143
|
+
|
1144
|
+
ordinals.each do |key, value|
|
1145
|
+
work_str.gsub!(Regexp.new(key), value)
|
1146
|
+
end
|
1147
|
+
|
1148
|
+
return work_str
|
1149
|
+
end
|
1150
|
+
|
1151
|
+
def self.language_to_english(str)
|
1152
|
+
|
1153
|
+
work_str = str.clone
|
1154
|
+
|
1155
|
+
languages = {
|
1156
|
+
|
1157
|
+
# french
|
1158
|
+
'janvier' => 'January',
|
1159
|
+
'février' => 'February',
|
1160
|
+
'mars' => 'March',
|
1161
|
+
'avril' => 'April',
|
1162
|
+
'mai' => 'May',
|
1163
|
+
'juin' => 'June',
|
1164
|
+
'juillet' => 'July',
|
1165
|
+
'août' => 'August',
|
1166
|
+
'septembre' => 'September',
|
1167
|
+
'octobre' => 'October',
|
1168
|
+
'novembre' => 'November',
|
1169
|
+
'décembre' => 'December',
|
1170
|
+
|
1171
|
+
# spanish
|
1172
|
+
'enero' => 'January',
|
1173
|
+
'febrero' => 'February',
|
1174
|
+
'marzo' => 'March',
|
1175
|
+
'abril' => 'April',
|
1176
|
+
'mayo' => 'May',
|
1177
|
+
'junio' => 'June',
|
1178
|
+
'julio' => 'July',
|
1179
|
+
'agosto' => 'August',
|
1180
|
+
'septiembre' => 'September',
|
1181
|
+
'octubre' => 'October',
|
1182
|
+
'noviembre' => 'November',
|
1183
|
+
'diciembre' => 'December'
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
languages.each do |key, value|
|
1187
|
+
work_str.gsub!(/#{key}/i, value)
|
1188
|
+
end
|
1189
|
+
|
1190
|
+
return work_str
|
1191
|
+
end
|
1092
1192
|
end
|
data/lib/timetwister/version.rb
CHANGED
data/lib/timetwister.rb
CHANGED
@@ -6,23 +6,59 @@ module Timetwister
|
|
6
6
|
def self.parse(str, options={})
|
7
7
|
|
8
8
|
out = []
|
9
|
+
str = rearrange_conjunctions(str)
|
9
10
|
|
10
11
|
str.split(';').each do |semi|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
12
|
+
semi.split(/\sand\s|\s\&\s/i).each do |conj|
|
13
|
+
|
14
|
+
# check for dates of form "Month Day(-Day), Year" before splitting on commas
|
15
|
+
# (removes certainty markers as to not jam the regex)
|
16
|
+
if Parser.replace_ordinals(conj).gsub(/[\?\[\]]/, '').match(/[a-z]*\.?\s[0-9]{1,2}(\s?-[0-9]{1,2})?\,\s[0-9]{4}/i)
|
17
|
+
out << Parser.string_to_dates(conj, options)
|
18
|
+
else
|
19
|
+
conj.split(',').each do |comma|
|
20
|
+
out << Parser.string_to_dates(comma, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
24
25
|
|
25
26
|
return out
|
26
27
|
|
27
28
|
end
|
29
|
+
|
30
|
+
# sometimes years are considered implicit in complex dates
|
31
|
+
# e.g. "1900 January & February"
|
32
|
+
# this rearranges them into complete atomic dates
|
33
|
+
def self.rearrange_conjunctions(str)
|
34
|
+
|
35
|
+
# if we don't have a complete year and month, call it quits
|
36
|
+
if !str.match(/[0-9]{4}/) || !str.match(/[a-z]+/i)
|
37
|
+
return str
|
38
|
+
end
|
39
|
+
|
40
|
+
year = str.match(/[0-9]{4}/)[0]
|
41
|
+
month = str.match(/[a-z]+/i)[0]
|
42
|
+
return_str = ''
|
43
|
+
|
44
|
+
if month.eql?('and')
|
45
|
+
return str
|
46
|
+
end
|
47
|
+
|
48
|
+
str.split(/\sand\s|\s\&\s/).each do |conj|
|
49
|
+
|
50
|
+
if !conj.match(/[0-9]{4}/)
|
51
|
+
conj << ' ' + year
|
52
|
+
end
|
53
|
+
|
54
|
+
if !conj.match(/[a-z]+/i)
|
55
|
+
conj = month + ' ' + conj
|
56
|
+
end
|
57
|
+
|
58
|
+
return_str << ' and ' + conj
|
59
|
+
end
|
60
|
+
|
61
|
+
return return_str.sub(/\sand\s/, '')
|
62
|
+
|
63
|
+
end
|
28
64
|
end
|
data/spec/dates_spec.rb
ADDED
@@ -0,0 +1,650 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'timetwister'
|
5
|
+
|
6
|
+
describe Timetwister do
|
7
|
+
|
8
|
+
it "parses ISO 8601 single dates" do
|
9
|
+
date = Timetwister.parse("1776-07-04")
|
10
|
+
expect(date[0][:date_start]).to eq(date[0][:date_end])
|
11
|
+
expect(date[0][:test_data]).to eq("30")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "parses ISO 8601 date ranges" do
|
15
|
+
date = Timetwister.parse("1776-07-04/1789-03-01")
|
16
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
17
|
+
expect(date[0][:date_end]).to eq("1789-03-01")
|
18
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
19
|
+
expect(date[0][:test_data]).to eq("40")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "parses definite and approximate single years" do
|
23
|
+
date = Timetwister.parse("1776")
|
24
|
+
expect(date[0][:date_start]).to eq("1776")
|
25
|
+
expect(date[0][:date_end]).to eq("1776")
|
26
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
27
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
28
|
+
expect(date[0][:test_data]).to eq("70")
|
29
|
+
|
30
|
+
date = Timetwister.parse("ca. 1776")
|
31
|
+
expect(date[0][:date_start]).to eq("1776")
|
32
|
+
expect(date[0][:date_end]).to eq("1776")
|
33
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
34
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
35
|
+
expect(date[0][:test_data]).to eq("70")
|
36
|
+
|
37
|
+
date = Timetwister.parse("[1776]")
|
38
|
+
expect(date[0][:date_start]).to eq("1776")
|
39
|
+
expect(date[0][:date_end]).to eq("1776")
|
40
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
41
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
42
|
+
expect(date[0][:test_data]).to eq("70")
|
43
|
+
end
|
44
|
+
|
45
|
+
it "parses ranges of full dates" do
|
46
|
+
|
47
|
+
forms = ["July 4 1776 - March 1 1789", "4 July 1776 - 1 March 1789", "1776 July 4 - 1789 March 1", "1776 4 July - 1789 1 March"]
|
48
|
+
forms.each do |f|
|
49
|
+
date = Timetwister.parse(f)
|
50
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
51
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
52
|
+
expect(date[0][:date_end]).to eq("1789-03-01")
|
53
|
+
expect(date[0][:date_end_full]).to eq("1789-03-01")
|
54
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
55
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
56
|
+
expect(date[0][:test_data]).to eq("80")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
it "parses ranges of months+dates" do
|
61
|
+
forms = ["July 1776 - March 1789", "1776 July - 1789 March"]
|
62
|
+
forms.each do |f|
|
63
|
+
date = Timetwister.parse(f)
|
64
|
+
expect(date[0][:date_start]).to eq("1776-07")
|
65
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
66
|
+
expect(date[0][:date_end]).to eq("1789-03")
|
67
|
+
expect(date[0][:date_end_full]).to eq("1789-03-31")
|
68
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
69
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
70
|
+
expect(date[0][:test_data]).to eq("100")
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
it "parses ranges of just years" do
|
75
|
+
date = Timetwister.parse("1776 - 1789")
|
76
|
+
expect(date[0][:date_start]).to eq("1776")
|
77
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
78
|
+
expect(date[0][:date_end]).to eq("1789")
|
79
|
+
expect(date[0][:date_end_full]).to eq("1789-12-31")
|
80
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
81
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
82
|
+
expect(date[0][:test_data]).to eq("120")
|
83
|
+
end
|
84
|
+
|
85
|
+
it "parses ranges of decades" do
|
86
|
+
date = Timetwister.parse("1770's - 1780s")
|
87
|
+
expect(date[0][:date_start]).to eq("1770")
|
88
|
+
expect(date[0][:date_start_full]).to eq("1770-01-01")
|
89
|
+
expect(date[0][:date_end]).to eq("1789")
|
90
|
+
expect(date[0][:date_end_full]).to eq("1789-12-31")
|
91
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
92
|
+
expect(date[0][:index_dates]).to eq([1770, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
93
|
+
expect(date[0][:test_data]).to eq("190")
|
94
|
+
end
|
95
|
+
|
96
|
+
it "parses ranges of a year and a decade" do
|
97
|
+
date = Timetwister.parse("1770's - 1787")
|
98
|
+
expect(date[0][:date_start]).to eq("1770")
|
99
|
+
expect(date[0][:date_start_full]).to eq("1770-01-01")
|
100
|
+
expect(date[0][:date_end]).to eq("1787")
|
101
|
+
expect(date[0][:date_end_full]).to eq("1787-12-31")
|
102
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
103
|
+
expect(date[0][:index_dates]).to eq([1770, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787])
|
104
|
+
expect(date[0][:test_data]).to eq("140")
|
105
|
+
|
106
|
+
date = Timetwister.parse("1776 - 1780's")
|
107
|
+
expect(date[0][:date_start]).to eq("1776")
|
108
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
109
|
+
expect(date[0][:date_end]).to eq("1789")
|
110
|
+
expect(date[0][:date_end_full]).to eq("1789-12-31")
|
111
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
112
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
113
|
+
expect(date[0][:test_data]).to eq("130")
|
114
|
+
end
|
115
|
+
|
116
|
+
it "parses ranges of a year and a two-digit year" do
|
117
|
+
date = Timetwister.parse("1771 - 76")
|
118
|
+
expect(date[0][:date_start]).to eq("1771")
|
119
|
+
expect(date[0][:date_start_full]).to eq("1771-01-01")
|
120
|
+
expect(date[0][:date_end]).to eq("1776")
|
121
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
122
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
123
|
+
expect(date[0][:index_dates]).to eq([1771, 1772, 1773, 1774, 1775, 1776])
|
124
|
+
expect(date[0][:test_data]).to eq("145")
|
125
|
+
end
|
126
|
+
|
127
|
+
it "parses open-ended ranges" do
|
128
|
+
date = Timetwister.parse("1776 - ")
|
129
|
+
expect(date[0][:date_start]).to eq("1776")
|
130
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
131
|
+
expect(date[0][:date_end]).to eq(nil)
|
132
|
+
expect(date[0][:index_dates]).to eq([1776])
|
133
|
+
expect(date[0][:test_data]).to eq("150")
|
134
|
+
|
135
|
+
date = Timetwister.parse(" - 1776")
|
136
|
+
expect(date[0][:date_end]).to eq("1776")
|
137
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
138
|
+
expect(date[0][:date_start]).to eq(nil)
|
139
|
+
expect(date[0][:index_dates]).to eq([1776])
|
140
|
+
expect(date[0][:test_data]).to eq("160")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "parses undated values" do
|
144
|
+
forms = ["n.d.", "undated", "no date"]
|
145
|
+
forms.each do |f|
|
146
|
+
date = Timetwister.parse(f)
|
147
|
+
expect(date[0][:date_start]).to eq(nil)
|
148
|
+
expect(date[0][:date_start_full]).to eq(nil)
|
149
|
+
expect(date[0][:date_end]).to eq(nil)
|
150
|
+
expect(date[0][:date_end_full]).to eq(nil)
|
151
|
+
expect(date[0][:inclusive_range]).to eq(nil)
|
152
|
+
expect(date[0][:index_dates]).to eq([])
|
153
|
+
expect(date[0][:test_data]).to eq(nil)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
it "parses single decades" do
|
158
|
+
date = Timetwister.parse("1770's")
|
159
|
+
expect(date[0][:date_start]).to eq("1770")
|
160
|
+
expect(date[0][:date_start_full]).to eq("1770-01-01")
|
161
|
+
expect(date[0][:date_end]).to eq("1779")
|
162
|
+
expect(date[0][:date_end_full]).to eq("1779-12-31")
|
163
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
164
|
+
expect(date[0][:index_dates]).to eq([1770, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779])
|
165
|
+
expect(date[0][:test_data]).to eq("180")
|
166
|
+
end
|
167
|
+
|
168
|
+
it "parses single full dates" do
|
169
|
+
forms = ["July 4 1776", "4 July 1776", "1776 July 4", "1776 4 July"]
|
170
|
+
forms.each do |f|
|
171
|
+
date = Timetwister.parse(f)
|
172
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
173
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
174
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
175
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
176
|
+
expect(date[0][:index_dates]).to eq([1776])
|
177
|
+
expect(date[0][:test_data]).to eq("200")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
it "parses single month+year" do
|
182
|
+
forms = ["December 1776", "1776 December", "Dec 1776", "1776 Dec"]
|
183
|
+
forms.each do |f|
|
184
|
+
date = Timetwister.parse(f)
|
185
|
+
expect(date[0][:date_start]).to eq("1776-12")
|
186
|
+
expect(date[0][:date_start_full]).to eq("1776-12-01")
|
187
|
+
expect(date[0][:date_end]).to eq("1776-12")
|
188
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
189
|
+
expect(date[0][:index_dates]).to eq([1776])
|
190
|
+
expect(date[0][:test_data]).to eq("220")
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
it "parses month ranges within one year" do
|
195
|
+
forms = ["July-September 1776", "1776 July-September"]
|
196
|
+
forms.each do |f|
|
197
|
+
date = Timetwister.parse(f)
|
198
|
+
expect(date[0][:date_start]).to eq("1776-07")
|
199
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
200
|
+
expect(date[0][:date_end]).to eq("1776-09")
|
201
|
+
expect(date[0][:date_end_full]).to eq("1776-09-30")
|
202
|
+
expect(date[0][:index_dates]).to eq([1776])
|
203
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
204
|
+
expect(date[0][:test_data]).to eq("230")
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
it "parses a day range within a single month+year" do
|
209
|
+
forms = ["4-10 July 1776", "1776 July 4-10", "July 4-10, 1776", "1776 4-10 July"]
|
210
|
+
forms.each do |f|
|
211
|
+
date = Timetwister.parse(f)
|
212
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
213
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
214
|
+
expect(date[0][:date_end]).to eq("1776-07-10")
|
215
|
+
expect(date[0][:date_end_full]).to eq("1776-07-10")
|
216
|
+
expect(date[0][:index_dates]).to eq([1776])
|
217
|
+
expect(date[0][:test_data]).to eq("240")
|
218
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
it "parses decades with early/mid/late qualifiers" do
|
223
|
+
date = Timetwister.parse("early 1770's")
|
224
|
+
expect(date[0][:date_start]).to eq("1770")
|
225
|
+
expect(date[0][:date_start_full]).to eq("1770-01-01")
|
226
|
+
expect(date[0][:date_end]).to eq("1775")
|
227
|
+
expect(date[0][:date_end_full]).to eq("1775-12-31")
|
228
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
229
|
+
expect(date[0][:index_dates]).to eq([1770, 1771, 1772, 1773, 1774, 1775])
|
230
|
+
expect(date[0][:test_data]).to eq("250")
|
231
|
+
|
232
|
+
date = Timetwister.parse("mid 1770's")
|
233
|
+
expect(date[0][:date_start]).to eq("1773")
|
234
|
+
expect(date[0][:date_start_full]).to eq("1773-01-01")
|
235
|
+
expect(date[0][:date_end]).to eq("1778")
|
236
|
+
expect(date[0][:date_end_full]).to eq("1778-12-31")
|
237
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
238
|
+
expect(date[0][:index_dates]).to eq([1773, 1774, 1775, 1776, 1777, 1778])
|
239
|
+
expect(date[0][:test_data]).to eq("250")
|
240
|
+
|
241
|
+
date = Timetwister.parse("late 1770's")
|
242
|
+
expect(date[0][:date_start]).to eq("1775")
|
243
|
+
expect(date[0][:date_start_full]).to eq("1775-01-01")
|
244
|
+
expect(date[0][:date_end]).to eq("1779")
|
245
|
+
expect(date[0][:date_end_full]).to eq("1779-12-31")
|
246
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
247
|
+
expect(date[0][:index_dates]).to eq([1775, 1776, 1777, 1778, 1779])
|
248
|
+
expect(date[0][:test_data]).to eq("250")
|
249
|
+
end
|
250
|
+
|
251
|
+
it "parses ambiguous dates (e.g. 18--)" do
|
252
|
+
date = Timetwister.parse("17--")
|
253
|
+
expect(date[0][:date_start]).to eq("1700")
|
254
|
+
expect(date[0][:date_start_full]).to eq("1700-01-01")
|
255
|
+
expect(date[0][:date_end]).to eq("1799")
|
256
|
+
expect(date[0][:date_end_full]).to eq("1799-12-31")
|
257
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
258
|
+
expect(date[0][:index_dates][0]).to eq(1700)
|
259
|
+
expect(date[0][:index_dates][99]).to eq(1799)
|
260
|
+
expect(date[0][:test_data]).to eq("290")
|
261
|
+
end
|
262
|
+
|
263
|
+
it "parses day/month ranges within a single year" do
|
264
|
+
forms = ["4 May - 10 July 1776", "1776 May 4 - July 10", "May 4 - July 10 1776", "4 May - 10 July 1776"]
|
265
|
+
forms.each do |f|
|
266
|
+
date = Timetwister.parse(f)
|
267
|
+
expect(date[0][:date_start]).to eq("1776-05-04")
|
268
|
+
expect(date[0][:date_start_full]).to eq("1776-05-04")
|
269
|
+
expect(date[0][:date_end]).to eq("1776-07-10")
|
270
|
+
expect(date[0][:date_end_full]).to eq("1776-07-10")
|
271
|
+
expect(date[0][:index_dates]).to eq([1776])
|
272
|
+
expect(date[0][:test_data]).to eq("310")
|
273
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
it "parses full date + year/month date range" do
|
278
|
+
forms = ["4 July 1776 - March 1789", "1776 July 4 - 1789 March"]
|
279
|
+
forms.each do |f|
|
280
|
+
date = Timetwister.parse(f)
|
281
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
282
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
283
|
+
expect(date[0][:date_end]).to eq("1789-03-31")
|
284
|
+
expect(date[0][:date_end_full]).to eq("1789-03-31")
|
285
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
286
|
+
expect(date[0][:test_data]).to eq("330")
|
287
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
288
|
+
end
|
289
|
+
|
290
|
+
forms = ["July 1776 - March 1, 1789", "1776 July - 1789 March 1"]
|
291
|
+
forms.each do |f|
|
292
|
+
date = Timetwister.parse(f)
|
293
|
+
expect(date[0][:date_start]).to eq("1776-07-01")
|
294
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
295
|
+
expect(date[0][:date_end]).to eq("1789-03-01")
|
296
|
+
expect(date[0][:date_end_full]).to eq("1789-03-01")
|
297
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
298
|
+
expect(date[0][:test_data]).to eq("330")
|
299
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
# the normalized dates returned here are a bit funny
|
304
|
+
# we could do with standardizing them
|
305
|
+
it "parses year + month/year range" do
|
306
|
+
forms = ["1776 - March 1789", "1776 - 1789 March"]
|
307
|
+
forms.each do |f|
|
308
|
+
date = Timetwister.parse(f)
|
309
|
+
expect(date[0][:date_start]).to eq("1776-01")
|
310
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
311
|
+
expect(date[0][:date_end]).to eq("1789-03")
|
312
|
+
expect(date[0][:date_end_full]).to eq("1789-03-31")
|
313
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
314
|
+
expect(date[0][:test_data]).to eq("340")
|
315
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
316
|
+
end
|
317
|
+
|
318
|
+
forms = ["1776 July - 1789", "July 1776 - 1789"]
|
319
|
+
forms.each do |f|
|
320
|
+
date = Timetwister.parse(f)
|
321
|
+
expect(date[0][:date_start]).to eq("1776-07")
|
322
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
323
|
+
expect(date[0][:date_end]).to eq("1789-12")
|
324
|
+
expect(date[0][:date_end_full]).to eq("1789-12-31")
|
325
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
326
|
+
expect(date[0][:test_data]).to eq("340")
|
327
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
|
331
|
+
it "parses mm/dd/yyyy dates" do
|
332
|
+
forms = ["7/4/1776", "07/4/1776", "7/04/1776", "07/04/1776"]
|
333
|
+
forms.each do |f|
|
334
|
+
date = Timetwister.parse(f)
|
335
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
336
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
337
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
338
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
339
|
+
expect(date[0][:index_dates]).to eq([1776])
|
340
|
+
expect(date[0][:test_data]).to eq("350")
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
it "parses seasons" do
|
345
|
+
date = Timetwister.parse("Winter 1776")
|
346
|
+
expect(date[0][:date_start]).to eq("1776-01-01")
|
347
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
348
|
+
expect(date[0][:date_end]).to eq("1776-03-20")
|
349
|
+
expect(date[0][:date_end_full]).to eq("1776-03-20")
|
350
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
351
|
+
expect(date[0][:index_dates]).to eq([1776])
|
352
|
+
expect(date[0][:test_data]).to eq("310")
|
353
|
+
|
354
|
+
date = Timetwister.parse("1776 Spring")
|
355
|
+
expect(date[0][:date_start]).to eq("1776-03-20")
|
356
|
+
expect(date[0][:date_start_full]).to eq("1776-03-20")
|
357
|
+
expect(date[0][:date_end]).to eq("1776-06-21")
|
358
|
+
expect(date[0][:date_end_full]).to eq("1776-06-21")
|
359
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
360
|
+
expect(date[0][:index_dates]).to eq([1776])
|
361
|
+
expect(date[0][:test_data]).to eq("310")
|
362
|
+
|
363
|
+
date = Timetwister.parse("1776 Summer")
|
364
|
+
expect(date[0][:date_start]).to eq("1776-06-21")
|
365
|
+
expect(date[0][:date_start_full]).to eq("1776-06-21")
|
366
|
+
expect(date[0][:date_end]).to eq("1776-09-23")
|
367
|
+
expect(date[0][:date_end_full]).to eq("1776-09-23")
|
368
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
369
|
+
expect(date[0][:index_dates]).to eq([1776])
|
370
|
+
expect(date[0][:test_data]).to eq("310")
|
371
|
+
|
372
|
+
date = Timetwister.parse("Fall 1776")
|
373
|
+
expect(date[0][:date_start]).to eq("1776-09-23")
|
374
|
+
expect(date[0][:date_start_full]).to eq("1776-09-23")
|
375
|
+
expect(date[0][:date_end]).to eq("1776-12-22")
|
376
|
+
expect(date[0][:date_end_full]).to eq("1776-12-22")
|
377
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
378
|
+
expect(date[0][:index_dates]).to eq([1776])
|
379
|
+
expect(date[0][:test_data]).to eq("310")
|
380
|
+
end
|
381
|
+
|
382
|
+
it "parses dates with punctuation" do
|
383
|
+
forms = ["July 4 1776?", "July 4 1776 [?]", "July 4? 1776", "?July 4 1776?", "[July] 4 1776?"]
|
384
|
+
forms.each do |f|
|
385
|
+
date = Timetwister.parse(f)
|
386
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
387
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
388
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
389
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
390
|
+
expect(date[0][:index_dates]).to eq([1776])
|
391
|
+
expect(date[0][:test_data]).to eq("200")
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
it "parses circa dates" do
|
396
|
+
multi = ["ca. 1776 - 1777", "1776 - circa 1777", "ca 1776-77", "circa 1776 - 1777"]
|
397
|
+
multi.each do |f|
|
398
|
+
date = Timetwister.parse(f)
|
399
|
+
expect(date[0][:date_start]).to eq('1776')
|
400
|
+
expect(date[0][:date_end]).to eq('1777')
|
401
|
+
expect(date[0][:index_dates]).to eq([1776,1777])
|
402
|
+
end
|
403
|
+
|
404
|
+
single = ["ca. December 1776", "circa 1776 Dec", "ca 1776 December"]
|
405
|
+
single.each do |f|
|
406
|
+
date = Timetwister.parse(f)
|
407
|
+
expect(date[0][:date_start]).to eq('1776-12')
|
408
|
+
expect(date[0][:index_dates]).to eq([1776])
|
409
|
+
end
|
410
|
+
|
411
|
+
multi_months = ["ca. January 1776 - February 1777", "January 1776 - circa February 1777"]
|
412
|
+
multi_months.each do |f|
|
413
|
+
date = Timetwister.parse(f)
|
414
|
+
expect(date[0][:date_start]).to eq('1776-01')
|
415
|
+
expect(date[0][:date_end]).to eq('1777-02')
|
416
|
+
expect(date[0][:index_dates]).to eq([1776,1777])
|
417
|
+
end
|
418
|
+
|
419
|
+
# weird date forms
|
420
|
+
date = Timetwister.parse("ca. 1776-77")
|
421
|
+
expect(date[0][:date_start]).to eq('1776')
|
422
|
+
expect(date[0][:date_end]).to eq('1777')
|
423
|
+
expect(date[0][:index_dates]).to eq([1776,1777])
|
424
|
+
|
425
|
+
date = Timetwister.parse("ca. January - February 1776")
|
426
|
+
expect(date[0][:date_start]).to eq('1776-01')
|
427
|
+
expect(date[0][:date_end]).to eq('1776-02')
|
428
|
+
expect(date[0][:index_dates]).to eq([1776])
|
429
|
+
|
430
|
+
date = Timetwister.parse("ca. early 1770's")
|
431
|
+
expect(date[0][:date_start]).to eq('1770')
|
432
|
+
expect(date[0][:date_end]).to eq('1775')
|
433
|
+
expect(date[0][:index_dates]).to eq([1770,1771,1772,1773,1774,1775])
|
434
|
+
|
435
|
+
date = Timetwister.parse("ca. 01/01/1776")
|
436
|
+
expect(date[0][:date_start]).to eq('1776-01-01')
|
437
|
+
expect(date[0][:index_dates]).to eq([1776])
|
438
|
+
end
|
439
|
+
|
440
|
+
it "parses dates with certainty values" do
|
441
|
+
date = Timetwister.parse("Approximately July 4, 1776")
|
442
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
443
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
444
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
445
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
446
|
+
expect(date[0][:index_dates]).to eq([1776])
|
447
|
+
expect(date[0][:test_data]).to eq("200")
|
448
|
+
expect(date[0][:certainty]).to eq("approximate")
|
449
|
+
|
450
|
+
date = Timetwister.parse("[July 4, 1776]")
|
451
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
452
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
453
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
454
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
455
|
+
expect(date[0][:index_dates]).to eq([1776])
|
456
|
+
expect(date[0][:test_data]).to eq("200")
|
457
|
+
expect(date[0][:certainty]).to eq("inferred")
|
458
|
+
|
459
|
+
date = Timetwister.parse("July 4?, 1776")
|
460
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
461
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
462
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
463
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
464
|
+
expect(date[0][:index_dates]).to eq([1776])
|
465
|
+
expect(date[0][:test_data]).to eq("200")
|
466
|
+
expect(date[0][:certainty]).to eq("questionable")
|
467
|
+
|
468
|
+
date = Timetwister.parse("1771 - 76?")
|
469
|
+
expect(date[0][:date_start]).to eq("1771")
|
470
|
+
expect(date[0][:date_start_full]).to eq("1771-01-01")
|
471
|
+
expect(date[0][:date_end]).to eq("1776")
|
472
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
473
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
474
|
+
expect(date[0][:index_dates]).to eq([1771, 1772, 1773, 1774, 1775, 1776])
|
475
|
+
expect(date[0][:test_data]).to eq("145")
|
476
|
+
expect(date[0][:certainty]).to eq("questionable")
|
477
|
+
end
|
478
|
+
|
479
|
+
it "DOES NOT parse dates without years" do
|
480
|
+
forms = ["July 4", "June - July", "January 12 - July 4"]
|
481
|
+
forms.each do |f|
|
482
|
+
date = Timetwister.parse(f)
|
483
|
+
expect(date[0][:date_start]).to eq(nil)
|
484
|
+
expect(date[0][:date_start_full]).to eq(nil)
|
485
|
+
expect(date[0][:date_end]).to eq(nil)
|
486
|
+
expect(date[0][:date_end_full]).to eq(nil)
|
487
|
+
expect(date[0][:inclusive_range]).to eq(nil)
|
488
|
+
expect(date[0][:index_dates]).to eq([])
|
489
|
+
expect(date[0][:test_data]).to eq(nil)
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
it "DOES NOT parse dates that are obviously junk" do
|
494
|
+
forms = ["July 4 2776", "July 4 776", "July 4 1776 - July 4 7776", "1897-19??"]
|
495
|
+
forms.each do |f|
|
496
|
+
date = Timetwister.parse(f)
|
497
|
+
expect(date[0][:date_start]).to eq(nil)
|
498
|
+
expect(date[0][:date_start_full]).to eq(nil)
|
499
|
+
expect(date[0][:date_end]).to eq(nil)
|
500
|
+
expect(date[0][:date_end_full]).to eq(nil)
|
501
|
+
expect(date[0][:inclusive_range]).to eq(nil)
|
502
|
+
expect(date[0][:index_dates]).to eq([])
|
503
|
+
expect(date[0][:test_data]).to eq(nil)
|
504
|
+
end
|
505
|
+
end
|
506
|
+
|
507
|
+
it "parses lists of years" do
|
508
|
+
date = Timetwister.parse("1776, 1789, 1812")
|
509
|
+
expect(date[0][:date_start]).to eq("1776")
|
510
|
+
expect(date[0][:date_start_full]).to eq("1776-01-01")
|
511
|
+
expect(date[0][:date_end]).to eq("1776")
|
512
|
+
expect(date[0][:date_end_full]).to eq("1776-12-31")
|
513
|
+
expect(date[0][:test_data]).to eq("70")
|
514
|
+
|
515
|
+
expect(date[1][:date_start]).to eq("1789")
|
516
|
+
expect(date[1][:date_start_full]).to eq("1789-01-01")
|
517
|
+
expect(date[1][:date_end]).to eq("1789")
|
518
|
+
expect(date[1][:date_end_full]).to eq("1789-12-31")
|
519
|
+
expect(date[1][:test_data]).to eq("70")
|
520
|
+
|
521
|
+
expect(date[2][:date_start]).to eq("1812")
|
522
|
+
expect(date[2][:date_start_full]).to eq("1812-01-01")
|
523
|
+
expect(date[2][:date_end]).to eq("1812")
|
524
|
+
expect(date[2][:date_end_full]).to eq("1812-12-31")
|
525
|
+
expect(date[2][:test_data]).to eq("70")
|
526
|
+
end
|
527
|
+
|
528
|
+
it "parses lists of mixed date types" do
|
529
|
+
date = Timetwister.parse("July 1776 - August 1789, 1812 - 1820, 1900")
|
530
|
+
expect(date[0][:date_start]).to eq("1776-07")
|
531
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
532
|
+
expect(date[0][:date_end]).to eq("1789-08")
|
533
|
+
expect(date[0][:date_end_full]).to eq("1789-08-31")
|
534
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
535
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
536
|
+
expect(date[0][:test_data]).to eq("100")
|
537
|
+
|
538
|
+
|
539
|
+
expect(date[1][:date_start]).to eq("1812")
|
540
|
+
expect(date[1][:date_start_full]).to eq("1812-01-01")
|
541
|
+
expect(date[1][:date_end]).to eq("1820")
|
542
|
+
expect(date[1][:date_end_full]).to eq("1820-12-31")
|
543
|
+
expect(date[1][:inclusive_range]).to eq(true)
|
544
|
+
expect(date[1][:index_dates]).to eq([1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820])
|
545
|
+
expect(date[1][:test_data]).to eq("120")
|
546
|
+
|
547
|
+
expect(date[2][:date_start]).to eq("1900")
|
548
|
+
expect(date[2][:date_start_full]).to eq("1900-01-01")
|
549
|
+
expect(date[2][:date_end]).to eq("1900")
|
550
|
+
expect(date[2][:date_end_full]).to eq("1900-12-31")
|
551
|
+
expect(date[2][:test_data]).to eq("70")
|
552
|
+
end
|
553
|
+
|
554
|
+
it "parses lists with mixed delimiters" do
|
555
|
+
date = Timetwister.parse("July 1776 - August 1789; 1812 - 1820, 1900 and June 10-11, 1910")
|
556
|
+
expect(date[0][:date_start]).to eq("1776-07")
|
557
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
558
|
+
expect(date[0][:date_end]).to eq("1789-08")
|
559
|
+
expect(date[0][:date_end_full]).to eq("1789-08-31")
|
560
|
+
expect(date[0][:inclusive_range]).to eq(true)
|
561
|
+
expect(date[0][:index_dates]).to eq([1776, 1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789])
|
562
|
+
expect(date[0][:test_data]).to eq("100")
|
563
|
+
|
564
|
+
expect(date[1][:date_start]).to eq("1812")
|
565
|
+
expect(date[1][:date_start_full]).to eq("1812-01-01")
|
566
|
+
expect(date[1][:date_end]).to eq("1820")
|
567
|
+
expect(date[1][:date_end_full]).to eq("1820-12-31")
|
568
|
+
expect(date[1][:inclusive_range]).to eq(true)
|
569
|
+
expect(date[1][:index_dates]).to eq([1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820])
|
570
|
+
expect(date[1][:test_data]).to eq("120")
|
571
|
+
|
572
|
+
expect(date[2][:date_start]).to eq("1900")
|
573
|
+
expect(date[2][:date_start_full]).to eq("1900-01-01")
|
574
|
+
expect(date[2][:date_end]).to eq("1900")
|
575
|
+
expect(date[2][:date_end_full]).to eq("1900-12-31")
|
576
|
+
expect(date[2][:test_data]).to eq("70")
|
577
|
+
|
578
|
+
expect(date[3][:date_start]).to eq("1910-06-10")
|
579
|
+
expect(date[3][:date_start_full]).to eq("1910-06-10")
|
580
|
+
expect(date[3][:date_end]).to eq("1910-06-11")
|
581
|
+
expect(date[3][:date_end_full]).to eq("1910-06-11")
|
582
|
+
expect(date[3][:test_data]).to eq("240")
|
583
|
+
end
|
584
|
+
|
585
|
+
it "parses dates with ordinal numbers" do
|
586
|
+
forms = ["July twenty-first 1776", "July twenty-first, 1776", "July 21st, 1776", "July 21st 1776"]
|
587
|
+
forms.each do |f|
|
588
|
+
date = Timetwister.parse(f)
|
589
|
+
expect(date[0][:date_start]).to eq("1776-07-21")
|
590
|
+
expect(date[0][:date_start_full]).to eq("1776-07-21")
|
591
|
+
expect(date[0][:date_end]).to eq("1776-07-21")
|
592
|
+
expect(date[0][:date_end_full]).to eq("1776-07-21")
|
593
|
+
expect(date[0][:index_dates]).to eq([1776])
|
594
|
+
expect(date[0][:test_data]).to eq("200")
|
595
|
+
end
|
596
|
+
end
|
597
|
+
|
598
|
+
it "parses dates in multiple languages" do
|
599
|
+
forms = ["august 4 1776", "août 4 1776", "agosto 4 1776"]
|
600
|
+
forms.each do |f|
|
601
|
+
date = Timetwister.parse(f)
|
602
|
+
expect(date[0][:date_start]).to eq("1776-08-04")
|
603
|
+
expect(date[0][:date_start_full]).to eq("1776-08-04")
|
604
|
+
expect(date[0][:date_end]).to eq("1776-08-04")
|
605
|
+
expect(date[0][:date_end_full]).to eq("1776-08-04")
|
606
|
+
expect(date[0][:index_dates]).to eq([1776])
|
607
|
+
expect(date[0][:test_data]).to eq("200")
|
608
|
+
end
|
609
|
+
end
|
610
|
+
|
611
|
+
it "parses dates without clean conjunctions" do
|
612
|
+
forms = ["july 4 and 5 1776", "4 & 5 july 1776", "1776 july 4 and 5"]
|
613
|
+
forms.each do |f|
|
614
|
+
date = Timetwister.parse(f)
|
615
|
+
expect(date[0][:date_start]).to eq("1776-07-04")
|
616
|
+
expect(date[0][:date_start_full]).to eq("1776-07-04")
|
617
|
+
expect(date[0][:date_end]).to eq("1776-07-04")
|
618
|
+
expect(date[0][:date_end_full]).to eq("1776-07-04")
|
619
|
+
expect(date[0][:index_dates]).to eq([1776])
|
620
|
+
expect(date[0][:test_data]).to eq("200")
|
621
|
+
|
622
|
+
expect(date[1][:date_start]).to eq("1776-07-05")
|
623
|
+
expect(date[1][:date_start_full]).to eq("1776-07-05")
|
624
|
+
expect(date[1][:date_end]).to eq("1776-07-05")
|
625
|
+
expect(date[1][:date_end_full]).to eq("1776-07-05")
|
626
|
+
expect(date[1][:index_dates]).to eq([1776])
|
627
|
+
expect(date[1][:test_data]).to eq("200")
|
628
|
+
end
|
629
|
+
|
630
|
+
forms = ["july and august 1776", "1776 july and august"]
|
631
|
+
forms.each do |f|
|
632
|
+
date = Timetwister.parse(f)
|
633
|
+
expect(date[0][:date_start]).to eq("1776-07")
|
634
|
+
expect(date[0][:date_start_full]).to eq("1776-07-01")
|
635
|
+
expect(date[0][:date_end]).to eq("1776-07")
|
636
|
+
expect(date[0][:date_end_full]).to eq("1776-07-31")
|
637
|
+
expect(date[0][:index_dates]).to eq([1776])
|
638
|
+
expect(date[0][:test_data]).to eq("220")
|
639
|
+
|
640
|
+
expect(date[1][:date_start]).to eq("1776-08")
|
641
|
+
expect(date[1][:date_start_full]).to eq("1776-08-01")
|
642
|
+
expect(date[1][:date_end]).to eq("1776-08")
|
643
|
+
expect(date[1][:date_end_full]).to eq("1776-08-31")
|
644
|
+
expect(date[1][:index_dates]).to eq([1776])
|
645
|
+
expect(date[1][:test_data]).to eq("220")
|
646
|
+
end
|
647
|
+
|
648
|
+
end
|
649
|
+
|
650
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# The settings below are suggested to provide a good initial experience
|
44
|
+
# with RSpec, but feel free to customize to your heart's content.
|
45
|
+
=begin
|
46
|
+
# These two settings work together to allow you to limit a spec run
|
47
|
+
# to individual examples or groups you care about by tagging them with
|
48
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
49
|
+
# get run.
|
50
|
+
config.filter_run :focus
|
51
|
+
config.run_all_when_everything_filtered = true
|
52
|
+
|
53
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
54
|
+
# recommended. For more details, see:
|
55
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
56
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
57
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
58
|
+
config.disable_monkey_patching!
|
59
|
+
|
60
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
61
|
+
# be too noisy due to issues in dependencies.
|
62
|
+
config.warnings = true
|
63
|
+
|
64
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
65
|
+
# file, and it's useful to allow more verbose output when running an
|
66
|
+
# individual spec file.
|
67
|
+
if config.files_to_run.one?
|
68
|
+
# Use the documentation formatter for detailed output,
|
69
|
+
# unless a formatter has already been configured
|
70
|
+
# (e.g. via a command-line flag).
|
71
|
+
config.default_formatter = 'doc'
|
72
|
+
end
|
73
|
+
|
74
|
+
# Print the 10 slowest examples and example groups at the
|
75
|
+
# end of the spec run, to help surface which specs are running
|
76
|
+
# particularly slow.
|
77
|
+
config.profile_examples = 10
|
78
|
+
|
79
|
+
# Run specs in random order to surface order dependencies. If you find an
|
80
|
+
# order dependency and want to debug it, you can fix the order by providing
|
81
|
+
# the seed, which is printed after each run.
|
82
|
+
# --seed 1234
|
83
|
+
config.order = :random
|
84
|
+
|
85
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
86
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
87
|
+
# test failures related to randomization by passing the same `--seed` value
|
88
|
+
# as the one that triggered the failure.
|
89
|
+
Kernel.srand config.seed
|
90
|
+
=end
|
91
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: timetwister
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Duryee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-12-
|
11
|
+
date: 2015-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -60,6 +60,7 @@ extensions: []
|
|
60
60
|
extra_rdoc_files: []
|
61
61
|
files:
|
62
62
|
- .gitignore
|
63
|
+
- .travis.yml
|
63
64
|
- Gemfile
|
64
65
|
- LICENSE.txt
|
65
66
|
- README.md
|
@@ -67,6 +68,8 @@ files:
|
|
67
68
|
- lib/timetwister.rb
|
68
69
|
- lib/timetwister/parser.rb
|
69
70
|
- lib/timetwister/version.rb
|
71
|
+
- spec/dates_spec.rb
|
72
|
+
- spec/spec_helper.rb
|
70
73
|
- timetwister.gemspec
|
71
74
|
homepage: http://github.com/alexduryee/timetwister
|
72
75
|
licenses:
|
@@ -92,4 +95,6 @@ rubygems_version: 2.4.5
|
|
92
95
|
signing_key:
|
93
96
|
specification_version: 4
|
94
97
|
summary: Chronic wrapper to handle common date formats
|
95
|
-
test_files:
|
98
|
+
test_files:
|
99
|
+
- spec/dates_spec.rb
|
100
|
+
- spec/spec_helper.rb
|