-
Notifications
You must be signed in to change notification settings - Fork 342
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[New] FR month name little endian parsing
- Loading branch information
Showing
13 changed files
with
522 additions
and
125 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
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
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 |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { ParsingContext } from "../../../chrono"; | ||
import { ParsingResult } from "../../../results"; | ||
import { findYearClosestToRef } from "../../../calculation/years"; | ||
import { MONTH_DICTIONARY } from "../constants"; | ||
import { YEAR_PATTERN, parseYear } from "../constants"; | ||
import { ORDINAL_NUMBER_PATTERN, parseOrdinalNumberPattern } from "../constants"; | ||
import { matchAnyPattern } from "../../../utils/pattern"; | ||
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary"; | ||
|
||
const PATTERN = new RegExp( | ||
"(?:on\\s*?)?" + | ||
`(${ORDINAL_NUMBER_PATTERN})` + | ||
`(?:\\s*(?:au|\\-|\\–|jusqu\'au?|\\s)\\s*(${ORDINAL_NUMBER_PATTERN}))?` + | ||
`(?:-|/|\\s*(?:de)?\\s*)` + | ||
`(${matchAnyPattern(MONTH_DICTIONARY)})` + | ||
`(?:(?:-|/|,?\\s*)(${YEAR_PATTERN}(?![^\\s]\\d)))?` + | ||
`(?=\\W|$)`, | ||
"i" | ||
); | ||
|
||
const DATE_GROUP = 1; | ||
const DATE_TO_GROUP = 2; | ||
const MONTH_NAME_GROUP = 3; | ||
const YEAR_GROUP = 4; | ||
|
||
export default class FRMonthNameLittleEndianParser extends AbstractParserWithWordBoundaryChecking { | ||
innerPattern(): RegExp { | ||
return PATTERN; | ||
} | ||
|
||
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingResult { | ||
//console.log(match) | ||
|
||
const result = context.createParsingResult(match.index, match[0]); | ||
|
||
const month = MONTH_DICTIONARY[match[MONTH_NAME_GROUP].toLowerCase()]; | ||
const day = parseOrdinalNumberPattern(match[DATE_GROUP]); | ||
if (day > 31) { | ||
// e.g. "[96 Aug]" => "9[6 Aug]", we need to shift away from the next number | ||
match.index = match.index + match[DATE_GROUP].length; | ||
return null; | ||
} | ||
|
||
result.start.assign("month", month); | ||
result.start.assign("day", day); | ||
|
||
if (match[YEAR_GROUP]) { | ||
const yearNumber = parseYear(match[YEAR_GROUP]); | ||
result.start.assign("year", yearNumber); | ||
} else { | ||
const year = findYearClosestToRef(context.refDate, day, month); | ||
result.start.imply("year", year); | ||
} | ||
|
||
if (match[DATE_TO_GROUP]) { | ||
const endDate = parseOrdinalNumberPattern(match[DATE_TO_GROUP]); | ||
|
||
result.end = result.start.clone(); | ||
result.end.assign("day", endDate); | ||
} | ||
|
||
return result; | ||
} | ||
} |
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
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
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
Oops, something went wrong.