@fhss-web-team/fuzzy-dates 2.0.0 → 2.1.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.
@@ -21,7 +21,7 @@ function toSimpleDate(dateValue) {
21
21
  if (dateValue.precision === 'Year')
22
22
  return `${sign}${yyyy}`;
23
23
  const mm = String(month).padStart(2, '0');
24
- if (dateValue.precision === 'Month' || dateValue.precision === 'Season')
24
+ if (dateValue.precision === 'Month')
25
25
  return `${sign}${yyyy}-${mm}`;
26
26
  const dd = String(day).padStart(2, '0');
27
27
  return `${sign}${yyyy}-${mm}-${dd}`;
@@ -1,2 +1,2 @@
1
- export const DATE_NEG_INFINITY = new Date(-8640000000000000);
2
- export const DATE_POS_INFINITY = new Date(8640000000000000);
1
+ export const DATE_NEG_INFINITY = new Date(-62135596800000);
2
+ export const DATE_POS_INFINITY = new Date(253402300799999);
@@ -8,5 +8,5 @@ export type FuzzyDateModel = {
8
8
  start: SimpleDate | null;
9
9
  end: SimpleDate | null;
10
10
  };
11
- export type Precision = 'Year' | 'Season' | 'Month' | 'Day' | 'Hour' | 'Minute' | 'Second';
11
+ export type Precision = 'Year' | 'Month' | 'Day' | 'Hour' | 'Minute' | 'Second';
12
12
  export declare function isRange(model: FuzzyDateModel): boolean;
@@ -1,4 +1,3 @@
1
- import { isSeasonMonth, SEASON_MONTH_MAP } from '../parse/simpleDate/maps';
2
1
  import { isRange } from '../helpers/types';
3
2
  export function normalize(model) {
4
3
  const startDate = normalizeSimple(model.start);
@@ -31,12 +30,6 @@ function normalizeSimple(input) {
31
30
  case 'Year':
32
31
  options.year = 'numeric';
33
32
  break;
34
- case 'Season': {
35
- const month = date.getUTCMonth() + 1;
36
- if (!isSeasonMonth(month))
37
- return '';
38
- return `${SEASON_MONTH_MAP[month]} ${date.getUTCFullYear()}`;
39
- }
40
33
  case 'Month':
41
34
  options.month = 'long';
42
35
  options.year = 'numeric';
@@ -22,7 +22,7 @@ export declare function parse(input: string): {
22
22
  readonly min: Date;
23
23
  readonly max: Date;
24
24
  } | {
25
- readonly precision: "Season" | "Month";
25
+ readonly precision: "Month";
26
26
  readonly min: Date;
27
27
  readonly max: Date;
28
28
  } | {
@@ -35,7 +35,7 @@ export declare function parse(input: string): {
35
35
  readonly min: Date;
36
36
  readonly max: Date;
37
37
  } | {
38
- readonly precision: "Season" | "Month";
38
+ readonly precision: "Month";
39
39
  readonly min: Date;
40
40
  readonly max: Date;
41
41
  } | {
@@ -15,7 +15,7 @@ export declare function none(rawInput: string): {
15
15
  readonly min: Date;
16
16
  readonly max: Date;
17
17
  } | {
18
- readonly precision: "Season" | "Month";
18
+ readonly precision: "Month";
19
19
  readonly min: Date;
20
20
  readonly max: Date;
21
21
  } | {
@@ -28,7 +28,7 @@ export declare function none(rawInput: string): {
28
28
  readonly min: Date;
29
29
  readonly max: Date;
30
30
  } | {
31
- readonly precision: "Season" | "Month";
31
+ readonly precision: "Month";
32
32
  readonly min: Date;
33
33
  readonly max: Date;
34
34
  } | {
@@ -56,7 +56,7 @@ export declare function before(rawInput: string): {
56
56
  readonly min: Date;
57
57
  readonly max: Date;
58
58
  } | {
59
- readonly precision: "Season" | "Month";
59
+ readonly precision: "Month";
60
60
  readonly min: Date;
61
61
  readonly max: Date;
62
62
  } | {
@@ -83,7 +83,7 @@ export declare function after(rawInput: string): {
83
83
  readonly min: Date;
84
84
  readonly max: Date;
85
85
  } | {
86
- readonly precision: "Season" | "Month";
86
+ readonly precision: "Month";
87
87
  readonly min: Date;
88
88
  readonly max: Date;
89
89
  } | {
@@ -114,7 +114,7 @@ export declare function between(rawInput: string): {
114
114
  readonly min: Date;
115
115
  readonly max: Date;
116
116
  } | {
117
- readonly precision: "Season" | "Month";
117
+ readonly precision: "Month";
118
118
  readonly min: Date;
119
119
  readonly max: Date;
120
120
  } | {
@@ -127,7 +127,7 @@ export declare function between(rawInput: string): {
127
127
  readonly min: Date;
128
128
  readonly max: Date;
129
129
  } | {
130
- readonly precision: "Season" | "Month";
130
+ readonly precision: "Month";
131
131
  readonly min: Date;
132
132
  readonly max: Date;
133
133
  } | {
@@ -157,7 +157,7 @@ export declare function from(rawInput: string): {
157
157
  readonly min: Date;
158
158
  readonly max: Date;
159
159
  } | {
160
- readonly precision: "Season" | "Month";
160
+ readonly precision: "Month";
161
161
  readonly min: Date;
162
162
  readonly max: Date;
163
163
  } | {
@@ -170,7 +170,7 @@ export declare function from(rawInput: string): {
170
170
  readonly min: Date;
171
171
  readonly max: Date;
172
172
  } | {
173
- readonly precision: "Season" | "Month";
173
+ readonly precision: "Month";
174
174
  readonly min: Date;
175
175
  readonly max: Date;
176
176
  } | {
@@ -27,7 +27,7 @@ export declare const monthStringYear: (rawDate: string) => {
27
27
  } | {
28
28
  ok: true;
29
29
  value: {
30
- readonly precision: "Season" | "Month";
30
+ readonly precision: "Month";
31
31
  readonly min: Date;
32
32
  readonly max: Date;
33
33
  };
@@ -44,7 +44,7 @@ export declare const yearMonthString: (rawDate: string) => {
44
44
  } | {
45
45
  ok: true;
46
46
  value: {
47
- readonly precision: "Season" | "Month";
47
+ readonly precision: "Month";
48
48
  readonly min: Date;
49
49
  readonly max: Date;
50
50
  };
@@ -1,4 +1,3 @@
1
- import { isSeason } from './maps';
2
1
  import { ok } from '../../helpers/result';
3
2
  import { calculateMaxDate, parseDateGroups } from './helpers';
4
3
  const DAY = '(?<day>\\d{1,2})';
@@ -23,7 +22,7 @@ export const year = (rawDate) => {
23
22
  max,
24
23
  });
25
24
  };
26
- // MMM(M) YYYY || SEASON YYYY
25
+ // MMM(M) YYYY
27
26
  export const monthStringYear = (rawDate) => {
28
27
  const pattern = new RegExp(String.raw `^${MONTH_STRING}\s${YEAR}$`);
29
28
  const match = pattern.exec(rawDate);
@@ -33,7 +32,7 @@ export const monthStringYear = (rawDate) => {
33
32
  if (!result.ok)
34
33
  return result;
35
34
  const monthString = match.groups['month'].toLowerCase();
36
- const precision = isSeason(monthString) ? 'Season' : 'Month';
35
+ const precision = 'Month';
37
36
  const min = result.value.date;
38
37
  const max = calculateMaxDate(min, precision);
39
38
  return ok({
@@ -42,7 +41,7 @@ export const monthStringYear = (rawDate) => {
42
41
  max,
43
42
  });
44
43
  };
45
- // YYYY MMM(M) || YYYY SEASON
44
+ // YYYY MMM(M)
46
45
  export const yearMonthString = (rawDate) => {
47
46
  const pattern = new RegExp(String.raw `^${YEAR}\s${MONTH_STRING}$`);
48
47
  const match = pattern.exec(rawDate);
@@ -51,8 +50,7 @@ export const yearMonthString = (rawDate) => {
51
50
  const result = parseDateGroups(match.groups);
52
51
  if (!result.ok)
53
52
  return result;
54
- const monthString = match.groups['month'].toLowerCase();
55
- const precision = isSeason(monthString) ? 'Season' : 'Month';
53
+ const precision = 'Month';
56
54
  const min = result.value.date;
57
55
  const max = calculateMaxDate(min, precision);
58
56
  return ok({
@@ -1,13 +1,10 @@
1
- import { isMonth, isSeason, MONTH_NAME_MAP, MONTH_SEASON_MAP } from './maps';
1
+ import { isMonth, MONTH_NAME_MAP } from './maps';
2
2
  import { err, ok } from '../../helpers/result';
3
3
  export function calculateMaxDate(start, precision) {
4
4
  const endDate = new Date(start);
5
5
  if (precision === 'Year') {
6
6
  endDate.setUTCFullYear(endDate.getUTCFullYear() + 1);
7
7
  }
8
- else if (precision === 'Season') {
9
- endDate.setUTCMonth(endDate.getUTCMonth() + 3);
10
- }
11
8
  else if (precision === 'Month') {
12
9
  endDate.setUTCMonth(endDate.getUTCMonth() + 1);
13
10
  }
@@ -52,7 +49,5 @@ function resolveMonth(rawMonth) {
52
49
  return ok({ monthNumber: Number(monthToken) - 1 }); //months are zero-based
53
50
  if (isMonth(rawMonth))
54
51
  return ok({ monthNumber: MONTH_NAME_MAP[rawMonth] - 1 });
55
- if (isSeason(rawMonth))
56
- return ok({ monthNumber: MONTH_SEASON_MAP[rawMonth] - 1 });
57
52
  return err('Unknown month.');
58
53
  }
@@ -5,22 +5,6 @@ export declare const MONTH_SEASON_MAP: {
5
5
  readonly autumn: 9;
6
6
  readonly winter: 12;
7
7
  };
8
- export declare function isSeason(input: string): input is keyof typeof MONTH_SEASON_MAP;
9
- export declare const SEASON_MONTH_MAP: {
10
- readonly 1: "winter";
11
- readonly 2: "winter";
12
- readonly 3: "spring";
13
- readonly 4: "spring";
14
- readonly 5: "spring";
15
- readonly 6: "summer";
16
- readonly 7: "summer";
17
- readonly 8: "summer";
18
- readonly 9: "fall";
19
- readonly 10: "fall";
20
- readonly 11: "fall";
21
- readonly 12: "winter";
22
- };
23
- export declare function isSeasonMonth(input: number): input is keyof typeof SEASON_MONTH_MAP;
24
8
  export declare const MONTH_NAME_MAP: {
25
9
  readonly jan: 1;
26
10
  readonly january: 1;
@@ -5,26 +5,6 @@ export const MONTH_SEASON_MAP = {
5
5
  autumn: 9,
6
6
  winter: 12,
7
7
  };
8
- export function isSeason(input) {
9
- return Object.keys(MONTH_SEASON_MAP).includes(input);
10
- }
11
- export const SEASON_MONTH_MAP = {
12
- 1: 'winter',
13
- 2: 'winter',
14
- 3: 'spring',
15
- 4: 'spring',
16
- 5: 'spring',
17
- 6: 'summer',
18
- 7: 'summer',
19
- 8: 'summer',
20
- 9: 'fall',
21
- 10: 'fall',
22
- 11: 'fall',
23
- 12: 'winter',
24
- };
25
- export function isSeasonMonth(input) {
26
- return input >= 1 && input <= 12;
27
- }
28
8
  export const MONTH_NAME_MAP = {
29
9
  jan: 1,
30
10
  january: 1,
@@ -17,7 +17,7 @@ export declare function parseSimpleDate(input: string): {
17
17
  } | {
18
18
  ok: true;
19
19
  value: {
20
- readonly precision: "Season" | "Month";
20
+ readonly precision: "Month";
21
21
  readonly min: Date;
22
22
  readonly max: Date;
23
23
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fhss-web-team/fuzzy-dates",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "Parses imprecise date strings into a structured form that can be normalized, indexed, searched, and ordered while preserving the original input.",
5
5
  "homepage": "https://github.com/FHSS-Web-Team/fuzzy-dates#readme",
6
6
  "repository": {