@fhss-web-team/fuzzy-dates 1.0.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.
- package/LICENSE +21 -0
- package/README.md +52 -0
- package/dist/fuzzyDate/collate/collate.d.ts +2 -0
- package/dist/fuzzyDate/collate/collate.js +15 -0
- package/dist/fuzzyDate/fuzzyDate.d.ts +206 -0
- package/dist/fuzzyDate/fuzzyDate.js +220 -0
- package/dist/fuzzyDate/fuzzyDate.spec.d.ts +1 -0
- package/dist/fuzzyDate/fuzzyDate.spec.js +158 -0
- package/dist/fuzzyDate/gedcomX/toGedcomX.d.ts +2 -0
- package/dist/fuzzyDate/gedcomX/toGedcomX.js +31 -0
- package/dist/fuzzyDate/normalize/normalize.d.ts +2 -0
- package/dist/fuzzyDate/normalize/normalize.js +47 -0
- package/dist/fuzzyDate/parse/index.d.ts +187 -0
- package/dist/fuzzyDate/parse/index.js +91 -0
- package/dist/fuzzyDate/parse/inputDateFormats.d.ts +204 -0
- package/dist/fuzzyDate/parse/inputDateFormats.js +225 -0
- package/dist/fuzzyDate/parse/modifiers.d.ts +240 -0
- package/dist/fuzzyDate/parse/modifiers.js +193 -0
- package/dist/fuzzyDate/parse/stringToDate.d.ts +38 -0
- package/dist/fuzzyDate/parse/stringToDate.js +24 -0
- package/dist/fuzzyDate/types.d.ts +79 -0
- package/dist/fuzzyDate/types.js +88 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { calculateMaxDate, parseDateGroups } from '.';
|
|
2
|
+
import { ok, isSeason } from '../types';
|
|
3
|
+
const DAY = '(?<day>\\d{1,2})';
|
|
4
|
+
const MONTH_DIGIT = '(?<month>\\d{1,2})';
|
|
5
|
+
const MONTH_STRING = '(?<month>[a-z]+)';
|
|
6
|
+
const YEAR = '(?<year>\\d{4})';
|
|
7
|
+
const DECADE = '(?<decade>\\d{4}s)';
|
|
8
|
+
// YYYY
|
|
9
|
+
export const year = (rawDate) => {
|
|
10
|
+
const pattern = new RegExp(String.raw `^${YEAR}$`);
|
|
11
|
+
const match = pattern.exec(rawDate);
|
|
12
|
+
if (!match?.groups)
|
|
13
|
+
return null;
|
|
14
|
+
const result = parseDateGroups(match.groups);
|
|
15
|
+
if (!result.ok)
|
|
16
|
+
return result;
|
|
17
|
+
const format = 'YYYY';
|
|
18
|
+
const minDate = result.value.date;
|
|
19
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
20
|
+
return ok({
|
|
21
|
+
format: format,
|
|
22
|
+
minDate: minDate,
|
|
23
|
+
maxDate: maxDate,
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
// MMM(M) YYYY || SEASON YYYY
|
|
27
|
+
export const monthStringYear = (rawDate) => {
|
|
28
|
+
const pattern = new RegExp(String.raw `^${MONTH_STRING}\s${YEAR}$`);
|
|
29
|
+
const match = pattern.exec(rawDate);
|
|
30
|
+
if (!match?.groups)
|
|
31
|
+
return null;
|
|
32
|
+
const result = parseDateGroups(match.groups);
|
|
33
|
+
if (!result.ok)
|
|
34
|
+
return result;
|
|
35
|
+
const monthString = match.groups['month'].toLowerCase();
|
|
36
|
+
const format = isSeason(monthString) ? 'SEASON_YYYY' : 'MMMM_YYYY';
|
|
37
|
+
const minDate = result.value.date;
|
|
38
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
39
|
+
return ok({
|
|
40
|
+
format: format,
|
|
41
|
+
minDate: minDate,
|
|
42
|
+
maxDate: maxDate,
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
// YYYY MMM(M) || YYYY SEASON
|
|
46
|
+
export const yearMonthString = (rawDate) => {
|
|
47
|
+
const pattern = new RegExp(String.raw `^${YEAR}\s${MONTH_STRING}$`);
|
|
48
|
+
const match = pattern.exec(rawDate);
|
|
49
|
+
if (!match?.groups)
|
|
50
|
+
return null;
|
|
51
|
+
const result = parseDateGroups(match.groups);
|
|
52
|
+
if (!result.ok)
|
|
53
|
+
return result;
|
|
54
|
+
const monthString = match.groups['month'].toLowerCase();
|
|
55
|
+
const format = isSeason(monthString) ? 'SEASON_YYYY' : 'MMMM_YYYY';
|
|
56
|
+
const minDate = result.value.date;
|
|
57
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
58
|
+
return ok({
|
|
59
|
+
format: format,
|
|
60
|
+
minDate: minDate,
|
|
61
|
+
maxDate: maxDate,
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
// D(D) MMM(M) YYYY
|
|
65
|
+
export const dayMonthStringYear = (rawDate) => {
|
|
66
|
+
const pattern = new RegExp(String.raw `^${DAY}\s${MONTH_STRING}\s${YEAR}$`);
|
|
67
|
+
const match = pattern.exec(rawDate);
|
|
68
|
+
if (!match?.groups)
|
|
69
|
+
return null;
|
|
70
|
+
const result = parseDateGroups(match.groups);
|
|
71
|
+
if (!result.ok)
|
|
72
|
+
return result;
|
|
73
|
+
const format = 'D_MMMM_YYYY';
|
|
74
|
+
const minDate = result.value.date;
|
|
75
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
76
|
+
return ok({
|
|
77
|
+
format: format,
|
|
78
|
+
minDate: minDate,
|
|
79
|
+
maxDate: maxDate,
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
// MMM(M) D(D) YYYY
|
|
83
|
+
export const monthStringDayYear = (rawDate) => {
|
|
84
|
+
const pattern = new RegExp(String.raw `^${MONTH_STRING}\s${DAY}\s${YEAR}$`);
|
|
85
|
+
const match = pattern.exec(rawDate);
|
|
86
|
+
if (!match?.groups)
|
|
87
|
+
return null;
|
|
88
|
+
const result = parseDateGroups(match.groups);
|
|
89
|
+
if (!result.ok)
|
|
90
|
+
return result;
|
|
91
|
+
const format = 'D_MMMM_YYYY';
|
|
92
|
+
const minDate = result.value.date;
|
|
93
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
94
|
+
return ok({
|
|
95
|
+
format: format,
|
|
96
|
+
minDate: minDate,
|
|
97
|
+
maxDate: maxDate,
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
// YYYY MMM(M) D(D)
|
|
101
|
+
export const yearMonthStringDay = (rawDate) => {
|
|
102
|
+
const pattern = new RegExp(String.raw `^${YEAR}\s${MONTH_STRING}\s${DAY}$`);
|
|
103
|
+
const match = pattern.exec(rawDate);
|
|
104
|
+
if (!match?.groups)
|
|
105
|
+
return null;
|
|
106
|
+
const result = parseDateGroups(match.groups);
|
|
107
|
+
if (!result.ok)
|
|
108
|
+
return result;
|
|
109
|
+
const format = 'D_MMMM_YYYY';
|
|
110
|
+
const minDate = result.value.date;
|
|
111
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
112
|
+
return ok({
|
|
113
|
+
format: format,
|
|
114
|
+
minDate: minDate,
|
|
115
|
+
maxDate: maxDate,
|
|
116
|
+
});
|
|
117
|
+
};
|
|
118
|
+
// YYYY D(D) MMM(M)
|
|
119
|
+
export const yearDayMonthString = (rawDate) => {
|
|
120
|
+
const pattern = new RegExp(String.raw `^${YEAR}\s${DAY}\s${MONTH_STRING}$`);
|
|
121
|
+
const match = pattern.exec(rawDate);
|
|
122
|
+
if (!match?.groups)
|
|
123
|
+
return null;
|
|
124
|
+
const result = parseDateGroups(match.groups);
|
|
125
|
+
if (!result.ok)
|
|
126
|
+
return result;
|
|
127
|
+
const format = 'D_MMMM_YYYY';
|
|
128
|
+
const minDate = result.value.date;
|
|
129
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
130
|
+
return ok({
|
|
131
|
+
format: format,
|
|
132
|
+
minDate: minDate,
|
|
133
|
+
maxDate: maxDate,
|
|
134
|
+
});
|
|
135
|
+
};
|
|
136
|
+
// M(M) YYYY
|
|
137
|
+
export const monthDigitYear = (rawDate) => {
|
|
138
|
+
const pattern = new RegExp(String.raw `^${MONTH_DIGIT}\s${YEAR}$`);
|
|
139
|
+
const match = pattern.exec(rawDate);
|
|
140
|
+
if (!match?.groups)
|
|
141
|
+
return null;
|
|
142
|
+
const result = parseDateGroups(match.groups);
|
|
143
|
+
if (!result.ok)
|
|
144
|
+
return result;
|
|
145
|
+
const format = 'MMMM_YYYY';
|
|
146
|
+
const minDate = result.value.date;
|
|
147
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
148
|
+
return ok({
|
|
149
|
+
format: format,
|
|
150
|
+
minDate: minDate,
|
|
151
|
+
maxDate: maxDate,
|
|
152
|
+
});
|
|
153
|
+
};
|
|
154
|
+
// YYYY M(M)
|
|
155
|
+
export const yearMonthDigit = (rawDate) => {
|
|
156
|
+
const pattern = new RegExp(String.raw `^${YEAR}\s${MONTH_DIGIT}$`);
|
|
157
|
+
const match = pattern.exec(rawDate);
|
|
158
|
+
if (!match?.groups)
|
|
159
|
+
return null;
|
|
160
|
+
const result = parseDateGroups(match.groups);
|
|
161
|
+
if (!result.ok)
|
|
162
|
+
return result;
|
|
163
|
+
const format = 'MMMM_YYYY';
|
|
164
|
+
const minDate = result.value.date;
|
|
165
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
166
|
+
return ok({
|
|
167
|
+
format: format,
|
|
168
|
+
minDate: minDate,
|
|
169
|
+
maxDate: maxDate,
|
|
170
|
+
});
|
|
171
|
+
};
|
|
172
|
+
// D(D) M(M) YYYY
|
|
173
|
+
export const dayMonthDigitYear = (rawDate) => {
|
|
174
|
+
const pattern = new RegExp(String.raw `^${DAY}\s${MONTH_DIGIT}\s${YEAR}$`);
|
|
175
|
+
const match = pattern.exec(rawDate);
|
|
176
|
+
if (!match?.groups)
|
|
177
|
+
return null;
|
|
178
|
+
const result = parseDateGroups(match.groups);
|
|
179
|
+
if (!result.ok)
|
|
180
|
+
return result;
|
|
181
|
+
const format = 'D_MMMM_YYYY';
|
|
182
|
+
const minDate = result.value.date;
|
|
183
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
184
|
+
return ok({
|
|
185
|
+
format: format,
|
|
186
|
+
minDate: minDate,
|
|
187
|
+
maxDate: maxDate,
|
|
188
|
+
});
|
|
189
|
+
};
|
|
190
|
+
// YYYY M(M) D(D)
|
|
191
|
+
export const yearMonthDigitDay = (rawDate) => {
|
|
192
|
+
const pattern = new RegExp(String.raw `^${YEAR}\s${MONTH_DIGIT}\s${DAY}$`);
|
|
193
|
+
const match = pattern.exec(rawDate);
|
|
194
|
+
if (!match?.groups)
|
|
195
|
+
return null;
|
|
196
|
+
const result = parseDateGroups(match.groups);
|
|
197
|
+
if (!result.ok)
|
|
198
|
+
return result;
|
|
199
|
+
const format = 'D_MMMM_YYYY';
|
|
200
|
+
const minDate = result.value.date;
|
|
201
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
202
|
+
return ok({
|
|
203
|
+
format: format,
|
|
204
|
+
minDate: minDate,
|
|
205
|
+
maxDate: maxDate,
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
// YYYYs
|
|
209
|
+
export const decade = (rawDate) => {
|
|
210
|
+
const pattern = new RegExp(String.raw `^${DECADE}$`);
|
|
211
|
+
const match = pattern.exec(rawDate);
|
|
212
|
+
if (!match?.groups)
|
|
213
|
+
return null;
|
|
214
|
+
const result = parseDateGroups(match.groups);
|
|
215
|
+
if (!result.ok)
|
|
216
|
+
return result;
|
|
217
|
+
const format = 'YYYYs';
|
|
218
|
+
const minDate = result.value.date;
|
|
219
|
+
const maxDate = calculateMaxDate(minDate, format);
|
|
220
|
+
return ok({
|
|
221
|
+
format: format,
|
|
222
|
+
minDate: minDate,
|
|
223
|
+
maxDate: maxDate,
|
|
224
|
+
});
|
|
225
|
+
};
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
export declare const none: (cleanedInput: string, rawInput: string) => {
|
|
2
|
+
ok: false;
|
|
3
|
+
error: "Year is required.";
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: "Unknown month.";
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: "Unknown date format.";
|
|
10
|
+
} | {
|
|
11
|
+
ok: true;
|
|
12
|
+
value: {
|
|
13
|
+
readonly original: string;
|
|
14
|
+
readonly modifier: "NONE";
|
|
15
|
+
readonly start: {
|
|
16
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
17
|
+
readonly minDate: Date;
|
|
18
|
+
readonly maxDate: Date;
|
|
19
|
+
};
|
|
20
|
+
readonly end: {
|
|
21
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
22
|
+
readonly minDate: Date;
|
|
23
|
+
readonly maxDate: Date;
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
export declare const before: (cleanedInput: string, rawInput: string) => {
|
|
28
|
+
ok: false;
|
|
29
|
+
error: "Year is required.";
|
|
30
|
+
} | {
|
|
31
|
+
ok: false;
|
|
32
|
+
error: "Unknown month.";
|
|
33
|
+
} | {
|
|
34
|
+
ok: false;
|
|
35
|
+
error: "Unknown date format.";
|
|
36
|
+
} | {
|
|
37
|
+
ok: true;
|
|
38
|
+
value: {
|
|
39
|
+
readonly original: string;
|
|
40
|
+
readonly modifier: "BEFORE";
|
|
41
|
+
readonly start: {
|
|
42
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
43
|
+
readonly minDate: Date;
|
|
44
|
+
readonly maxDate: Date;
|
|
45
|
+
};
|
|
46
|
+
readonly end: {
|
|
47
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
48
|
+
readonly minDate: Date;
|
|
49
|
+
readonly maxDate: Date;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export declare const after: (cleanedInput: string, rawInput: string) => {
|
|
54
|
+
ok: false;
|
|
55
|
+
error: "Year is required.";
|
|
56
|
+
} | {
|
|
57
|
+
ok: false;
|
|
58
|
+
error: "Unknown month.";
|
|
59
|
+
} | {
|
|
60
|
+
ok: false;
|
|
61
|
+
error: "Unknown date format.";
|
|
62
|
+
} | {
|
|
63
|
+
ok: true;
|
|
64
|
+
value: {
|
|
65
|
+
readonly original: string;
|
|
66
|
+
readonly modifier: "AFTER";
|
|
67
|
+
readonly start: {
|
|
68
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
69
|
+
readonly minDate: Date;
|
|
70
|
+
readonly maxDate: Date;
|
|
71
|
+
};
|
|
72
|
+
readonly end: {
|
|
73
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
74
|
+
readonly minDate: Date;
|
|
75
|
+
readonly maxDate: Date;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
export declare const about: (cleanedInput: string, rawInput: string) => {
|
|
80
|
+
ok: false;
|
|
81
|
+
error: "Year is required.";
|
|
82
|
+
} | {
|
|
83
|
+
ok: false;
|
|
84
|
+
error: "Unknown month.";
|
|
85
|
+
} | {
|
|
86
|
+
ok: false;
|
|
87
|
+
error: "Unknown date format.";
|
|
88
|
+
} | {
|
|
89
|
+
ok: true;
|
|
90
|
+
value: {
|
|
91
|
+
readonly original: string;
|
|
92
|
+
readonly modifier: "ABOUT";
|
|
93
|
+
readonly start: {
|
|
94
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
95
|
+
readonly minDate: Date;
|
|
96
|
+
readonly maxDate: Date;
|
|
97
|
+
};
|
|
98
|
+
readonly end: {
|
|
99
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
100
|
+
readonly minDate: Date;
|
|
101
|
+
readonly maxDate: Date;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
export declare const between: (cleanedInput: string, rawInput: string) => {
|
|
106
|
+
ok: false;
|
|
107
|
+
error: "Year is required.";
|
|
108
|
+
} | {
|
|
109
|
+
ok: false;
|
|
110
|
+
error: "Unknown month.";
|
|
111
|
+
} | {
|
|
112
|
+
ok: false;
|
|
113
|
+
error: "Unknown date format.";
|
|
114
|
+
} | {
|
|
115
|
+
ok: false;
|
|
116
|
+
error: "Invalid \"BETWEEN\" modifier.";
|
|
117
|
+
} | {
|
|
118
|
+
ok: true;
|
|
119
|
+
value: {
|
|
120
|
+
readonly original: string;
|
|
121
|
+
readonly modifier: "BETWEEN";
|
|
122
|
+
readonly start: {
|
|
123
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
124
|
+
readonly minDate: Date;
|
|
125
|
+
readonly maxDate: Date;
|
|
126
|
+
};
|
|
127
|
+
readonly end: {
|
|
128
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
129
|
+
readonly minDate: Date;
|
|
130
|
+
readonly maxDate: Date;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export declare const from: (cleanedInput: string, rawInput: string) => {
|
|
135
|
+
ok: false;
|
|
136
|
+
error: "Year is required.";
|
|
137
|
+
} | {
|
|
138
|
+
ok: false;
|
|
139
|
+
error: "Unknown month.";
|
|
140
|
+
} | {
|
|
141
|
+
ok: false;
|
|
142
|
+
error: "Unknown date format.";
|
|
143
|
+
} | {
|
|
144
|
+
ok: false;
|
|
145
|
+
error: "Invalid \"FROM\" modifier.";
|
|
146
|
+
} | {
|
|
147
|
+
ok: true;
|
|
148
|
+
value: {
|
|
149
|
+
readonly original: string;
|
|
150
|
+
readonly modifier: "FROM";
|
|
151
|
+
readonly start: {
|
|
152
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
153
|
+
readonly minDate: Date;
|
|
154
|
+
readonly maxDate: Date;
|
|
155
|
+
};
|
|
156
|
+
readonly end: {
|
|
157
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
158
|
+
readonly minDate: Date;
|
|
159
|
+
readonly maxDate: Date;
|
|
160
|
+
};
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
export declare const early: (cleanedInput: string, rawInput: string) => {
|
|
164
|
+
ok: false;
|
|
165
|
+
error: "Year is required.";
|
|
166
|
+
} | {
|
|
167
|
+
ok: false;
|
|
168
|
+
error: "Unknown month.";
|
|
169
|
+
} | {
|
|
170
|
+
ok: false;
|
|
171
|
+
error: "Unknown date format.";
|
|
172
|
+
} | {
|
|
173
|
+
ok: true;
|
|
174
|
+
value: {
|
|
175
|
+
readonly original: string;
|
|
176
|
+
readonly modifier: "EARLY";
|
|
177
|
+
readonly start: {
|
|
178
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
179
|
+
readonly minDate: Date;
|
|
180
|
+
readonly maxDate: Date;
|
|
181
|
+
};
|
|
182
|
+
readonly end: {
|
|
183
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
184
|
+
readonly minDate: Date;
|
|
185
|
+
readonly maxDate: Date;
|
|
186
|
+
};
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
export declare const mid: (cleanedInput: string, rawInput: string) => {
|
|
190
|
+
ok: false;
|
|
191
|
+
error: "Year is required.";
|
|
192
|
+
} | {
|
|
193
|
+
ok: false;
|
|
194
|
+
error: "Unknown month.";
|
|
195
|
+
} | {
|
|
196
|
+
ok: false;
|
|
197
|
+
error: "Unknown date format.";
|
|
198
|
+
} | {
|
|
199
|
+
ok: true;
|
|
200
|
+
value: {
|
|
201
|
+
readonly original: string;
|
|
202
|
+
readonly modifier: "MID";
|
|
203
|
+
readonly start: {
|
|
204
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
205
|
+
readonly minDate: Date;
|
|
206
|
+
readonly maxDate: Date;
|
|
207
|
+
};
|
|
208
|
+
readonly end: {
|
|
209
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
210
|
+
readonly minDate: Date;
|
|
211
|
+
readonly maxDate: Date;
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
export declare const late: (cleanedInput: string, rawInput: string) => {
|
|
216
|
+
ok: false;
|
|
217
|
+
error: "Year is required.";
|
|
218
|
+
} | {
|
|
219
|
+
ok: false;
|
|
220
|
+
error: "Unknown month.";
|
|
221
|
+
} | {
|
|
222
|
+
ok: false;
|
|
223
|
+
error: "Unknown date format.";
|
|
224
|
+
} | {
|
|
225
|
+
ok: true;
|
|
226
|
+
value: {
|
|
227
|
+
readonly original: string;
|
|
228
|
+
readonly modifier: "LATE";
|
|
229
|
+
readonly start: {
|
|
230
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
231
|
+
readonly minDate: Date;
|
|
232
|
+
readonly maxDate: Date;
|
|
233
|
+
};
|
|
234
|
+
readonly end: {
|
|
235
|
+
readonly format: "YYYYs" | "YYYY" | "SEASON_YYYY" | "MMMM_YYYY" | "D_MMMM_YYYY";
|
|
236
|
+
readonly minDate: Date;
|
|
237
|
+
readonly maxDate: Date;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import { getTimes } from '.';
|
|
2
|
+
import { ok, err, DATE_NEG_INFINITY, DATE_POS_INFINITY } from '../types';
|
|
3
|
+
import { stringToDate } from './stringToDate';
|
|
4
|
+
export const none = (cleanedInput, rawInput) => {
|
|
5
|
+
const result = stringToDate(cleanedInput);
|
|
6
|
+
if (!result.ok)
|
|
7
|
+
return result;
|
|
8
|
+
const date = result.value;
|
|
9
|
+
return ok({
|
|
10
|
+
original: rawInput,
|
|
11
|
+
modifier: 'NONE',
|
|
12
|
+
start: {
|
|
13
|
+
format: date.format,
|
|
14
|
+
minDate: date.minDate,
|
|
15
|
+
maxDate: date.maxDate,
|
|
16
|
+
},
|
|
17
|
+
end: {
|
|
18
|
+
format: date.format,
|
|
19
|
+
minDate: date.minDate,
|
|
20
|
+
maxDate: date.maxDate,
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export const before = (cleanedInput, rawInput) => {
|
|
25
|
+
const result = stringToDate(cleanedInput.slice('before '.length));
|
|
26
|
+
if (!result.ok)
|
|
27
|
+
return result;
|
|
28
|
+
const date = result.value;
|
|
29
|
+
return ok({
|
|
30
|
+
original: rawInput,
|
|
31
|
+
modifier: 'BEFORE',
|
|
32
|
+
start: {
|
|
33
|
+
format: date.format,
|
|
34
|
+
minDate: DATE_NEG_INFINITY,
|
|
35
|
+
maxDate: date.minDate,
|
|
36
|
+
},
|
|
37
|
+
end: {
|
|
38
|
+
format: date.format,
|
|
39
|
+
minDate: date.minDate,
|
|
40
|
+
maxDate: date.maxDate,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
export const after = (cleanedInput, rawInput) => {
|
|
45
|
+
const result = stringToDate(cleanedInput.slice('after '.length));
|
|
46
|
+
if (!result.ok)
|
|
47
|
+
return result;
|
|
48
|
+
const date = result.value;
|
|
49
|
+
return ok({
|
|
50
|
+
original: rawInput,
|
|
51
|
+
modifier: 'AFTER',
|
|
52
|
+
start: {
|
|
53
|
+
format: date.format,
|
|
54
|
+
minDate: date.minDate,
|
|
55
|
+
maxDate: date.maxDate,
|
|
56
|
+
},
|
|
57
|
+
end: {
|
|
58
|
+
format: date.format,
|
|
59
|
+
minDate: date.maxDate,
|
|
60
|
+
maxDate: DATE_POS_INFINITY,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
export const about = (cleanedInput, rawInput) => {
|
|
65
|
+
const result = stringToDate(cleanedInput.slice('about '.length));
|
|
66
|
+
if (!result.ok)
|
|
67
|
+
return result;
|
|
68
|
+
const date = result.value;
|
|
69
|
+
return ok({
|
|
70
|
+
original: rawInput,
|
|
71
|
+
modifier: 'ABOUT',
|
|
72
|
+
start: {
|
|
73
|
+
format: date.format,
|
|
74
|
+
minDate: date.minDate,
|
|
75
|
+
maxDate: date.maxDate,
|
|
76
|
+
},
|
|
77
|
+
end: {
|
|
78
|
+
format: date.format,
|
|
79
|
+
minDate: date.minDate,
|
|
80
|
+
maxDate: date.maxDate,
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
export const between = (cleanedInput, rawInput) => {
|
|
85
|
+
const dates = cleanedInput.slice('between '.length).split(' and ');
|
|
86
|
+
if (dates.length !== 2)
|
|
87
|
+
return err('Invalid "BETWEEN" modifier.');
|
|
88
|
+
const startResult = stringToDate(dates[0]);
|
|
89
|
+
const endDateResult = stringToDate(dates[1]);
|
|
90
|
+
if (!startResult.ok)
|
|
91
|
+
return startResult;
|
|
92
|
+
if (!endDateResult.ok)
|
|
93
|
+
return endDateResult;
|
|
94
|
+
const start = startResult.value;
|
|
95
|
+
const end = endDateResult.value;
|
|
96
|
+
return ok({
|
|
97
|
+
original: rawInput,
|
|
98
|
+
modifier: 'BETWEEN',
|
|
99
|
+
start: {
|
|
100
|
+
format: start.format,
|
|
101
|
+
minDate: start.minDate,
|
|
102
|
+
maxDate: start.maxDate,
|
|
103
|
+
},
|
|
104
|
+
end: { format: end.format, minDate: end.minDate, maxDate: end.maxDate },
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
export const from = (cleanedInput, rawInput) => {
|
|
108
|
+
const dates = cleanedInput.slice('from '.length).split(' to ');
|
|
109
|
+
if (dates.length !== 2)
|
|
110
|
+
return err('Invalid "FROM" modifier.');
|
|
111
|
+
const startResult = stringToDate(dates[0]);
|
|
112
|
+
const endDateResult = stringToDate(dates[1]);
|
|
113
|
+
if (!startResult.ok)
|
|
114
|
+
return startResult;
|
|
115
|
+
if (!endDateResult.ok)
|
|
116
|
+
return endDateResult;
|
|
117
|
+
const start = startResult.value;
|
|
118
|
+
const end = endDateResult.value;
|
|
119
|
+
return ok({
|
|
120
|
+
original: rawInput,
|
|
121
|
+
modifier: 'FROM',
|
|
122
|
+
start: {
|
|
123
|
+
format: start.format,
|
|
124
|
+
minDate: start.minDate,
|
|
125
|
+
maxDate: start.maxDate,
|
|
126
|
+
},
|
|
127
|
+
end: { format: end.format, minDate: end.minDate, maxDate: end.maxDate },
|
|
128
|
+
});
|
|
129
|
+
};
|
|
130
|
+
export const early = (cleanedInput, rawInput) => {
|
|
131
|
+
const result = stringToDate(cleanedInput.slice('early '.length));
|
|
132
|
+
if (!result.ok)
|
|
133
|
+
return result;
|
|
134
|
+
const date = result.value;
|
|
135
|
+
const { start, half } = getTimes(date);
|
|
136
|
+
return ok({
|
|
137
|
+
original: rawInput,
|
|
138
|
+
modifier: 'EARLY',
|
|
139
|
+
start: {
|
|
140
|
+
format: date.format,
|
|
141
|
+
minDate: new Date(start),
|
|
142
|
+
maxDate: new Date(start + half),
|
|
143
|
+
},
|
|
144
|
+
end: {
|
|
145
|
+
format: date.format,
|
|
146
|
+
minDate: new Date(start),
|
|
147
|
+
maxDate: new Date(start + half),
|
|
148
|
+
},
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
export const mid = (cleanedInput, rawInput) => {
|
|
152
|
+
const result = stringToDate(cleanedInput.slice('mid '.length));
|
|
153
|
+
if (!result.ok)
|
|
154
|
+
return result;
|
|
155
|
+
const date = result.value;
|
|
156
|
+
console.log(date);
|
|
157
|
+
const { start, half } = getTimes(date);
|
|
158
|
+
return ok({
|
|
159
|
+
original: rawInput,
|
|
160
|
+
modifier: 'MID',
|
|
161
|
+
start: {
|
|
162
|
+
format: date.format,
|
|
163
|
+
minDate: new Date(start + half / 2),
|
|
164
|
+
maxDate: new Date(start + half),
|
|
165
|
+
},
|
|
166
|
+
end: {
|
|
167
|
+
format: date.format,
|
|
168
|
+
minDate: new Date(start + half / 2),
|
|
169
|
+
maxDate: new Date(start + half),
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
export const late = (cleanedInput, rawInput) => {
|
|
174
|
+
const result = stringToDate(cleanedInput.slice('late '.length));
|
|
175
|
+
if (!result.ok)
|
|
176
|
+
return result;
|
|
177
|
+
const date = result.value;
|
|
178
|
+
const { start, half } = getTimes(date);
|
|
179
|
+
return ok({
|
|
180
|
+
original: rawInput,
|
|
181
|
+
modifier: 'LATE',
|
|
182
|
+
start: {
|
|
183
|
+
format: date.format,
|
|
184
|
+
minDate: new Date(start + half),
|
|
185
|
+
maxDate: date.maxDate,
|
|
186
|
+
},
|
|
187
|
+
end: {
|
|
188
|
+
format: date.format,
|
|
189
|
+
minDate: new Date(start + half),
|
|
190
|
+
maxDate: date.maxDate,
|
|
191
|
+
},
|
|
192
|
+
});
|
|
193
|
+
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare function stringToDate(dateInput: string): {
|
|
2
|
+
ok: false;
|
|
3
|
+
error: "Year is required.";
|
|
4
|
+
} | {
|
|
5
|
+
ok: false;
|
|
6
|
+
error: "Unknown month.";
|
|
7
|
+
} | {
|
|
8
|
+
ok: false;
|
|
9
|
+
error: "Unknown date format.";
|
|
10
|
+
} | {
|
|
11
|
+
ok: true;
|
|
12
|
+
value: {
|
|
13
|
+
readonly format: "YYYY";
|
|
14
|
+
readonly minDate: Date;
|
|
15
|
+
readonly maxDate: Date;
|
|
16
|
+
};
|
|
17
|
+
} | {
|
|
18
|
+
ok: true;
|
|
19
|
+
value: {
|
|
20
|
+
readonly format: "SEASON_YYYY" | "MMMM_YYYY";
|
|
21
|
+
readonly minDate: Date;
|
|
22
|
+
readonly maxDate: Date;
|
|
23
|
+
};
|
|
24
|
+
} | {
|
|
25
|
+
ok: true;
|
|
26
|
+
value: {
|
|
27
|
+
readonly format: "D_MMMM_YYYY";
|
|
28
|
+
readonly minDate: Date;
|
|
29
|
+
readonly maxDate: Date;
|
|
30
|
+
};
|
|
31
|
+
} | {
|
|
32
|
+
ok: true;
|
|
33
|
+
value: {
|
|
34
|
+
readonly format: "YYYYs";
|
|
35
|
+
readonly minDate: Date;
|
|
36
|
+
readonly maxDate: Date;
|
|
37
|
+
};
|
|
38
|
+
};
|