chrono-node 2.6.3 → 2.6.4
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/README.md +25 -3
- package/dist/cjs/calculation/mergingCalculation.js +2 -2
- package/dist/cjs/chrono.d.ts +3 -1
- package/dist/cjs/chrono.js +10 -4
- package/dist/cjs/chrono.js.map +1 -1
- package/dist/cjs/common/calculation/weekdays.d.ts +1 -1
- package/dist/cjs/common/calculation/weekdays.js +7 -7
- package/dist/cjs/common/casualReferences.js +7 -7
- package/dist/cjs/common/parsers/AbstractParserWithWordBoundary.d.ts +1 -1
- package/dist/cjs/common/parsers/AbstractTimeExpressionParser.js +16 -16
- package/dist/cjs/common/refiners/ExtractTimezoneAbbrRefiner.d.ts +1 -1
- package/dist/cjs/index.d.ts +7 -62
- package/dist/cjs/index.js +8 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/locales/de/index.d.ts +5 -2
- package/dist/cjs/locales/de/index.js +7 -1
- package/dist/cjs/locales/de/index.js.map +1 -1
- package/dist/cjs/locales/de/parsers/DECasualTimeParser.js +8 -8
- package/dist/cjs/locales/de/parsers/DESpecificTimeExpressionParser.js +9 -9
- package/dist/cjs/locales/en/configuration.d.ts +5 -0
- package/dist/cjs/locales/en/configuration.js +58 -0
- package/dist/cjs/locales/en/configuration.js.map +1 -0
- package/dist/cjs/locales/en/constants.d.ts +1 -1
- package/dist/cjs/locales/en/index.d.ts +5 -4
- package/dist/cjs/locales/en/index.js +12 -51
- package/dist/cjs/locales/en/index.js.map +1 -1
- package/dist/cjs/locales/en/parsers/ENMonthNameMiddleEndianParser.d.ts +1 -1
- package/dist/cjs/locales/en/parsers/ENMonthNameParser.d.ts +1 -1
- package/dist/cjs/locales/en/parsers/ENTimeExpressionParser.js +5 -5
- package/dist/cjs/locales/es/index.d.ts +5 -2
- package/dist/cjs/locales/es/index.js +7 -1
- package/dist/cjs/locales/es/index.js.map +1 -1
- package/dist/cjs/locales/es/parsers/ESCasualTimeParser.js +5 -5
- package/dist/cjs/locales/fr/index.d.ts +5 -2
- package/dist/cjs/locales/fr/index.js +7 -1
- package/dist/cjs/locales/fr/index.js.map +1 -1
- package/dist/cjs/locales/fr/parsers/FRCasualDateParser.js +2 -2
- package/dist/cjs/locales/fr/parsers/FRCasualTimeParser.js +6 -6
- package/dist/cjs/locales/fr/parsers/FRSpecificTimeExpressionParser.js +6 -6
- package/dist/cjs/locales/ja/index.d.ts +5 -2
- package/dist/cjs/locales/ja/index.js +7 -1
- package/dist/cjs/locales/ja/index.js.map +1 -1
- package/dist/cjs/locales/ja/parsers/JPCasualDateParser.js +27 -5
- package/dist/cjs/locales/ja/parsers/JPCasualDateParser.js.map +1 -1
- package/dist/cjs/locales/nl/index.d.ts +5 -2
- package/dist/cjs/locales/nl/index.js +7 -1
- package/dist/cjs/locales/nl/index.js.map +1 -1
- package/dist/cjs/locales/nl/parsers/NLCasualDateTimeParser.js +5 -5
- package/dist/cjs/locales/nl/parsers/NLCasualTimeParser.js +5 -5
- package/dist/cjs/locales/nl/parsers/NLMonthNameMiddleEndianParser.d.ts +1 -1
- package/dist/cjs/locales/pt/index.d.ts +5 -2
- package/dist/cjs/locales/pt/index.js +7 -1
- package/dist/cjs/locales/pt/index.js.map +1 -1
- package/dist/cjs/locales/pt/parsers/PTCasualTimeParser.js +5 -5
- package/dist/cjs/locales/ru/index.d.ts +5 -2
- package/dist/cjs/locales/ru/index.js +7 -1
- package/dist/cjs/locales/ru/index.js.map +1 -1
- package/dist/cjs/locales/ru/parsers/RUMonthNameParser.d.ts +1 -1
- package/dist/cjs/locales/ru/parsers/RUTimeExpressionParser.js +5 -5
- package/dist/cjs/locales/uk/constants.d.ts +33 -0
- package/dist/cjs/locales/uk/constants.js +301 -0
- package/dist/cjs/locales/uk/constants.js.map +1 -0
- package/dist/cjs/locales/uk/index.d.ts +11 -0
- package/dist/cjs/locales/uk/index.js +64 -0
- package/dist/cjs/locales/uk/index.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKCasualDateParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKCasualDateParser.js +56 -0
- package/dist/cjs/locales/uk/parsers/UKCasualDateParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKCasualTimeParser.d.ts +7 -0
- package/dist/cjs/locales/uk/parsers/UKCasualTimeParser.js +77 -0
- package/dist/cjs/locales/uk/parsers/UKCasualTimeParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKMonthNameLittleEndianParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKMonthNameLittleEndianParser.js +59 -0
- package/dist/cjs/locales/uk/parsers/UKMonthNameLittleEndianParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKMonthNameParser.d.ts +7 -0
- package/dist/cjs/locales/uk/parsers/UKMonthNameParser.js +45 -0
- package/dist/cjs/locales/uk/parsers/UKMonthNameParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKRelativeDateFormatParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKRelativeDateFormatParser.js +66 -0
- package/dist/cjs/locales/uk/parsers/UKRelativeDateFormatParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKTimeExpressionParser.d.ts +12 -0
- package/dist/cjs/locales/uk/parsers/UKTimeExpressionParser.js +57 -0
- package/dist/cjs/locales/uk/parsers/UKTimeExpressionParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitAgoFormatParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitAgoFormatParser.js +22 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitAgoFormatParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.js +29 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitWithinFormatParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitWithinFormatParser.js +22 -0
- package/dist/cjs/locales/uk/parsers/UKTimeUnitWithinFormatParser.js.map +1 -0
- package/dist/cjs/locales/uk/parsers/UKWeekdayParser.d.ts +8 -0
- package/dist/cjs/locales/uk/parsers/UKWeekdayParser.js +50 -0
- package/dist/cjs/locales/uk/parsers/UKWeekdayParser.js.map +1 -0
- package/dist/cjs/locales/uk/refiners/UKMergeDateRangeRefiner.d.ts +4 -0
- package/dist/cjs/locales/uk/refiners/UKMergeDateRangeRefiner.js +13 -0
- package/dist/cjs/locales/uk/refiners/UKMergeDateRangeRefiner.js.map +1 -0
- package/dist/cjs/locales/uk/refiners/UKMergeDateTimeRefiner.d.ts +4 -0
- package/dist/cjs/locales/uk/refiners/UKMergeDateTimeRefiner.js +13 -0
- package/dist/cjs/locales/uk/refiners/UKMergeDateTimeRefiner.js.map +1 -0
- package/dist/cjs/locales/zh/hans/index.d.ts +5 -2
- package/dist/cjs/locales/zh/hans/index.js +8 -2
- package/dist/cjs/locales/zh/hans/index.js.map +1 -1
- package/dist/cjs/locales/zh/hans/parsers/ZHHansDateParser.d.ts +1 -1
- package/dist/cjs/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.d.ts +1 -1
- package/dist/cjs/locales/zh/hans/parsers/ZHHansTimeExpressionParser.d.ts +1 -1
- package/dist/cjs/locales/zh/hant/index.d.ts +5 -2
- package/dist/cjs/locales/zh/hant/index.js +8 -2
- package/dist/cjs/locales/zh/hant/index.js.map +1 -1
- package/dist/cjs/locales/zh/hant/parsers/ZHHantDateParser.d.ts +1 -1
- package/dist/cjs/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.d.ts +1 -1
- package/dist/cjs/locales/zh/hant/parsers/ZHHantTimeExpressionParser.d.ts +1 -1
- package/dist/cjs/results.d.ts +1 -1
- package/dist/cjs/timezone.d.ts +1 -1
- package/dist/cjs/timezone.js +11 -11
- package/dist/cjs/types.d.ts +58 -0
- package/dist/cjs/types.js +34 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils/dayjs.js +3 -3
- package/dist/esm/calculation/mergingCalculation.js +1 -1
- package/dist/esm/chrono.d.ts +3 -1
- package/dist/esm/chrono.js +7 -4
- package/dist/esm/chrono.js.map +1 -1
- package/dist/esm/common/calculation/weekdays.d.ts +1 -1
- package/dist/esm/common/calculation/weekdays.js +1 -1
- package/dist/esm/common/casualReferences.js +1 -1
- package/dist/esm/common/parsers/AbstractParserWithWordBoundary.d.ts +1 -1
- package/dist/esm/common/parsers/AbstractTimeExpressionParser.js +1 -1
- package/dist/esm/common/refiners/ExtractTimezoneAbbrRefiner.d.ts +1 -1
- package/dist/esm/index.d.ts +7 -62
- package/dist/esm/index.js +6 -32
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/locales/de/index.d.ts +5 -2
- package/dist/esm/locales/de/index.js +4 -0
- package/dist/esm/locales/de/index.js.map +1 -1
- package/dist/esm/locales/de/parsers/DECasualTimeParser.js +1 -1
- package/dist/esm/locales/de/parsers/DESpecificTimeExpressionParser.js +1 -1
- package/dist/esm/locales/en/configuration.d.ts +5 -0
- package/dist/esm/locales/en/configuration.js +52 -0
- package/dist/esm/locales/en/configuration.js.map +1 -0
- package/dist/esm/locales/en/constants.d.ts +1 -1
- package/dist/esm/locales/en/index.d.ts +5 -4
- package/dist/esm/locales/en/index.js +9 -48
- package/dist/esm/locales/en/index.js.map +1 -1
- package/dist/esm/locales/en/parsers/ENMonthNameMiddleEndianParser.d.ts +1 -1
- package/dist/esm/locales/en/parsers/ENMonthNameParser.d.ts +1 -1
- package/dist/esm/locales/en/parsers/ENTimeExpressionParser.js +1 -1
- package/dist/esm/locales/es/index.d.ts +5 -2
- package/dist/esm/locales/es/index.js +4 -0
- package/dist/esm/locales/es/index.js.map +1 -1
- package/dist/esm/locales/es/parsers/ESCasualTimeParser.js +1 -1
- package/dist/esm/locales/fr/index.d.ts +5 -2
- package/dist/esm/locales/fr/index.js +4 -0
- package/dist/esm/locales/fr/index.js.map +1 -1
- package/dist/esm/locales/fr/parsers/FRCasualDateParser.js +1 -1
- package/dist/esm/locales/fr/parsers/FRCasualTimeParser.js +1 -1
- package/dist/esm/locales/fr/parsers/FRSpecificTimeExpressionParser.js +1 -1
- package/dist/esm/locales/ja/index.d.ts +5 -2
- package/dist/esm/locales/ja/index.js +4 -0
- package/dist/esm/locales/ja/index.js.map +1 -1
- package/dist/esm/locales/ja/parsers/JPCasualDateParser.js +25 -3
- package/dist/esm/locales/ja/parsers/JPCasualDateParser.js.map +1 -1
- package/dist/esm/locales/nl/index.d.ts +5 -2
- package/dist/esm/locales/nl/index.js +4 -0
- package/dist/esm/locales/nl/index.js.map +1 -1
- package/dist/esm/locales/nl/parsers/NLCasualDateTimeParser.js +1 -1
- package/dist/esm/locales/nl/parsers/NLCasualTimeParser.js +1 -1
- package/dist/esm/locales/nl/parsers/NLMonthNameMiddleEndianParser.d.ts +1 -1
- package/dist/esm/locales/pt/index.d.ts +5 -2
- package/dist/esm/locales/pt/index.js +4 -0
- package/dist/esm/locales/pt/index.js.map +1 -1
- package/dist/esm/locales/pt/parsers/PTCasualTimeParser.js +1 -1
- package/dist/esm/locales/ru/index.d.ts +5 -2
- package/dist/esm/locales/ru/index.js +4 -0
- package/dist/esm/locales/ru/index.js.map +1 -1
- package/dist/esm/locales/ru/parsers/RUMonthNameParser.d.ts +1 -1
- package/dist/esm/locales/ru/parsers/RUTimeExpressionParser.js +1 -1
- package/dist/esm/locales/uk/constants.d.ts +33 -0
- package/dist/esm/locales/uk/constants.js +324 -0
- package/dist/esm/locales/uk/constants.js.map +1 -0
- package/dist/esm/locales/uk/index.d.ts +11 -0
- package/dist/esm/locales/uk/index.js +52 -0
- package/dist/esm/locales/uk/index.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKCasualDateParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKCasualDateParser.js +34 -0
- package/dist/esm/locales/uk/parsers/UKCasualDateParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKCasualTimeParser.d.ts +7 -0
- package/dist/esm/locales/uk/parsers/UKCasualTimeParser.js +52 -0
- package/dist/esm/locales/uk/parsers/UKCasualTimeParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKMonthNameLittleEndianParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKMonthNameLittleEndianParser.js +56 -0
- package/dist/esm/locales/uk/parsers/UKMonthNameLittleEndianParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKMonthNameParser.d.ts +7 -0
- package/dist/esm/locales/uk/parsers/UKMonthNameParser.js +42 -0
- package/dist/esm/locales/uk/parsers/UKMonthNameParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKRelativeDateFormatParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKRelativeDateFormatParser.js +60 -0
- package/dist/esm/locales/uk/parsers/UKRelativeDateFormatParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKTimeExpressionParser.d.ts +12 -0
- package/dist/esm/locales/uk/parsers/UKTimeExpressionParser.js +54 -0
- package/dist/esm/locales/uk/parsers/UKTimeExpressionParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitAgoFormatParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitAgoFormatParser.js +19 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitAgoFormatParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.js +26 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitWithinFormatParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitWithinFormatParser.js +19 -0
- package/dist/esm/locales/uk/parsers/UKTimeUnitWithinFormatParser.js.map +1 -0
- package/dist/esm/locales/uk/parsers/UKWeekdayParser.d.ts +8 -0
- package/dist/esm/locales/uk/parsers/UKWeekdayParser.js +47 -0
- package/dist/esm/locales/uk/parsers/UKWeekdayParser.js.map +1 -0
- package/dist/esm/locales/uk/refiners/UKMergeDateRangeRefiner.d.ts +4 -0
- package/dist/esm/locales/uk/refiners/UKMergeDateRangeRefiner.js +7 -0
- package/dist/esm/locales/uk/refiners/UKMergeDateRangeRefiner.js.map +1 -0
- package/dist/esm/locales/uk/refiners/UKMergeDateTimeRefiner.d.ts +4 -0
- package/dist/esm/locales/uk/refiners/UKMergeDateTimeRefiner.js +7 -0
- package/dist/esm/locales/uk/refiners/UKMergeDateTimeRefiner.js.map +1 -0
- package/dist/esm/locales/zh/hans/index.d.ts +5 -2
- package/dist/esm/locales/zh/hans/index.js +5 -1
- package/dist/esm/locales/zh/hans/index.js.map +1 -1
- package/dist/esm/locales/zh/hans/parsers/ZHHansDateParser.d.ts +1 -1
- package/dist/esm/locales/zh/hans/parsers/ZHHansDeadlineFormatParser.d.ts +1 -1
- package/dist/esm/locales/zh/hans/parsers/ZHHansTimeExpressionParser.d.ts +1 -1
- package/dist/esm/locales/zh/hant/index.d.ts +5 -2
- package/dist/esm/locales/zh/hant/index.js +5 -1
- package/dist/esm/locales/zh/hant/index.js.map +1 -1
- package/dist/esm/locales/zh/hant/parsers/ZHHantDateParser.d.ts +1 -1
- package/dist/esm/locales/zh/hant/parsers/ZHHantDeadlineFormatParser.d.ts +1 -1
- package/dist/esm/locales/zh/hant/parsers/ZHHantTimeExpressionParser.d.ts +1 -1
- package/dist/esm/results.d.ts +1 -1
- package/dist/esm/timezone.d.ts +1 -1
- package/dist/esm/timezone.js +1 -1
- package/dist/esm/types.d.ts +58 -0
- package/dist/esm/types.js +31 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils/dayjs.js +1 -1
- package/package.json +9 -1
- package/src/calculation/mergingCalculation.ts +1 -1
- package/src/chrono.ts +14 -8
- package/src/common/calculation/weekdays.ts +1 -1
- package/src/common/casualReferences.ts +1 -1
- package/src/common/parsers/AbstractParserWithWordBoundary.ts +1 -1
- package/src/common/parsers/AbstractTimeExpressionParser.ts +1 -1
- package/src/common/parsers/ISOFormatParser.ts +1 -1
- package/src/common/refiners/ExtractTimezoneAbbrRefiner.ts +1 -1
- package/src/index.ts +6 -151
- package/src/locales/de/index.ts +6 -2
- package/src/locales/de/parsers/DECasualTimeParser.ts +1 -1
- package/src/locales/de/parsers/DESpecificTimeExpressionParser.ts +1 -1
- package/src/locales/en/configuration.ts +70 -0
- package/src/locales/en/constants.ts +1 -1
- package/src/locales/en/index.ts +11 -65
- package/src/locales/en/parsers/ENTimeExpressionParser.ts +1 -1
- package/src/locales/es/index.ts +6 -2
- package/src/locales/es/parsers/ESCasualTimeParser.ts +1 -1
- package/src/locales/fr/index.ts +6 -2
- package/src/locales/fr/parsers/FRCasualDateParser.ts +1 -1
- package/src/locales/fr/parsers/FRCasualTimeParser.ts +1 -1
- package/src/locales/fr/parsers/FRSpecificTimeExpressionParser.ts +1 -1
- package/src/locales/ja/index.ts +6 -2
- package/src/locales/ja/parsers/JPCasualDateParser.ts +26 -3
- package/src/locales/nl/index.ts +6 -2
- package/src/locales/nl/parsers/NLCasualDateTimeParser.ts +1 -1
- package/src/locales/nl/parsers/NLCasualTimeParser.ts +1 -1
- package/src/locales/pt/index.ts +6 -2
- package/src/locales/pt/parsers/PTCasualTimeParser.ts +1 -1
- package/src/locales/ru/index.ts +6 -2
- package/src/locales/ru/parsers/RUTimeExpressionParser.ts +1 -1
- package/src/locales/uk/constants.ts +349 -0
- package/src/locales/uk/index.ts +90 -0
- package/src/locales/uk/parsers/UKCasualDateParser.ts +50 -0
- package/src/locales/uk/parsers/UKCasualTimeParser.ts +59 -0
- package/src/locales/uk/parsers/UKMonthNameLittleEndianParser.ts +72 -0
- package/src/locales/uk/parsers/UKMonthNameParser.ts +61 -0
- package/src/locales/uk/parsers/UKRelativeDateFormatParser.ts +85 -0
- package/src/locales/uk/parsers/UKTimeExpressionParser.ts +64 -0
- package/src/locales/uk/parsers/UKTimeUnitAgoFormatParser.ts +24 -0
- package/src/locales/uk/parsers/UKTimeUnitCasualRelativeFormatParser.ts +34 -0
- package/src/locales/uk/parsers/UKTimeUnitWithinFormatParser.ts +27 -0
- package/src/locales/uk/parsers/UKWeekdayParser.ts +59 -0
- package/src/locales/uk/refiners/UKMergeDateRangeRefiner.ts +13 -0
- package/src/locales/uk/refiners/UKMergeDateTimeRefiner.ts +13 -0
- package/src/locales/zh/hans/index.ts +6 -2
- package/src/locales/zh/hant/index.ts +6 -2
- package/src/results.ts +1 -1
- package/src/timezone.ts +1 -1
- package/src/types.ts +150 -0
- package/src/utils/dayjs.ts +1 -1
- package/test/debugging.test.ts +17 -0
- package/test/en/en_month_name_little_endian.test.ts +12 -0
- package/test/en/en_timezone_exp.test.ts +1 -1
- package/test/ja/ja_casual.test.ts +50 -13
- package/test/uk/uk_casual.test.ts +153 -0
- package/test/uk/uk_month.test.ts +70 -0
- package/test/uk/uk_month_name_little_endian.test.ts +148 -0
- package/test/uk/uk_relative.test.ts +74 -0
- package/test/uk/uk_time_exp.test.ts +111 -0
- package/test/uk/uk_time_units_ago.test.ts +48 -0
- package/test/uk/uk_time_units_casual_relative.test.ts +112 -0
- package/test/uk/uk_time_units_within.test.ts +16 -0
- package/test/uk/uk_weekday.test.ts +52 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { REGEX_PARTS, TIME_UNIT_DICTIONARY } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import dayjs from "dayjs";
|
|
5
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
6
|
+
import { matchAnyPattern } from "../../../utils/pattern";
|
|
7
|
+
|
|
8
|
+
const PATTERN = new RegExp(
|
|
9
|
+
`(в минулому|у минулому|на минулому|минулого|на наступному|в наступному|у наступному|наступного|на цьому|в цьому|у цьому|цього)\\s*(${matchAnyPattern(
|
|
10
|
+
TIME_UNIT_DICTIONARY
|
|
11
|
+
)})(?=\\s*)${REGEX_PARTS.rightBoundary}`,
|
|
12
|
+
REGEX_PARTS.flags
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
const MODIFIER_WORD_GROUP = 1;
|
|
16
|
+
const RELATIVE_WORD_GROUP = 2;
|
|
17
|
+
|
|
18
|
+
export default class UKRelativeDateFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
19
|
+
patternLeftBoundary(): string {
|
|
20
|
+
return REGEX_PARTS.leftBoundary;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
innerPattern(): RegExp {
|
|
24
|
+
return PATTERN;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
28
|
+
const modifier = match[MODIFIER_WORD_GROUP].toLowerCase();
|
|
29
|
+
const unitWord = match[RELATIVE_WORD_GROUP].toLowerCase();
|
|
30
|
+
const timeunit = TIME_UNIT_DICTIONARY[unitWord];
|
|
31
|
+
|
|
32
|
+
if (
|
|
33
|
+
modifier == "на наступному" ||
|
|
34
|
+
modifier == "в наступному" ||
|
|
35
|
+
modifier == "у наступному" ||
|
|
36
|
+
modifier == "наступного"
|
|
37
|
+
) {
|
|
38
|
+
const timeUnits = {};
|
|
39
|
+
timeUnits[timeunit] = 1;
|
|
40
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (
|
|
44
|
+
modifier == "на минулому" ||
|
|
45
|
+
modifier == "в минулому" ||
|
|
46
|
+
modifier == "у минулому" ||
|
|
47
|
+
modifier == "минулого"
|
|
48
|
+
) {
|
|
49
|
+
const timeUnits = {};
|
|
50
|
+
timeUnits[timeunit] = -1;
|
|
51
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const components = context.createParsingComponents();
|
|
55
|
+
let date = dayjs(context.reference.instant);
|
|
56
|
+
|
|
57
|
+
// This week
|
|
58
|
+
if (timeunit.match(/week/i)) {
|
|
59
|
+
date = date.add(-date.get("d"), "d");
|
|
60
|
+
components.imply("day", date.date());
|
|
61
|
+
components.imply("month", date.month() + 1);
|
|
62
|
+
components.imply("year", date.year());
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// This month
|
|
66
|
+
else if (timeunit.match(/month/i)) {
|
|
67
|
+
date = date.add(-date.date() + 1, "d");
|
|
68
|
+
components.imply("day", date.date());
|
|
69
|
+
components.assign("year", date.year());
|
|
70
|
+
components.assign("month", date.month() + 1);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// This year
|
|
74
|
+
else if (timeunit.match(/year/i)) {
|
|
75
|
+
date = date.add(-date.date() + 1, "d");
|
|
76
|
+
date = date.add(-date.month(), "month");
|
|
77
|
+
|
|
78
|
+
components.imply("day", date.date());
|
|
79
|
+
components.imply("month", date.month() + 1);
|
|
80
|
+
components.assign("year", date.year());
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return components;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
import { Meridiem } from "../../../types";
|
|
4
|
+
import { AbstractTimeExpressionParser } from "../../../common/parsers/AbstractTimeExpressionParser";
|
|
5
|
+
import { REGEX_PARTS } from "../constants";
|
|
6
|
+
|
|
7
|
+
export default class UKTimeExpressionParser extends AbstractTimeExpressionParser {
|
|
8
|
+
constructor(strictMode) {
|
|
9
|
+
super(strictMode);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
patternFlags(): string {
|
|
13
|
+
return REGEX_PARTS.flags;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
primaryPatternLeftBoundary(): string {
|
|
17
|
+
return `(^|\\s|T|(?:[^\\p{L}\\p{N}_]))`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
followingPhase(): string {
|
|
21
|
+
return `\\s*(?:\\-|\\–|\\~|\\〜|до|і|по|\\?)\\s*`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
primaryPrefix(): string {
|
|
25
|
+
return `(?:(?:в|у|о|об|з|із|від)\\s*)??`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
primarySuffix(): string {
|
|
29
|
+
return `(?:\\s*(?:ранку|вечора|по обіді|після обіду))?(?!\\/)${REGEX_PARTS.rightBoundary}`;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
extractPrimaryTimeComponents(context: ParsingContext, match: RegExpMatchArray): null | ParsingComponents {
|
|
33
|
+
const components = super.extractPrimaryTimeComponents(context, match);
|
|
34
|
+
if (components) {
|
|
35
|
+
if (match[0].endsWith("вечора")) {
|
|
36
|
+
const hour = components.get("hour");
|
|
37
|
+
if (hour >= 6 && hour < 12) {
|
|
38
|
+
components.assign("hour", components.get("hour") + 12);
|
|
39
|
+
components.assign("meridiem", Meridiem.PM);
|
|
40
|
+
} else if (hour < 6) {
|
|
41
|
+
components.assign("meridiem", Meridiem.AM);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (match[0].endsWith("по обіді") || match[0].endsWith("після обіду")) {
|
|
46
|
+
components.assign("meridiem", Meridiem.PM);
|
|
47
|
+
const hour = components.get("hour");
|
|
48
|
+
if (hour >= 0 && hour <= 6) {
|
|
49
|
+
components.assign("hour", components.get("hour") + 12);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (match[0].endsWith("ранку")) {
|
|
54
|
+
components.assign("meridiem", Meridiem.AM);
|
|
55
|
+
const hour = components.get("hour");
|
|
56
|
+
if (hour < 12) {
|
|
57
|
+
components.assign("hour", components.get("hour"));
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return components;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { parseTimeUnits, REGEX_PARTS, TIME_UNITS_PATTERN } from "../constants";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
import { reverseTimeUnits } from "../../../utils/timeunits";
|
|
6
|
+
|
|
7
|
+
const PATTERN = new RegExp(`(${TIME_UNITS_PATTERN})\\s{0,5}тому(?=(?:\\W|$))`, REGEX_PARTS.flags);
|
|
8
|
+
|
|
9
|
+
export default class UKTimeUnitAgoFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
10
|
+
patternLeftBoundary(): string {
|
|
11
|
+
return REGEX_PARTS.leftBoundary;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
innerPattern(): RegExp {
|
|
15
|
+
return PATTERN;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray) {
|
|
19
|
+
const timeUnits = parseTimeUnits(match[1]);
|
|
20
|
+
const outputTimeUnits = reverseTimeUnits(timeUnits);
|
|
21
|
+
|
|
22
|
+
return ParsingComponents.createRelativeFromReference(context.reference, outputTimeUnits);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { TIME_UNITS_PATTERN, parseTimeUnits, REGEX_PARTS } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
import { reverseTimeUnits } from "../../../utils/timeunits";
|
|
6
|
+
|
|
7
|
+
const PATTERN = new RegExp(
|
|
8
|
+
`(ці|останні|минулі|майбутні|наступні|після|через|\\+|-)\\s*(${TIME_UNITS_PATTERN})${REGEX_PARTS.rightBoundary}`,
|
|
9
|
+
REGEX_PARTS.flags
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export default class UKTimeUnitCasualRelativeFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
13
|
+
patternLeftBoundary(): string {
|
|
14
|
+
return REGEX_PARTS.leftBoundary;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
innerPattern(): RegExp {
|
|
18
|
+
return PATTERN;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
22
|
+
const prefix = match[1].toLowerCase();
|
|
23
|
+
let timeUnits = parseTimeUnits(match[3]);
|
|
24
|
+
switch (prefix) {
|
|
25
|
+
case "останні":
|
|
26
|
+
case "минулі":
|
|
27
|
+
case "-":
|
|
28
|
+
timeUnits = reverseTimeUnits(timeUnits);
|
|
29
|
+
break;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { TIME_UNITS_PATTERN, parseTimeUnits, REGEX_PARTS } from "../constants";
|
|
2
|
+
import { ParsingContext } from "../../../chrono";
|
|
3
|
+
import { ParsingComponents } from "../../../results";
|
|
4
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
5
|
+
|
|
6
|
+
const PATTERN = `(?:(?:приблизно|орієнтовно)\\s*(?:~\\s*)?)?(${TIME_UNITS_PATTERN})${REGEX_PARTS.rightBoundary}`;
|
|
7
|
+
const PATTERN_WITH_PREFIX = new RegExp(
|
|
8
|
+
`(?:протягом|на протязі|протягом|упродовж|впродовж)\\s*${PATTERN}`,
|
|
9
|
+
REGEX_PARTS.flags
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
const PATTERN_WITHOUT_PREFIX = new RegExp(PATTERN, "i");
|
|
13
|
+
|
|
14
|
+
export default class UKTimeUnitWithinFormatParser extends AbstractParserWithWordBoundaryChecking {
|
|
15
|
+
patternLeftBoundary(): string {
|
|
16
|
+
return REGEX_PARTS.leftBoundary;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
innerPattern(context: ParsingContext): RegExp {
|
|
20
|
+
return context.option.forwardDate ? PATTERN_WITHOUT_PREFIX : PATTERN_WITH_PREFIX;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
24
|
+
const timeUnits = parseTimeUnits(match[1]);
|
|
25
|
+
return ParsingComponents.createRelativeFromReference(context.reference, timeUnits);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { ParsingContext } from "../../../chrono";
|
|
2
|
+
import { ParsingComponents } from "../../../results";
|
|
3
|
+
// TODO: ADD REGEX_PARTS below
|
|
4
|
+
import { REGEX_PARTS, WEEKDAY_DICTIONARY } from "../constants";
|
|
5
|
+
import { matchAnyPattern } from "../../../utils/pattern";
|
|
6
|
+
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary";
|
|
7
|
+
import { createParsingComponentsAtWeekday } from "../../../common/calculation/weekdays";
|
|
8
|
+
|
|
9
|
+
const PATTERN = new RegExp(
|
|
10
|
+
`(?:(?:,|\\(|()\\s*)?` +
|
|
11
|
+
`(?:в\\s*?)?` +
|
|
12
|
+
`(?:у\\s*?)?` +
|
|
13
|
+
`(?:(цей|минулого|минулий|попередній|попереднього|наступного|наступний|наступному)\\s*)?` +
|
|
14
|
+
`(${matchAnyPattern(WEEKDAY_DICTIONARY)})` +
|
|
15
|
+
`(?:\\s*(?:,|\\)|)))?` +
|
|
16
|
+
`(?:\\s*(на|у|в)\\s*(цьому|минулому|наступному)\\s*тижні)?` +
|
|
17
|
+
`${REGEX_PARTS.rightBoundary}`,
|
|
18
|
+
REGEX_PARTS.flags
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
const PREFIX_GROUP = 1;
|
|
22
|
+
const WEEKDAY_GROUP = 2;
|
|
23
|
+
const POSTFIX_GROUP = 3;
|
|
24
|
+
|
|
25
|
+
export default class UKWeekdayParser extends AbstractParserWithWordBoundaryChecking {
|
|
26
|
+
innerPattern(): RegExp {
|
|
27
|
+
return PATTERN;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
patternLeftBoundary(): string {
|
|
31
|
+
return REGEX_PARTS.leftBoundary;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents {
|
|
35
|
+
const dayOfWeek = match[WEEKDAY_GROUP].toLocaleLowerCase();
|
|
36
|
+
const weekday = WEEKDAY_DICTIONARY[dayOfWeek];
|
|
37
|
+
const prefix = match[PREFIX_GROUP];
|
|
38
|
+
const postfix = match[POSTFIX_GROUP];
|
|
39
|
+
let modifierWord = prefix || postfix;
|
|
40
|
+
modifierWord = modifierWord || "";
|
|
41
|
+
modifierWord = modifierWord.toLocaleLowerCase();
|
|
42
|
+
|
|
43
|
+
let modifier = null;
|
|
44
|
+
if (
|
|
45
|
+
modifierWord == "минулого" ||
|
|
46
|
+
modifierWord == "минулий" ||
|
|
47
|
+
modifierWord == "попередній" ||
|
|
48
|
+
modifierWord == "попереднього"
|
|
49
|
+
) {
|
|
50
|
+
modifier = "last";
|
|
51
|
+
} else if (modifierWord == "наступного" || modifierWord == "наступний") {
|
|
52
|
+
modifier = "next";
|
|
53
|
+
} else if (modifierWord == "цей" || modifierWord == "цього" || modifierWord == "цьому") {
|
|
54
|
+
modifier = "this";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return createParsingComponentsAtWeekday(context.reference, weekday, modifier);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AbstractMergeDateRangeRefiner from "../../../common/refiners/AbstractMergeDateRangeRefiner";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merging before and after results (see. AbstractMergeDateRangeRefiner)
|
|
5
|
+
* This implementation should provide Russian connecting phases
|
|
6
|
+
* - [з|із] 06.09.1989 [до|по] 11.12.1996
|
|
7
|
+
* - [з|із] п'ятниці і до середи
|
|
8
|
+
*/
|
|
9
|
+
export default class UKMergeDateRangeRefiner extends AbstractMergeDateRangeRefiner {
|
|
10
|
+
patternBetween(): RegExp {
|
|
11
|
+
return /^\s*(і до|і по|до|по|-)\s*$/i;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import AbstractMergeDateTimeRefiner from "../../../common/refiners/AbstractMergeDateTimeRefiner";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Merging date-only result and time-only result (see. AbstractMergeDateTimeRefiner).
|
|
5
|
+
* This implementation should provide Ukrainian connecting phases
|
|
6
|
+
* - 2020-02-13 [в/у/о] 6:00
|
|
7
|
+
* - Завтра [,] 7:00
|
|
8
|
+
*/
|
|
9
|
+
export default class UKMergeDateTimeRefiner extends AbstractMergeDateTimeRefiner {
|
|
10
|
+
patternBetween(): RegExp {
|
|
11
|
+
return new RegExp(`^\\s*(T|в|у|о|,|-)?\\s*$`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
* Chrono components for zh support
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { Chrono, Configuration } from "../../../chrono";
|
|
6
5
|
import ExtractTimezoneOffsetRefiner from "../../../common/refiners/ExtractTimezoneOffsetRefiner";
|
|
7
6
|
import { includeCommonConfiguration } from "../../../configurations";
|
|
8
|
-
import {
|
|
7
|
+
import { Chrono, Configuration, Parser, Refiner } from "../../../chrono";
|
|
8
|
+
import { ParsingResult } from "../../../results";
|
|
9
|
+
import { Component, ParsedResult, ParsingOption, ParsingReference, Meridiem, Weekday } from "../../../types";
|
|
9
10
|
import ZHHansCasualDateParser from "./parsers/ZHHansCasualDateParser";
|
|
10
11
|
import ZHHansDateParser from "./parsers/ZHHansDateParser";
|
|
11
12
|
import ZHHansDeadlineFormatParser from "./parsers/ZHHansDeadlineFormatParser";
|
|
@@ -15,6 +16,9 @@ import ZHHansWeekdayParser from "./parsers/ZHHansWeekdayParser";
|
|
|
15
16
|
import ZHHansMergeDateRangeRefiner from "./refiners/ZHHansMergeDateRangeRefiner";
|
|
16
17
|
import ZHHansMergeDateTimeRefiner from "./refiners/ZHHansMergeDateTimeRefiner";
|
|
17
18
|
|
|
19
|
+
export { Chrono, Parser, Refiner, ParsingResult };
|
|
20
|
+
export { Component, ParsedResult, ParsingOption, ParsingReference, Meridiem, Weekday };
|
|
21
|
+
|
|
18
22
|
// Shortcuts
|
|
19
23
|
export const hans = new Chrono(createCasualConfiguration());
|
|
20
24
|
|
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
* TODO: Complete general zh support (current support only zh-Hant)
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { Chrono, Configuration } from "../../../chrono";
|
|
7
6
|
import ExtractTimezoneOffsetRefiner from "../../../common/refiners/ExtractTimezoneOffsetRefiner";
|
|
8
7
|
import { includeCommonConfiguration } from "../../../configurations";
|
|
9
|
-
import {
|
|
8
|
+
import { Chrono, Configuration, Parser, Refiner } from "../../../chrono";
|
|
9
|
+
import { ParsingResult } from "../../../results";
|
|
10
|
+
import { Component, ParsedResult, ParsingOption, ParsingReference, Meridiem, Weekday } from "../../../types";
|
|
10
11
|
import ZHHantCasualDateParser from "./parsers/ZHHantCasualDateParser";
|
|
11
12
|
import ZHHantDateParser from "./parsers/ZHHantDateParser";
|
|
12
13
|
import ZHHantDeadlineFormatParser from "./parsers/ZHHantDeadlineFormatParser";
|
|
@@ -16,6 +17,9 @@ import ZHHantWeekdayParser from "./parsers/ZHHantWeekdayParser";
|
|
|
16
17
|
import ZHHantMergeDateRangeRefiner from "./refiners/ZHHantMergeDateRangeRefiner";
|
|
17
18
|
import ZHHantMergeDateTimeRefiner from "./refiners/ZHHantMergeDateTimeRefiner";
|
|
18
19
|
|
|
20
|
+
export { Chrono, Parser, Refiner, ParsingResult };
|
|
21
|
+
export { Component, ParsedResult, ParsingOption, ParsingReference, Meridiem, Weekday };
|
|
22
|
+
|
|
19
23
|
// Shortcuts
|
|
20
24
|
export const hant = new Chrono(createCasualConfiguration());
|
|
21
25
|
|
package/src/results.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Component, ParsedComponents, ParsedResult, ParsingReference } from "./
|
|
1
|
+
import { Component, ParsedComponents, ParsedResult, ParsingReference } from "./types";
|
|
2
2
|
|
|
3
3
|
import quarterOfYear from "dayjs/plugin/quarterOfYear";
|
|
4
4
|
import dayjs, { QUnitType } from "dayjs";
|
package/src/timezone.ts
CHANGED
package/src/types.ts
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { DebugConsume, DebugHandler } from "./debugging";
|
|
2
|
+
|
|
3
|
+
export interface ParsingOption {
|
|
4
|
+
/**
|
|
5
|
+
* To parse only forward dates (the results should be after the reference date).
|
|
6
|
+
* This effects date/time implication (e.g. weekday or time mentioning)
|
|
7
|
+
*/
|
|
8
|
+
forwardDate?: boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Additional timezone keywords for the parsers to recognize.
|
|
12
|
+
* Any value provided will override the default handling of that value.
|
|
13
|
+
*/
|
|
14
|
+
timezones?: TimezoneAbbrMap;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Internal debug event handler.
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
debug?: DebugHandler | DebugConsume;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Some timezone abbreviations are ambiguous in that they refer to different offsets
|
|
25
|
+
* depending on the time of year — daylight savings time (DST), or non-DST. This interface
|
|
26
|
+
* allows defining such timezones
|
|
27
|
+
*/
|
|
28
|
+
export interface AmbiguousTimezoneMap {
|
|
29
|
+
timezoneOffsetDuringDst: number;
|
|
30
|
+
timezoneOffsetNonDst: number;
|
|
31
|
+
/**
|
|
32
|
+
* Return the start date of DST for the given year.
|
|
33
|
+
* timezone.ts contains helper methods for common such rules.
|
|
34
|
+
*/
|
|
35
|
+
dstStart: (year: number) => Date;
|
|
36
|
+
/**
|
|
37
|
+
* Return the end date of DST for the given year.
|
|
38
|
+
* timezone.ts contains helper methods for common such rules.
|
|
39
|
+
*/
|
|
40
|
+
dstEnd: (year: number) => Date;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* A map describing how timezone abbreviations should map to time offsets.
|
|
45
|
+
* Supports both unambigous mappings abbreviation => offset,
|
|
46
|
+
* and ambiguous mappings, where the offset will depend on whether the
|
|
47
|
+
* time in question is during daylight savings time or not.
|
|
48
|
+
*/
|
|
49
|
+
export type TimezoneAbbrMap = { [key: string]: number | AmbiguousTimezoneMap };
|
|
50
|
+
|
|
51
|
+
export interface ParsingReference {
|
|
52
|
+
/**
|
|
53
|
+
* Reference date. The instant (JavaScript Date object) when the input is written or mention.
|
|
54
|
+
* This effect date/time implication (e.g. weekday or time mentioning).
|
|
55
|
+
* (default = now)
|
|
56
|
+
*/
|
|
57
|
+
instant?: Date;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Reference timezone. The timezone where the input is written or mention.
|
|
61
|
+
* Date/time implication will account the difference between input timezone and the current system timezone.
|
|
62
|
+
* (default = current timezone)
|
|
63
|
+
*/
|
|
64
|
+
timezone?: string | number;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Parsed result or final output.
|
|
69
|
+
* Each result object represents a date/time (or date/time-range) mentioning in the input.
|
|
70
|
+
*/
|
|
71
|
+
export interface ParsedResult {
|
|
72
|
+
readonly refDate: Date;
|
|
73
|
+
readonly index: number;
|
|
74
|
+
readonly text: string;
|
|
75
|
+
|
|
76
|
+
readonly start: ParsedComponents;
|
|
77
|
+
readonly end?: ParsedComponents;
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Create a javascript date object (from the result.start).
|
|
81
|
+
*/
|
|
82
|
+
date(): Date;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* A collection of parsed date/time components (e.g. day, hour, minute, ..., etc).
|
|
87
|
+
*
|
|
88
|
+
* Each parsed component has three different levels of certainty.
|
|
89
|
+
* - *Certain* (or *Known*): The component is directly mentioned and parsed.
|
|
90
|
+
* - *Implied*: The component is not directly mentioned, but implied by other parsed information.
|
|
91
|
+
* - *Unknown*: Completely no mention of the component.
|
|
92
|
+
*/
|
|
93
|
+
export interface ParsedComponents {
|
|
94
|
+
/**
|
|
95
|
+
* Check the component certainly if the component is *Certain* (or *Known*)
|
|
96
|
+
*/
|
|
97
|
+
isCertain(component: Component): boolean;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Get the component value for either *Certain* or *Implied* value.
|
|
101
|
+
*/
|
|
102
|
+
get(component: Component): number | null;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* @return a javascript date object.
|
|
106
|
+
*/
|
|
107
|
+
date(): Date;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type Component =
|
|
111
|
+
| "year"
|
|
112
|
+
| "month"
|
|
113
|
+
| "day"
|
|
114
|
+
| "weekday"
|
|
115
|
+
| "hour"
|
|
116
|
+
| "minute"
|
|
117
|
+
| "second"
|
|
118
|
+
| "millisecond"
|
|
119
|
+
| "meridiem"
|
|
120
|
+
| "timezoneOffset";
|
|
121
|
+
|
|
122
|
+
export enum Meridiem {
|
|
123
|
+
AM = 0,
|
|
124
|
+
PM = 1,
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export enum Weekday {
|
|
128
|
+
SUNDAY = 0,
|
|
129
|
+
MONDAY = 1,
|
|
130
|
+
TUESDAY = 2,
|
|
131
|
+
WEDNESDAY = 3,
|
|
132
|
+
THURSDAY = 4,
|
|
133
|
+
FRIDAY = 5,
|
|
134
|
+
SATURDAY = 6,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export enum Month {
|
|
138
|
+
JANUARY = 1,
|
|
139
|
+
FEBRUARY = 2,
|
|
140
|
+
MARCH = 3,
|
|
141
|
+
APRIL = 4,
|
|
142
|
+
MAY = 5,
|
|
143
|
+
JUNE = 6,
|
|
144
|
+
JULY = 7,
|
|
145
|
+
AUGUST = 8,
|
|
146
|
+
SEPTEMBER = 9,
|
|
147
|
+
OCTOBER = 10,
|
|
148
|
+
NOVEMBER = 11,
|
|
149
|
+
DECEMBER = 12,
|
|
150
|
+
}
|
package/src/utils/dayjs.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ParsingComponents } from "../results";
|
|
2
2
|
import dayjs from "dayjs";
|
|
3
|
-
import { Meridiem } from "../
|
|
3
|
+
import { Meridiem } from "../types";
|
|
4
4
|
|
|
5
5
|
export function assignTheNextDay(component: ParsingComponents, targetDayJs: dayjs.Dayjs) {
|
|
6
6
|
targetDayJs = targetDayJs.add(1, "day");
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { BufferedDebugHandler } from "../src/debugging";
|
|
2
|
+
|
|
3
|
+
test("Test - BufferedDebugHandler", () => {
|
|
4
|
+
const debugHandler = new BufferedDebugHandler();
|
|
5
|
+
|
|
6
|
+
const debugBlockA = jest.fn();
|
|
7
|
+
debugHandler.debug(() => debugBlockA());
|
|
8
|
+
expect(debugBlockA).not.toBeCalled();
|
|
9
|
+
|
|
10
|
+
const debugBlockB = jest.fn();
|
|
11
|
+
debugHandler.debug(() => debugBlockB());
|
|
12
|
+
expect(debugBlockB).not.toBeCalled();
|
|
13
|
+
|
|
14
|
+
debugHandler.executeBufferedBlocks();
|
|
15
|
+
expect(debugBlockA).toBeCalled();
|
|
16
|
+
expect(debugBlockB).toBeCalled();
|
|
17
|
+
});
|
|
@@ -211,6 +211,18 @@ test("Test - Range expression", () => {
|
|
|
211
211
|
|
|
212
212
|
expect(result.end).toBeDate(new Date(2013, 9 - 1, 12, 12));
|
|
213
213
|
});
|
|
214
|
+
|
|
215
|
+
testSingleCase(chrono, " 17 August 2013 to 19 August 2013", new Date(2012, 7, 10), (result) => {
|
|
216
|
+
expect(result.text).toBe("17 August 2013 to 19 August 2013");
|
|
217
|
+
|
|
218
|
+
expect(result.start.get("year")).toBe(2013);
|
|
219
|
+
expect(result.start.get("month")).toBe(8);
|
|
220
|
+
expect(result.start.get("day")).toBe(17);
|
|
221
|
+
|
|
222
|
+
expect(result.end.get("year")).toBe(2013);
|
|
223
|
+
expect(result.end.get("month")).toBe(8);
|
|
224
|
+
expect(result.end.get("day")).toBe(19);
|
|
225
|
+
});
|
|
214
226
|
});
|
|
215
227
|
|
|
216
228
|
test("Test - Combined expression", () => {
|