chrono-node 2.3.9 → 2.4.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.
- package/dist/chrono.js.map +1 -1
- package/dist/common/calculation/weekdays.d.ts +7 -0
- package/dist/common/calculation/weekdays.js +68 -0
- package/dist/common/calculation/weekdays.js.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/locales/de/parsers/DEWeekdayParser.js +2 -8
- package/dist/locales/de/parsers/DEWeekdayParser.js.map +1 -1
- package/dist/locales/en/constants.d.ts +2 -1
- package/dist/locales/en/constants.js.map +1 -1
- package/dist/locales/en/parsers/ENWeekdayParser.js +3 -9
- package/dist/locales/en/parsers/ENWeekdayParser.js.map +1 -1
- package/dist/locales/fr/parsers/FRWeekdayParser.js +4 -10
- package/dist/locales/fr/parsers/FRWeekdayParser.js.map +1 -1
- package/dist/locales/nl/parsers/NLWeekdayParser.js +3 -9
- package/dist/locales/nl/parsers/NLWeekdayParser.js.map +1 -1
- package/dist/locales/pt/parsers/PTWeekdayParser.js +4 -10
- package/dist/locales/pt/parsers/PTWeekdayParser.js.map +1 -1
- package/dist/locales/ru/constants.js +4 -5
- package/dist/locales/ru/constants.js.map +1 -1
- package/dist/locales/ru/parsers/RUWeekdayParser.js +3 -9
- package/dist/locales/ru/parsers/RUWeekdayParser.js.map +1 -1
- package/dist/locales/ru/refiners/RUMergeDateRangeRefiner.d.ts +1 -1
- package/dist/locales/ru/refiners/RUMergeDateRangeRefiner.js +2 -2
- package/dist/locales/ru/refiners/RUMergeDateRangeRefiner.js.map +1 -1
- package/dist/results.d.ts +2 -1
- package/dist/results.js +14 -10
- package/dist/results.js.map +1 -1
- package/package.json +1 -1
- package/src/chrono.ts +3 -1
- package/src/common/calculation/weekdays.ts +89 -0
- package/src/index.ts +10 -0
- package/src/locales/de/parsers/DEWeekdayParser.ts +2 -8
- package/src/locales/en/constants.ts +2 -1
- package/src/locales/en/parsers/ENWeekdayParser.ts +3 -9
- package/src/locales/fr/parsers/FRWeekdayParser.ts +4 -10
- package/src/locales/nl/parsers/NLWeekdayParser.ts +3 -9
- package/src/locales/pt/parsers/PTWeekdayParser.ts +4 -10
- package/src/locales/ru/constants.ts +4 -6
- package/src/locales/ru/parsers/RUWeekdayParser.ts +3 -9
- package/src/locales/ru/refiners/RUMergeDateRangeRefiner.ts +1 -1
- package/src/results.ts +27 -15
- package/test/calculation.test.ts +116 -0
- package/test/en/en.test.ts +10 -0
- package/test/en/en_weekday.test.ts +116 -1
- package/src/calculation/weeks.ts +0 -38
package/dist/results.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"results.js","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":";;;;;;AAEA,+EAAuD;AACvD,kDAAyC;AACzC,yCAAuF;AACvF,yCAA8C;AAC9C,eAAK,CAAC,MAAM,CAAC,uBAAa,CAAC,CAAC;AAE5B,MAAa,qBAAqB;IAI9B,YAAY,KAA+B;;QACvC,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,IAAI,IAAI,EAAE,CAAC;QAC5B,IAAI,KAAK,YAAY,IAAI,EAAE;YACvB,IAAI,CAAC,OAAO,GAAG,KAAK,CAAC;SACxB;aAAM;YACH,IAAI,CAAC,OAAO,GAAG,MAAA,KAAK,CAAC,OAAO,mCAAI,IAAI,IAAI,EAAE,CAAC;YAC3C,IAAI,CAAC,cAAc,GAAG,2BAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;SAC1D;IACL,CAAC;CACJ;
|
|
1
|
+
{"version":3,"file":"results.js","sourceRoot":"","sources":["../src/results.ts"],"names":[],"mappings":";;;;;;AAEA,+EAAuD;AACvD,kDAAyC;AACzC,yCAAuF;AACvF,yCAA8C;AAC9C,eAAK,CAAC,MAAM,CAAC,uBAAa,CAAC,CAAC;AAE5B,MAAa,qBAAqB;IAI9B,YAAY,KAA+B;;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,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QAChD,OAAO,MAAM,CAAC;IAClB,CAAC;IAED,IAAI;QACA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,CAAC;IAED,QAAQ;QACJ,OAAO,0BAA0B,IAAI,CAAC,KAAK,YAAY,IAAI,CAAC,IAAI,UAAU,CAAC;IAC/E,CAAC;CACJ;AAvCD,sCAuCC"}
|
package/package.json
CHANGED
package/src/chrono.ts
CHANGED
|
@@ -140,7 +140,9 @@ export class ParsingContext implements DebugHandler {
|
|
|
140
140
|
readonly option: ParsingOption;
|
|
141
141
|
readonly reference: ReferenceWithTimezone;
|
|
142
142
|
|
|
143
|
-
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated. Use reference.instant instead.
|
|
145
|
+
*/
|
|
144
146
|
readonly refDate: Date;
|
|
145
147
|
|
|
146
148
|
constructor(text: string, refDate?: ParsingReference | Date, option?: ParsingOption) {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { Weekday } from "../../index";
|
|
2
|
+
import { ParsingComponents, ReferenceWithTimezone } from "../../results";
|
|
3
|
+
import { addImpliedTimeUnits } from "../../utils/timeunits";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Returns the parsing components at the weekday (considering the modifier). The time and timezone is assume to be
|
|
7
|
+
* similar to the reference.
|
|
8
|
+
* @param reference
|
|
9
|
+
* @param weekday
|
|
10
|
+
* @param modifier "this", "next", "last" modifier word. If empty, returns the weekday closest to the `refDate`.
|
|
11
|
+
*/
|
|
12
|
+
export function createParsingComponentsAtWeekday(
|
|
13
|
+
reference: ReferenceWithTimezone,
|
|
14
|
+
weekday: Weekday,
|
|
15
|
+
modifier?: "this" | "next" | "last"
|
|
16
|
+
): ParsingComponents {
|
|
17
|
+
const refDate = reference.getDateWithAdjustedTimezone();
|
|
18
|
+
const daysToWeekday = getDaysToWeekday(refDate, weekday, modifier);
|
|
19
|
+
|
|
20
|
+
let components = new ParsingComponents(reference);
|
|
21
|
+
components = addImpliedTimeUnits(components, { "day": daysToWeekday });
|
|
22
|
+
components.assign("weekday", weekday);
|
|
23
|
+
|
|
24
|
+
return components;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns number of days from refDate to the weekday. The refDate date and timezone information is used.
|
|
29
|
+
* @param refDate
|
|
30
|
+
* @param weekday
|
|
31
|
+
* @param modifier "this", "next", "last" modifier word. If empty, returns the weekday closest to the `refDate`.
|
|
32
|
+
*/
|
|
33
|
+
export function getDaysToWeekday(refDate: Date, weekday: Weekday, modifier?: "this" | "next" | "last"): number {
|
|
34
|
+
const refWeekday = refDate.getDay() as Weekday;
|
|
35
|
+
switch (modifier) {
|
|
36
|
+
case "this":
|
|
37
|
+
return getDaysForwardToWeekday(refDate, weekday);
|
|
38
|
+
case "last":
|
|
39
|
+
return getBackwardDaysToWeekday(refDate, weekday);
|
|
40
|
+
case "next":
|
|
41
|
+
// From Sunday, the next Sunday is 7 days later.
|
|
42
|
+
// Otherwise, next Mon is 1 days later, next Tues is 2 days later, and so on..., (return enum value)
|
|
43
|
+
if (refWeekday == Weekday.SUNDAY) {
|
|
44
|
+
return weekday == Weekday.SUNDAY ? 7 : weekday;
|
|
45
|
+
}
|
|
46
|
+
// From Saturday, the next Saturday is 7 days later, the next Sunday is 8-days later.
|
|
47
|
+
// Otherwise, next Mon is (1 + 1) days later, next Tues is (1 + 2) days later, and so on...,
|
|
48
|
+
// (return, 2 + [enum value] days)
|
|
49
|
+
if (refWeekday == Weekday.SATURDAY) {
|
|
50
|
+
if (weekday == Weekday.SATURDAY) return 7;
|
|
51
|
+
if (weekday == Weekday.SUNDAY) return 8;
|
|
52
|
+
return 1 + weekday;
|
|
53
|
+
}
|
|
54
|
+
// From weekdays, next Mon is the following week's Mon, next Tues the following week's Tues, and so on...
|
|
55
|
+
// If the week's weekday already passed (weekday < refWeekday), we simply count forward to next week
|
|
56
|
+
// (similar to 'this'). Otherwise, count forward to this week, then add another 7 days.
|
|
57
|
+
if (weekday < refWeekday && weekday != Weekday.SUNDAY) {
|
|
58
|
+
return getDaysForwardToWeekday(refDate, weekday);
|
|
59
|
+
} else {
|
|
60
|
+
return getDaysForwardToWeekday(refDate, weekday) + 7;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return getDaysToWeekdayClosest(refDate, weekday);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function getDaysToWeekdayClosest(refDate: Date, weekday: Weekday): number {
|
|
67
|
+
const backward = getBackwardDaysToWeekday(refDate, weekday);
|
|
68
|
+
const forward = getDaysForwardToWeekday(refDate, weekday);
|
|
69
|
+
|
|
70
|
+
return forward < -backward ? forward : backward;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function getDaysForwardToWeekday(refDate: Date, weekday: Weekday): number {
|
|
74
|
+
const refWeekday = refDate.getDay();
|
|
75
|
+
let forwardCount = weekday - refWeekday;
|
|
76
|
+
if (forwardCount < 0) {
|
|
77
|
+
forwardCount += 7;
|
|
78
|
+
}
|
|
79
|
+
return forwardCount;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getBackwardDaysToWeekday(refDate: Date, weekday: Weekday): number {
|
|
83
|
+
const refWeekday = refDate.getDay();
|
|
84
|
+
let backwardCount = weekday - refWeekday;
|
|
85
|
+
if (backwardCount >= 0) {
|
|
86
|
+
backwardCount -= 7;
|
|
87
|
+
}
|
|
88
|
+
return backwardCount;
|
|
89
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -99,6 +99,16 @@ export enum Meridiem {
|
|
|
99
99
|
PM = 1,
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
export enum Weekday {
|
|
103
|
+
SUNDAY = 0,
|
|
104
|
+
MONDAY = 1,
|
|
105
|
+
TUESDAY = 2,
|
|
106
|
+
WEDNESDAY = 3,
|
|
107
|
+
THURSDAY = 4,
|
|
108
|
+
FRIDAY = 5,
|
|
109
|
+
SATURDAY = 6,
|
|
110
|
+
}
|
|
111
|
+
|
|
102
112
|
// Export all locales
|
|
103
113
|
import * as de from "./locales/de";
|
|
104
114
|
import * as fr from "./locales/fr";
|
|
@@ -3,7 +3,7 @@ import { ParsingComponents } from "../../../results";
|
|
|
3
3
|
import { WEEKDAY_DICTIONARY } from "../constants";
|
|
4
4
|
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
5
|
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
7
|
|
|
8
8
|
const PATTERN = new RegExp(
|
|
9
9
|
"(?:(?:\\,|\\(|\\()\\s*)?" +
|
|
@@ -44,12 +44,6 @@ export default class DEWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
44
44
|
modifier = "this";
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
|
|
48
|
-
return context
|
|
49
|
-
.createParsingComponents()
|
|
50
|
-
.assign("weekday", offset)
|
|
51
|
-
.imply("day", date.date())
|
|
52
|
-
.imply("month", date.month() + 1)
|
|
53
|
-
.imply("year", date.year());
|
|
47
|
+
return createParsingComponentsAtWeekday(context.reference, offset, modifier);
|
|
54
48
|
}
|
|
55
49
|
}
|
|
@@ -2,8 +2,9 @@ import { OpUnitType, QUnitType } from "dayjs";
|
|
|
2
2
|
import { matchAnyPattern, repeatedTimeunitPattern } from "../../utils/pattern";
|
|
3
3
|
import { findMostLikelyADYear } from "../../calculation/years";
|
|
4
4
|
import { TimeUnits } from "../../utils/timeunits";
|
|
5
|
+
import { Weekday } from "../../index";
|
|
5
6
|
|
|
6
|
-
export const WEEKDAY_DICTIONARY: { [word: string]:
|
|
7
|
+
export const WEEKDAY_DICTIONARY: { [word: string]: Weekday } = {
|
|
7
8
|
sunday: 0,
|
|
8
9
|
sun: 0,
|
|
9
10
|
"sun.": 0,
|
|
@@ -3,7 +3,7 @@ import { ParsingComponents } from "../../../results";
|
|
|
3
3
|
import { WEEKDAY_DICTIONARY } from "../constants";
|
|
4
4
|
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
5
|
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
7
|
|
|
8
8
|
const PATTERN = new RegExp(
|
|
9
9
|
"(?:(?:\\,|\\(|\\()\\s*)?" +
|
|
@@ -27,7 +27,7 @@ export default class ENWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
27
27
|
|
|
28
28
|
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
29
29
|
const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
|
30
|
-
const
|
|
30
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
31
31
|
const prefix = match[PREFIX_GROUP];
|
|
32
32
|
const postfix = match[POSTFIX_GROUP];
|
|
33
33
|
let modifierWord = prefix || postfix;
|
|
@@ -43,12 +43,6 @@ export default class ENWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
43
43
|
modifier = "this";
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
return context
|
|
48
|
-
.createParsingComponents()
|
|
49
|
-
.assign("weekday", offset)
|
|
50
|
-
.imply("day", date.date())
|
|
51
|
-
.imply("month", date.month() + 1)
|
|
52
|
-
.imply("year", date.year());
|
|
46
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
53
47
|
}
|
|
54
48
|
}
|
|
@@ -3,7 +3,7 @@ import { ParsingComponents } from "../../../results";
|
|
|
3
3
|
import { WEEKDAY_DICTIONARY } from "../constants";
|
|
4
4
|
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
5
|
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
7
|
|
|
8
8
|
const PATTERN = new RegExp(
|
|
9
9
|
"(?:(?:\\,|\\(|\\()\\s*)?" +
|
|
@@ -25,8 +25,8 @@ export default class FRWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
25
25
|
|
|
26
26
|
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
27
27
|
const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
28
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
29
|
+
if (weekday === undefined) {
|
|
30
30
|
return null;
|
|
31
31
|
}
|
|
32
32
|
|
|
@@ -41,12 +41,6 @@ export default class FRWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
41
41
|
modifier = "next";
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
return context
|
|
46
|
-
.createParsingComponents()
|
|
47
|
-
.assign("weekday", offset)
|
|
48
|
-
.imply("day", date.date())
|
|
49
|
-
.imply("month", date.month() + 1)
|
|
50
|
-
.imply("year", date.year());
|
|
44
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
@@ -3,7 +3,7 @@ import { ParsingComponents } from "../../../results";
|
|
|
3
3
|
import { WEEKDAY_DICTIONARY } from "../../nl/constants";
|
|
4
4
|
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
5
|
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
7
|
|
|
8
8
|
const PATTERN = new RegExp(
|
|
9
9
|
"(?:(?:\\,|\\(|\\()\\s*)?" +
|
|
@@ -25,7 +25,7 @@ export default class NLWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
25
25
|
|
|
26
26
|
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
27
27
|
const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
|
28
|
-
const
|
|
28
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
29
29
|
const prefix = match[PREFIX_GROUP];
|
|
30
30
|
const postfix = match[POSTFIX_GROUP];
|
|
31
31
|
let modifierWord = prefix || postfix;
|
|
@@ -41,12 +41,6 @@ export default class NLWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
41
41
|
modifier = "this";
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
return context
|
|
46
|
-
.createParsingComponents()
|
|
47
|
-
.assign("weekday", offset)
|
|
48
|
-
.imply("day", date.date())
|
|
49
|
-
.imply("month", date.month() + 1)
|
|
50
|
-
.imply("year", date.year());
|
|
44
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
51
45
|
}
|
|
52
46
|
}
|
|
@@ -3,7 +3,7 @@ import { ParsingComponents } from "../../../results";
|
|
|
3
3
|
import { WEEKDAY_DICTIONARY } from "../constants";
|
|
4
4
|
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
5
|
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
7
|
|
|
8
8
|
const PATTERN = new RegExp(
|
|
9
9
|
"(?:(?:\\,|\\(|\\()\\s*)?" +
|
|
@@ -26,8 +26,8 @@ export default class PTWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
26
26
|
|
|
27
27
|
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
28
28
|
const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
|
29
|
-
const
|
|
30
|
-
if (
|
|
29
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
30
|
+
if (weekday === undefined) {
|
|
31
31
|
return null;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -45,12 +45,6 @@ export default class PTWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
45
45
|
modifier = "this";
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
return context
|
|
50
|
-
.createParsingComponents()
|
|
51
|
-
.assign("weekday", offset)
|
|
52
|
-
.imply("day", date.date())
|
|
53
|
-
.imply("month", date.month() + 1)
|
|
54
|
-
.imply("year", date.year());
|
|
48
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
55
49
|
}
|
|
56
50
|
}
|
|
@@ -47,9 +47,9 @@ export const FULL_MONTH_NAME_DICTIONARY: { [word: string]: number } = {
|
|
|
47
47
|
январь: 1,
|
|
48
48
|
января: 1,
|
|
49
49
|
январе: 1,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
февраль: 2,
|
|
51
|
+
февраля: 2,
|
|
52
|
+
феврале: 2,
|
|
53
53
|
март: 3,
|
|
54
54
|
марта: 3,
|
|
55
55
|
марте: 3,
|
|
@@ -125,7 +125,7 @@ export const INTEGER_WORD_DICTIONARY: { [word: string]: number } = {
|
|
|
125
125
|
семь: 7,
|
|
126
126
|
семи: 7,
|
|
127
127
|
восемь: 8,
|
|
128
|
-
|
|
128
|
+
восьми: 8,
|
|
129
129
|
девять: 9,
|
|
130
130
|
девяти: 9,
|
|
131
131
|
десять: 10,
|
|
@@ -288,8 +288,6 @@ export function parseOrdinalNumberPattern(match: string): number {
|
|
|
288
288
|
if (ORDINAL_WORD_DICTIONARY[num] !== undefined) {
|
|
289
289
|
return ORDINAL_WORD_DICTIONARY[num];
|
|
290
290
|
}
|
|
291
|
-
|
|
292
|
-
num = num.replace(/(?:st|nd|rd|th)$/i, "");
|
|
293
291
|
return parseInt(num);
|
|
294
292
|
}
|
|
295
293
|
|
|
@@ -3,7 +3,7 @@ import { ParsingComponents } from "../../../results";
|
|
|
3
3
|
import { REGEX_PARTS, WEEKDAY_DICTIONARY } from "../constants";
|
|
4
4
|
import { matchAnyPattern } from "../../../utils/pattern";
|
|
5
5
|
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
-
import {
|
|
6
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
7
7
|
|
|
8
8
|
const PATTERN = new RegExp(
|
|
9
9
|
`(?:(?:,|\\(|()\\s*)?` +
|
|
@@ -31,7 +31,7 @@ export default class RUWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
31
31
|
|
|
32
32
|
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
33
33
|
const dayOfWeek = match[WEEKDAY_GROUP].toLowerCase();
|
|
34
|
-
const
|
|
34
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
35
35
|
const prefix = match[PREFIX_GROUP];
|
|
36
36
|
const postfix = match[POSTFIX_GROUP];
|
|
37
37
|
let modifierWord = prefix || postfix;
|
|
@@ -52,12 +52,6 @@ export default class RUWeekdayParser extends AbstractParserWithWordBoundaryCheck
|
|
|
52
52
|
modifier = "this";
|
|
53
53
|
}
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
return context
|
|
57
|
-
.createParsingComponents()
|
|
58
|
-
.assign("weekday", offset)
|
|
59
|
-
.imply("day", date.date())
|
|
60
|
-
.imply("month", date.month() + 1)
|
|
61
|
-
.imply("year", date.year());
|
|
55
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
62
56
|
}
|
|
63
57
|
}
|
|
@@ -6,7 +6,7 @@ import AbstractMergeDateRangeRefiner from "../../../common/refiners/AbstractMerg
|
|
|
6
6
|
* - c 06.09.1989 [до|по] 11.12.1996
|
|
7
7
|
* - c пятницы и до среды
|
|
8
8
|
*/
|
|
9
|
-
export default class
|
|
9
|
+
export default class RUMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner {
|
|
10
10
|
patternBetween(): RegExp {
|
|
11
11
|
return /^\s*(и до|и по|до|по|-)\s*$/i;
|
|
12
12
|
}
|
package/src/results.ts
CHANGED
|
@@ -19,6 +19,31 @@ export class ReferenceWithTimezone {
|
|
|
19
19
|
this.timezoneOffset = toTimezoneOffset(input.timezone);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns a JS date (system timezone) with the { year, month, day, hour, minute, second } equal to the reference.
|
|
25
|
+
* The output's instant is NOT the reference's instant when the reference's and system's timezone are different.
|
|
26
|
+
*/
|
|
27
|
+
getDateWithAdjustedTimezone() {
|
|
28
|
+
return new Date(this.instant.getTime() + this.getSystemTimezoneAdjustmentMinute(this.instant) * 60000);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the number minutes difference between the JS date's timezone and the reference timezone.
|
|
33
|
+
* @param date
|
|
34
|
+
* @param overrideTimezoneOffset
|
|
35
|
+
*/
|
|
36
|
+
getSystemTimezoneAdjustmentMinute(date?: Date, overrideTimezoneOffset?: number): number {
|
|
37
|
+
if (!date || date.getTime() < 0) {
|
|
38
|
+
// Javascript date timezone calculation got effect when the time epoch < 0
|
|
39
|
+
// e.g. new Date('Tue Feb 02 1300 00:00:00 GMT+0900 (JST)') => Tue Feb 02 1300 00:18:59 GMT+0918 (JST)
|
|
40
|
+
date = new Date();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const currentTimezoneOffset = -date.getTimezoneOffset();
|
|
44
|
+
const targetTimezoneOffset = overrideTimezoneOffset ?? this.timezoneOffset ?? currentTimezoneOffset;
|
|
45
|
+
return currentTimezoneOffset - targetTimezoneOffset;
|
|
46
|
+
}
|
|
22
47
|
}
|
|
23
48
|
|
|
24
49
|
export class ParsingComponents implements ParsedComponents {
|
|
@@ -141,7 +166,8 @@ export class ParsingComponents implements ParsedComponents {
|
|
|
141
166
|
|
|
142
167
|
date(): Date {
|
|
143
168
|
const date = this.dateWithoutTimezoneAdjustment();
|
|
144
|
-
|
|
169
|
+
const timezoneAdjustment = this.reference.getSystemTimezoneAdjustmentMinute(date, this.get("timezoneOffset"));
|
|
170
|
+
return new Date(date.getTime() + timezoneAdjustment * 60000);
|
|
145
171
|
}
|
|
146
172
|
|
|
147
173
|
private dateWithoutTimezoneAdjustment() {
|
|
@@ -159,20 +185,6 @@ export class ParsingComponents implements ParsedComponents {
|
|
|
159
185
|
return date;
|
|
160
186
|
}
|
|
161
187
|
|
|
162
|
-
private getSystemTimezoneAdjustmentMinute(date?: Date) {
|
|
163
|
-
if (!date || date.getTime() < 0) {
|
|
164
|
-
// Javascript date timezone calculation got effect when the time epoch < 0
|
|
165
|
-
// e.g. new Date('Tue Feb 02 1300 00:00:00 GMT+0900 (JST)') => Tue Feb 02 1300 00:18:59 GMT+0918 (JST)
|
|
166
|
-
date = new Date();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
const currentTimezoneOffset = -date.getTimezoneOffset();
|
|
170
|
-
const targetTimezoneOffset =
|
|
171
|
-
this.get("timezoneOffset") ?? this.reference.timezoneOffset ?? currentTimezoneOffset;
|
|
172
|
-
|
|
173
|
-
return currentTimezoneOffset - targetTimezoneOffset;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
188
|
static createRelativeFromReference(
|
|
177
189
|
reference: ReferenceWithTimezone,
|
|
178
190
|
fragments: { [c in QUnitType]?: number }
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { createParsingComponentsAtWeekday, getDaysToWeekday } from "../src/common/calculation/weekdays";
|
|
2
|
+
import { Weekday } from "../src";
|
|
3
|
+
import { ReferenceWithTimezone } from "../src/results";
|
|
4
|
+
|
|
5
|
+
test("Test - This Weekday Calculation", () => {
|
|
6
|
+
{
|
|
7
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, 20 Aug 2022 12:00:00"));
|
|
8
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.MONDAY, "this");
|
|
9
|
+
expect(output.date()).toStrictEqual(new Date("Mon, Aug 22 2022 12:00:00"));
|
|
10
|
+
}
|
|
11
|
+
{
|
|
12
|
+
const reference = new ReferenceWithTimezone(new Date("Sun, 21 Aug 2022 12:00:00"));
|
|
13
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.FRIDAY, "this");
|
|
14
|
+
expect(output.date()).toStrictEqual(new Date("Fri, Aug 26 2022 12:00:00"));
|
|
15
|
+
}
|
|
16
|
+
{
|
|
17
|
+
const reference = new ReferenceWithTimezone(new Date("Tue, Aug 2 2022 12:00:00"));
|
|
18
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SUNDAY, "this");
|
|
19
|
+
expect(output.date()).toStrictEqual(new Date("Sun, Aug 7 2022 12:00:00"));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test("Test - Last Weekday Calculation", () => {
|
|
24
|
+
{
|
|
25
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, 20 Aug 2022 12:00:00"));
|
|
26
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.FRIDAY, "last");
|
|
27
|
+
expect(output.date()).toStrictEqual(new Date("Fri, Aug 19 2022 12:00:00"));
|
|
28
|
+
}
|
|
29
|
+
{
|
|
30
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, 20 Aug 2022 12:00:00"));
|
|
31
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.MONDAY, "last");
|
|
32
|
+
expect(output.date()).toStrictEqual(new Date("Mon, Aug 15 2022 12:00:00"));
|
|
33
|
+
}
|
|
34
|
+
{
|
|
35
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, 20 Aug 2022 12:00:00"));
|
|
36
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SUNDAY, "last");
|
|
37
|
+
expect(output.date()).toStrictEqual(new Date("Sun, Aug 14 2022 12:00:00"));
|
|
38
|
+
}
|
|
39
|
+
{
|
|
40
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, 20 Aug 2022 12:00:00"));
|
|
41
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SATURDAY, "last");
|
|
42
|
+
expect(output.date()).toStrictEqual(new Date("Sat, Aug 13 2022 12:00:00"));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
test("Test - Next Weekday Calculation", () => {
|
|
47
|
+
{
|
|
48
|
+
const reference = new ReferenceWithTimezone(new Date("Sun, Aug 21 2022 12:00:00"));
|
|
49
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.MONDAY, "next");
|
|
50
|
+
expect(output.date()).toStrictEqual(new Date("Mon, Aug 22 2022 12:00:00"));
|
|
51
|
+
}
|
|
52
|
+
{
|
|
53
|
+
const reference = new ReferenceWithTimezone(new Date("Sun, Aug 21 2022 12:00:00"));
|
|
54
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SATURDAY, "next");
|
|
55
|
+
expect(output.date()).toStrictEqual(new Date("Sat, Aug 27 2022 12:00:00"));
|
|
56
|
+
}
|
|
57
|
+
{
|
|
58
|
+
const reference = new ReferenceWithTimezone(new Date("Sun, Aug 21 2022 12:00:00"));
|
|
59
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SUNDAY, "next");
|
|
60
|
+
expect(output.date()).toStrictEqual(new Date("Sun, Aug 28 2022 12:00:00"));
|
|
61
|
+
}
|
|
62
|
+
{
|
|
63
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, Aug 20 2022 12:00:00"));
|
|
64
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.FRIDAY, "next");
|
|
65
|
+
expect(output.date()).toStrictEqual(new Date("Fri, Aug 26 2022 12:00:00"));
|
|
66
|
+
}
|
|
67
|
+
{
|
|
68
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, Aug 20 2022 12:00:00"));
|
|
69
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SATURDAY, "next");
|
|
70
|
+
expect(output.date()).toStrictEqual(new Date("Sat, Aug 27 2022 12:00:00"));
|
|
71
|
+
}
|
|
72
|
+
{
|
|
73
|
+
const reference = new ReferenceWithTimezone(new Date("Sat, Aug 20 2022 12:00:00"));
|
|
74
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SUNDAY, "next");
|
|
75
|
+
expect(output.date()).toStrictEqual(new Date("Sun, Aug 28 2022 12:00:00"));
|
|
76
|
+
}
|
|
77
|
+
{
|
|
78
|
+
const reference = new ReferenceWithTimezone(new Date("Tue, Aug 2 2022 12:00:00"));
|
|
79
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.MONDAY, "next");
|
|
80
|
+
expect(output.date()).toStrictEqual(new Date("Mon, Aug 8 2022 12:00:00"));
|
|
81
|
+
}
|
|
82
|
+
{
|
|
83
|
+
const reference = new ReferenceWithTimezone(new Date("Tue, Aug 2 2022 12:00:00"));
|
|
84
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.FRIDAY, "next");
|
|
85
|
+
expect(output.date()).toStrictEqual(new Date("Fri, Aug 12 2022 12:00:00"));
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
const reference = new ReferenceWithTimezone(new Date("Tue, Aug 2 2022 12:00:00"));
|
|
90
|
+
const output = createParsingComponentsAtWeekday(reference, Weekday.SUNDAY, "next");
|
|
91
|
+
expect(output.date()).toStrictEqual(new Date("Sun, Aug 14 2022 12:00:00"));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
test("Test - Closest Weekday Calculation", () => {
|
|
96
|
+
{
|
|
97
|
+
const refDate = new Date("Sat, 20 Aug 2022 12:00:00");
|
|
98
|
+
expect(getDaysToWeekday(refDate, Weekday.MONDAY)).toBe(2);
|
|
99
|
+
}
|
|
100
|
+
{
|
|
101
|
+
const refDate = new Date("Sat, 20 Aug 2022 12:00:00");
|
|
102
|
+
expect(getDaysToWeekday(refDate, Weekday.TUESDAY)).toBe(3);
|
|
103
|
+
}
|
|
104
|
+
{
|
|
105
|
+
const refDate = new Date("Sat, 20 Aug 2022 12:00:00");
|
|
106
|
+
expect(getDaysToWeekday(refDate, Weekday.FRIDAY)).toBe(-1);
|
|
107
|
+
}
|
|
108
|
+
{
|
|
109
|
+
const refDate = new Date("Sat, 20 Aug 2022 12:00:00");
|
|
110
|
+
expect(getDaysToWeekday(refDate, Weekday.THURSDAY)).toBe(-2);
|
|
111
|
+
}
|
|
112
|
+
{
|
|
113
|
+
const refDate = new Date("Sat, 20 Aug 2022 12:00:00");
|
|
114
|
+
expect(getDaysToWeekday(refDate, Weekday.WEDNESDAY)).toBe(-3);
|
|
115
|
+
}
|
|
116
|
+
});
|
package/test/en/en.test.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as chrono from "../../src";
|
|
2
2
|
import { testSingleCase, testUnexpectedResult } from "../test_util";
|
|
3
3
|
import ENTimeExpressionParser from "../../src/locales/en/parsers/ENTimeExpressionParser";
|
|
4
|
+
import { Meridiem } from "../../src";
|
|
4
5
|
|
|
5
6
|
test("Test - Date + Time Expression", function () {
|
|
6
7
|
testSingleCase(chrono, "Something happen on 2014-04-18 13:00 - 16:00 as", (result) => {
|
|
@@ -95,6 +96,15 @@ test("Test - Random text", function () {
|
|
|
95
96
|
expect(result.start.get("day")).toBe(3);
|
|
96
97
|
expect(result.start.get("month")).toBe(7);
|
|
97
98
|
});
|
|
99
|
+
|
|
100
|
+
testSingleCase(chrono, "03-27-2022, 02:00 AM", new Date(2017, 7 - 1, 7), (result) => {
|
|
101
|
+
expect(result.text).toBe("03-27-2022, 02:00 AM");
|
|
102
|
+
expect(result.start.get("day")).toBe(27);
|
|
103
|
+
expect(result.start.get("month")).toBe(3);
|
|
104
|
+
expect(result.start.get("year")).toBe(2022);
|
|
105
|
+
expect(result.start.get("hour")).toBe(2);
|
|
106
|
+
expect(result.start.get("meridiem")).toBe(Meridiem.AM);
|
|
107
|
+
});
|
|
98
108
|
});
|
|
99
109
|
|
|
100
110
|
test("Test - Wikipedia Texts", function () {
|