chrono-node 2.6.2 → 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 +56 -4
- 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/AbstractMergeDateRangeRefiner.js +15 -7
- package/dist/cjs/common/refiners/AbstractMergeDateRangeRefiner.js.map +1 -1
- package/dist/cjs/common/refiners/ExtractTimezoneAbbrRefiner.d.ts +3 -4
- package/dist/cjs/common/refiners/ExtractTimezoneAbbrRefiner.js +6 -196
- package/dist/cjs/common/refiners/ExtractTimezoneAbbrRefiner.js.map +1 -1
- package/dist/cjs/common/refiners/ForwardDateRefiner.js +14 -14
- package/dist/cjs/common/refiners/ForwardDateRefiner.js.map +1 -1
- package/dist/cjs/configurations.js +1 -1
- package/dist/cjs/configurations.js.map +1 -1
- package/dist/cjs/index.d.ts +7 -41
- package/dist/cjs/index.js +8 -16
- 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 +5 -1
- package/dist/cjs/locales/en/constants.js +5 -18
- package/dist/cjs/locales/en/constants.js.map +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/en/parsers/ENTimeUnitAgoFormatParser.js +2 -2
- package/dist/cjs/locales/en/parsers/ENTimeUnitAgoFormatParser.js.map +1 -1
- package/dist/cjs/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.d.ts +2 -0
- package/dist/cjs/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +6 -1
- package/dist/cjs/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js.map +1 -1
- package/dist/cjs/locales/en/parsers/ENTimeUnitLaterFormatParser.js +1 -1
- package/dist/cjs/locales/en/parsers/ENTimeUnitLaterFormatParser.js.map +1 -1
- package/dist/cjs/locales/en/parsers/ENTimeUnitWithinFormatParser.d.ts +2 -0
- package/dist/cjs/locales/en/parsers/ENTimeUnitWithinFormatParser.js +10 -1
- package/dist/cjs/locales/en/parsers/ENTimeUnitWithinFormatParser.js.map +1 -1
- 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/constants.js +4 -1
- package/dist/cjs/locales/ru/constants.js.map +1 -1
- 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 +2 -2
- package/dist/cjs/results.js +3 -3
- package/dist/cjs/results.js.map +1 -1
- package/dist/cjs/timezone.d.ts +5 -194
- package/dist/cjs/timezone.js +80 -7
- package/dist/cjs/timezone.js.map +1 -1
- 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/AbstractMergeDateRangeRefiner.js +15 -7
- package/dist/esm/common/refiners/AbstractMergeDateRangeRefiner.js.map +1 -1
- package/dist/esm/common/refiners/ExtractTimezoneAbbrRefiner.d.ts +3 -4
- package/dist/esm/common/refiners/ExtractTimezoneAbbrRefiner.js +6 -196
- package/dist/esm/common/refiners/ExtractTimezoneAbbrRefiner.js.map +1 -1
- package/dist/esm/common/refiners/ForwardDateRefiner.js +14 -14
- package/dist/esm/common/refiners/ForwardDateRefiner.js.map +1 -1
- package/dist/esm/configurations.js +1 -1
- package/dist/esm/configurations.js.map +1 -1
- package/dist/esm/index.d.ts +7 -41
- package/dist/esm/index.js +6 -17
- 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 +5 -1
- package/dist/esm/locales/en/constants.js +21 -0
- package/dist/esm/locales/en/constants.js.map +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/en/parsers/ENTimeUnitAgoFormatParser.js +3 -3
- package/dist/esm/locales/en/parsers/ENTimeUnitAgoFormatParser.js.map +1 -1
- package/dist/esm/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.d.ts +2 -0
- package/dist/esm/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js +7 -2
- package/dist/esm/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.js.map +1 -1
- package/dist/esm/locales/en/parsers/ENTimeUnitLaterFormatParser.js +2 -2
- package/dist/esm/locales/en/parsers/ENTimeUnitLaterFormatParser.js.map +1 -1
- package/dist/esm/locales/en/parsers/ENTimeUnitWithinFormatParser.d.ts +2 -0
- package/dist/esm/locales/en/parsers/ENTimeUnitWithinFormatParser.js +11 -2
- package/dist/esm/locales/en/parsers/ENTimeUnitWithinFormatParser.js.map +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/constants.js +4 -1
- package/dist/esm/locales/ru/constants.js.map +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 +2 -2
- package/dist/esm/results.js +3 -3
- package/dist/esm/results.js.map +1 -1
- package/dist/esm/timezone.d.ts +5 -194
- package/dist/esm/timezone.js +74 -6
- package/dist/esm/timezone.js.map +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 +12 -5
- 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/AbstractMergeDateRangeRefiner.ts +13 -8
- package/src/common/refiners/ExtractTimezoneAbbrRefiner.ts +7 -201
- package/src/common/refiners/ForwardDateRefiner.ts +18 -16
- package/src/configurations.ts +3 -1
- package/src/index.ts +6 -107
- 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 +31 -1
- package/src/locales/en/index.ts +11 -65
- package/src/locales/en/parsers/ENTimeExpressionParser.ts +1 -1
- package/src/locales/en/parsers/ENTimeUnitAgoFormatParser.ts +3 -3
- package/src/locales/en/parsers/ENTimeUnitCasualRelativeFormatParser.ts +10 -2
- package/src/locales/en/parsers/ENTimeUnitLaterFormatParser.ts +5 -2
- package/src/locales/en/parsers/ENTimeUnitWithinFormatParser.ts +16 -3
- 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/constants.ts +4 -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 +4 -4
- package/src/timezone.ts +124 -7
- package/src/types.ts +150 -0
- package/src/utils/dayjs.ts +1 -1
- package/test/de/de_time_exp.test.ts +7 -7
- package/test/debugging.test.ts +17 -0
- package/test/en/en_month.test.ts +70 -0
- package/test/en/en_month_name_little_endian.test.ts +12 -0
- package/test/en/en_time_units_ago.test.ts +12 -0
- package/test/en/en_time_units_casual_relative.test.ts +18 -0
- package/test/en/en_time_units_later.test.ts +13 -10
- package/test/en/en_time_units_within.test.ts +12 -1
- package/test/en/en_timezone_exp.test.ts +142 -0
- package/test/en/en_weekday.test.ts +26 -0
- package/test/en/negative_cases.test.ts +2 -0
- package/test/fr/fr_time_exp.test.ts +2 -2
- package/test/ja/ja_casual.test.ts +50 -13
- package/test/system.test.ts +23 -1
- 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";
|
|
@@ -16,7 +16,7 @@ export class ReferenceWithTimezone {
|
|
|
16
16
|
this.instant = input;
|
|
17
17
|
} else {
|
|
18
18
|
this.instant = input.instant ?? new Date();
|
|
19
|
-
this.timezoneOffset = toTimezoneOffset(input.timezone);
|
|
19
|
+
this.timezoneOffset = toTimezoneOffset(input.timezone, this.instant);
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -138,8 +138,8 @@ export class ParsingComponents implements ParsedComponents {
|
|
|
138
138
|
return this.isCertain("weekday") && !this.isCertain("day") && !this.isCertain("month");
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
return this.isCertain("
|
|
141
|
+
isDateWithUnknownYear(): boolean {
|
|
142
|
+
return this.isCertain("month") && !this.isCertain("year");
|
|
143
143
|
}
|
|
144
144
|
|
|
145
145
|
isValidDate(): boolean {
|
package/src/timezone.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { TimezoneAbbrMap, Weekday, Month } from "./types";
|
|
3
|
+
|
|
4
|
+
export const TIMEZONE_ABBR_MAP: TimezoneAbbrMap = {
|
|
2
5
|
ACDT: 630,
|
|
3
6
|
ACST: 570,
|
|
4
7
|
ADT: -180,
|
|
@@ -32,7 +35,14 @@ export const TIMEZONE_ABBR_MAP = {
|
|
|
32
35
|
CCT: 390,
|
|
33
36
|
CDT: -300,
|
|
34
37
|
CEST: 120,
|
|
35
|
-
|
|
38
|
+
// Note: Many sources define CET as a constant UTC+1. In common usage, however,
|
|
39
|
+
// CET usually refers to the time observed in most of Europe, be it standard time or daylight saving time.
|
|
40
|
+
CET: {
|
|
41
|
+
timezoneOffsetDuringDst: 2 * 60,
|
|
42
|
+
timezoneOffsetNonDst: 60,
|
|
43
|
+
dstStart: (year: number) => getLastWeekdayOfMonth(year, Month.MARCH, Weekday.SUNDAY, 2),
|
|
44
|
+
dstEnd: (year: number) => getLastWeekdayOfMonth(year, Month.OCTOBER, Weekday.SUNDAY, 3),
|
|
45
|
+
},
|
|
36
46
|
CHADT: 825,
|
|
37
47
|
CHAST: 765,
|
|
38
48
|
CKT: -600,
|
|
@@ -40,6 +50,12 @@ export const TIMEZONE_ABBR_MAP = {
|
|
|
40
50
|
CLT: -240,
|
|
41
51
|
COT: -300,
|
|
42
52
|
CST: -360,
|
|
53
|
+
CT: {
|
|
54
|
+
timezoneOffsetDuringDst: -5 * 60,
|
|
55
|
+
timezoneOffsetNonDst: -6 * 60,
|
|
56
|
+
dstStart: (year: number) => getNthWeekdayOfMonth(year, Month.MARCH, Weekday.SUNDAY, 2, 2),
|
|
57
|
+
dstEnd: (year: number) => getNthWeekdayOfMonth(year, Month.NOVEMBER, Weekday.SUNDAY, 1, 2),
|
|
58
|
+
},
|
|
43
59
|
CVT: -60,
|
|
44
60
|
CXT: 420,
|
|
45
61
|
ChST: 600,
|
|
@@ -54,7 +70,12 @@ export const TIMEZONE_ABBR_MAP = {
|
|
|
54
70
|
EGST: 0,
|
|
55
71
|
EGT: -60,
|
|
56
72
|
EST: -300,
|
|
57
|
-
ET:
|
|
73
|
+
ET: {
|
|
74
|
+
timezoneOffsetDuringDst: -4 * 60,
|
|
75
|
+
timezoneOffsetNonDst: -5 * 60,
|
|
76
|
+
dstStart: (year: number) => getNthWeekdayOfMonth(year, Month.MARCH, Weekday.SUNDAY, 2, 2),
|
|
77
|
+
dstEnd: (year: number) => getNthWeekdayOfMonth(year, Month.NOVEMBER, Weekday.SUNDAY, 1, 2),
|
|
78
|
+
},
|
|
58
79
|
FJST: 780,
|
|
59
80
|
FJT: 720,
|
|
60
81
|
FKST: -180,
|
|
@@ -116,6 +137,12 @@ export const TIMEZONE_ABBR_MAP = {
|
|
|
116
137
|
MSD: 240,
|
|
117
138
|
MSK: 180,
|
|
118
139
|
MST: -420,
|
|
140
|
+
MT: {
|
|
141
|
+
timezoneOffsetDuringDst: -6 * 60,
|
|
142
|
+
timezoneOffsetNonDst: -7 * 60,
|
|
143
|
+
dstStart: (year: number) => getNthWeekdayOfMonth(year, Month.MARCH, Weekday.SUNDAY, 2, 2),
|
|
144
|
+
dstEnd: (year: number) => getNthWeekdayOfMonth(year, Month.NOVEMBER, Weekday.SUNDAY, 1, 2),
|
|
145
|
+
},
|
|
119
146
|
MUT: 240,
|
|
120
147
|
MVT: 300,
|
|
121
148
|
MYT: 480,
|
|
@@ -143,7 +170,12 @@ export const TIMEZONE_ABBR_MAP = {
|
|
|
143
170
|
PMST: -180,
|
|
144
171
|
PONT: 660,
|
|
145
172
|
PST: -480,
|
|
146
|
-
PT:
|
|
173
|
+
PT: {
|
|
174
|
+
timezoneOffsetDuringDst: -7 * 60,
|
|
175
|
+
timezoneOffsetNonDst: -8 * 60,
|
|
176
|
+
dstStart: (year: number) => getNthWeekdayOfMonth(year, Month.MARCH, Weekday.SUNDAY, 2, 2),
|
|
177
|
+
dstEnd: (year: number) => getNthWeekdayOfMonth(year, Month.NOVEMBER, Weekday.SUNDAY, 1, 2),
|
|
178
|
+
},
|
|
147
179
|
PWT: 540,
|
|
148
180
|
PYST: -180,
|
|
149
181
|
PYT: -240,
|
|
@@ -192,8 +224,67 @@ export const TIMEZONE_ABBR_MAP = {
|
|
|
192
224
|
YEKT: 360,
|
|
193
225
|
};
|
|
194
226
|
|
|
195
|
-
|
|
196
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Get the date which is the nth occurence of a given weekday in a given month and year.
|
|
229
|
+
*
|
|
230
|
+
* @param year The year for which to find the date
|
|
231
|
+
* @param month The month in which the date occurs
|
|
232
|
+
* @param weekday The weekday on which the date occurs
|
|
233
|
+
* @param n The nth occurence of the given weekday on the month to return
|
|
234
|
+
* @param hour The hour of day which should be set on the returned date
|
|
235
|
+
* @return The date which is the nth occurence of a given weekday in a given
|
|
236
|
+
* month and year, at the given hour of day
|
|
237
|
+
*/
|
|
238
|
+
export function getNthWeekdayOfMonth(year: number, month: Month, weekday: Weekday, n: 1 | 2 | 3 | 4, hour = 0): Date {
|
|
239
|
+
let dayOfMonth = 0;
|
|
240
|
+
let i = 0;
|
|
241
|
+
while (i < n) {
|
|
242
|
+
dayOfMonth++;
|
|
243
|
+
const date = new Date(year, month - 1, dayOfMonth);
|
|
244
|
+
if (date.getDay() === weekday) i++;
|
|
245
|
+
}
|
|
246
|
+
return new Date(year, month - 1, dayOfMonth, hour);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Get the date which is the last occurence of a given weekday in a given month and year.
|
|
251
|
+
*
|
|
252
|
+
* @param year The year for which to find the date
|
|
253
|
+
* @param month The month in which the date occurs
|
|
254
|
+
* @param weekday The weekday on which the date occurs
|
|
255
|
+
* @param hour The hour of day which should be set on the returned date
|
|
256
|
+
* @return The date which is the last occurence of a given weekday in a given
|
|
257
|
+
* month and year, at the given hour of day
|
|
258
|
+
*/
|
|
259
|
+
export function getLastWeekdayOfMonth(year: number, month: Month, weekday: Weekday, hour = 0): Date {
|
|
260
|
+
// Procedure: Find the first weekday of the next month, compare with the given weekday,
|
|
261
|
+
// and use the difference to determine how many days to subtract from the first of the next month.
|
|
262
|
+
const oneIndexedWeekday = weekday === 0 ? 7 : weekday;
|
|
263
|
+
const date = new Date(year, month - 1 + 1, 1, 12);
|
|
264
|
+
const firstWeekdayNextMonth = date.getDay() === 0 ? 7 : date.getDay();
|
|
265
|
+
let dayDiff;
|
|
266
|
+
if (firstWeekdayNextMonth === oneIndexedWeekday) dayDiff = 7;
|
|
267
|
+
else if (firstWeekdayNextMonth < oneIndexedWeekday) dayDiff = 7 + firstWeekdayNextMonth - oneIndexedWeekday;
|
|
268
|
+
else dayDiff = firstWeekdayNextMonth - oneIndexedWeekday;
|
|
269
|
+
date.setDate(date.getDate() - dayDiff);
|
|
270
|
+
return new Date(year, month - 1, date.getDate(), hour);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* Finds and returns timezone offset. If timezoneInput is numeric, it is returned. Otherwise, look for timezone offsets
|
|
275
|
+
* in the following order: timezoneOverrides -> {@link TIMEZONE_ABBR_MAP}.
|
|
276
|
+
*
|
|
277
|
+
* @param timezoneInput Uppercase timezone abbreviation or numeric offset in minutes
|
|
278
|
+
* @param date The date to use to determine whether to return DST offsets for ambiguous timezones
|
|
279
|
+
* @param timezoneOverrides Overrides for timezones
|
|
280
|
+
* @return timezone offset in minutes
|
|
281
|
+
*/
|
|
282
|
+
export function toTimezoneOffset(
|
|
283
|
+
timezoneInput?: string | number,
|
|
284
|
+
date?: Date,
|
|
285
|
+
timezoneOverrides: TimezoneAbbrMap = {}
|
|
286
|
+
): number | null {
|
|
287
|
+
if (timezoneInput == null) {
|
|
197
288
|
return null;
|
|
198
289
|
}
|
|
199
290
|
|
|
@@ -201,5 +292,31 @@ export function toTimezoneOffset(timezoneInput?: string | number): number | null
|
|
|
201
292
|
return timezoneInput;
|
|
202
293
|
}
|
|
203
294
|
|
|
204
|
-
|
|
295
|
+
const matchedTimezone = timezoneOverrides[timezoneInput] ?? TIMEZONE_ABBR_MAP[timezoneInput];
|
|
296
|
+
if (matchedTimezone == null) {
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
// This means that we have matched an unambiguous timezone
|
|
300
|
+
if (typeof matchedTimezone == "number") {
|
|
301
|
+
return matchedTimezone;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// The matched timezone is an ambiguous timezone, where the offset depends on whether the context (refDate)
|
|
305
|
+
// is during daylight savings or not.
|
|
306
|
+
|
|
307
|
+
// Without refDate as context, there's no way to know if DST or non-DST offset should be used. Return null instead.
|
|
308
|
+
if (date == null) {
|
|
309
|
+
return null;
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Return DST offset if the refDate is during daylight savings
|
|
313
|
+
if (
|
|
314
|
+
dayjs(date).isAfter(matchedTimezone.dstStart(date.getFullYear())) &&
|
|
315
|
+
!dayjs(date).isAfter(matchedTimezone.dstEnd(date.getFullYear()))
|
|
316
|
+
) {
|
|
317
|
+
return matchedTimezone.timezoneOffsetDuringDst;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// refDate is not during DST => return non-DST offset
|
|
321
|
+
return matchedTimezone.timezoneOffsetNonDst;
|
|
205
322
|
}
|