-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New: ZH new default configuration combining zh_hans and zh_hant
- Loading branch information
Wanasit Tanakitrungruang
committed
Jun 1, 2024
1 parent
57676b0
commit c5261b7
Showing
12 changed files
with
125 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,74 @@ | ||
export * from "./hant"; | ||
import { includeCommonConfiguration } from "../../configurations"; | ||
import { Chrono, Configuration, Parser, Refiner } from "../../chrono"; | ||
import { ParsingResult, ParsingComponents, ReferenceWithTimezone } from "../../results"; | ||
import { Component, ParsedResult, ParsingOption, ParsingReference, Meridiem, Weekday } from "../../types"; | ||
import ExtractTimezoneOffsetRefiner from "../../common/refiners/ExtractTimezoneOffsetRefiner"; | ||
|
||
import ZHHansCasualDateParser from "./hans/parsers/ZHHansCasualDateParser"; | ||
import ZHHansDateParser from "./hans/parsers/ZHHansDateParser"; | ||
import ZHHansDeadlineFormatParser from "./hans/parsers/ZHHansDeadlineFormatParser"; | ||
import ZHHansRelationWeekdayParser from "./hans/parsers/ZHHansRelationWeekdayParser"; | ||
import ZHHansTimeExpressionParser from "./hans/parsers/ZHHansTimeExpressionParser"; | ||
import ZHHansWeekdayParser from "./hans/parsers/ZHHansWeekdayParser"; | ||
|
||
import ZHHantCasualDateParser from "./hant/parsers/ZHHantCasualDateParser"; | ||
import ZHHantDateParser from "./hant/parsers/ZHHantDateParser"; | ||
import ZHHantDeadlineFormatParser from "./hant/parsers/ZHHantDeadlineFormatParser"; | ||
import ZHHantRelationWeekdayParser from "./hant/parsers/ZHHantRelationWeekdayParser"; | ||
import ZHHantTimeExpressionParser from "./hant/parsers/ZHHantTimeExpressionParser"; | ||
import ZHHantWeekdayParser from "./hant/parsers/ZHHantWeekdayParser"; | ||
import ZHHantMergeDateRangeRefiner from "./hant/refiners/ZHHantMergeDateRangeRefiner"; | ||
import ZHHantMergeDateTimeRefiner from "./hant/refiners/ZHHantMergeDateTimeRefiner"; | ||
|
||
export * as hant from "./hant"; | ||
export * as hans from "./hans"; | ||
export { Chrono, Parser, Refiner, ParsingResult, ParsingComponents, ReferenceWithTimezone }; | ||
export { Component, ParsedResult, ParsingOption, ParsingReference, Meridiem, Weekday }; | ||
|
||
export const casual = new Chrono(createCasualConfiguration()); | ||
export const strict = new Chrono(createConfiguration()); | ||
|
||
export function parse(text: string, ref?: ParsingReference | Date, option?: ParsingOption): ParsedResult[] { | ||
return casual.parse(text, ref, option); | ||
} | ||
|
||
export function parseDate(text: string, ref?: ParsingReference | Date, option?: ParsingOption): Date { | ||
return casual.parseDate(text, ref, option); | ||
} | ||
|
||
/** | ||
* @ignore (to be documented later) | ||
*/ | ||
export function createCasualConfiguration(): Configuration { | ||
const option = createConfiguration(); | ||
option.parsers.unshift(new ZHHantCasualDateParser()); | ||
return option; | ||
} | ||
|
||
/** | ||
* @ignore (to be documented later) | ||
*/ | ||
export function createConfiguration(): Configuration { | ||
const configuration = includeCommonConfiguration({ | ||
parsers: [ | ||
new ZHHantDateParser(), | ||
new ZHHansDateParser(), | ||
new ZHHantRelationWeekdayParser(), | ||
new ZHHansRelationWeekdayParser(), | ||
new ZHHantWeekdayParser(), | ||
new ZHHansWeekdayParser(), | ||
new ZHHantTimeExpressionParser(), | ||
new ZHHansTimeExpressionParser(), | ||
new ZHHantDeadlineFormatParser(), | ||
new ZHHansDeadlineFormatParser(), | ||
], | ||
refiners: [new ZHHantMergeDateRangeRefiner(), new ZHHantMergeDateTimeRefiner()], | ||
}); | ||
|
||
// REMOVE ExtractTimezoneOffsetRefiner | ||
configuration.refiners = configuration.refiners.filter( | ||
(refiner) => !(refiner instanceof ExtractTimezoneOffsetRefiner) | ||
); | ||
|
||
return configuration; | ||
} |
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hans_casual.test.ts → test/zh/hans/zh_hans_casual.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hans_date.test.ts → test/zh/hans/zh_hans_date.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hans_deadline.test.ts → test/zh/hans/zh_hans_deadline.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hans_weekday.test.ts → test/zh/hans/zh_hans_weekday.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hant_casual.test.ts → test/zh/hant/zh_hant_casual.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hant_date.test.ts → test/zh/hant/zh_hant_date.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hant_deadline.test.ts → test/zh/hant/zh_hant_deadline.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hant_time_exp.test.ts → test/zh/hant/zh_hant_time_exp.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
test/zh/zh_hant_weekday.test.ts → test/zh/hant/zh_hant_weekday.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters