-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for "morgennamiddag" and others + "volgende week <day>"
- Loading branch information
Showing
6 changed files
with
183 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { ParsingContext } from "../../../chrono"; | ||
import { ParsingComponents, ParsingResult } from "../../../results"; | ||
import { AbstractParserWithWordBoundaryChecking } from "../../../common/parsers/AbstractParserWithWordBoundary"; | ||
import * as references from "../../../common/casualReferences"; | ||
import {Meridiem} from "../../../index"; | ||
import {assignSimilarDate, assignTheNextDay} from "../../../utils/dayjs"; | ||
import dayjs from "dayjs"; | ||
|
||
/* | ||
* Find combined words | ||
* - morgenochtend | ||
* - morgenmiddag | ||
* - morgennamiddag | ||
* - morgenavond | ||
* - morgennacht | ||
* - vanochtend | ||
* - vanmiddag | ||
* - vannamiddag | ||
* - vanavond | ||
* - vannacht | ||
* - gisterenochtend | ||
* - gisterenmiddag | ||
* - gisterennamiddag | ||
* - gisterenavond | ||
* - gisterennacht | ||
* */ | ||
|
||
const DATE_GROUP = 1; | ||
const TIME_OF_DAY_GROUP = 2; | ||
|
||
export default class NLCasualDateTimeParser extends AbstractParserWithWordBoundaryChecking { | ||
innerPattern(context: ParsingContext): RegExp { | ||
return /(gisteren|morgen|van)(ochtend|middag|namiddag|avond|nacht)(?=\W|$)/i; | ||
} | ||
|
||
innerExtract(context: ParsingContext, match: RegExpMatchArray): ParsingComponents | ParsingResult { | ||
const dateText = match[DATE_GROUP].toLowerCase(); | ||
const timeText = match[TIME_OF_DAY_GROUP].toLowerCase(); | ||
const component = context.createParsingComponents(); | ||
const targetDate = dayjs(context.refDate); | ||
|
||
switch (dateText) { | ||
case "gisteren": | ||
assignSimilarDate(component, targetDate.add(-1, "day")); | ||
break; | ||
case "van": | ||
assignSimilarDate(component, targetDate); | ||
break; | ||
case "morgen": | ||
assignTheNextDay(component, targetDate); | ||
break; | ||
} | ||
|
||
switch (timeText) { | ||
case "ochtend": | ||
component.imply("meridiem", Meridiem.AM); | ||
component.imply("hour", 6); | ||
break; | ||
case "middag": | ||
component.imply("meridiem", Meridiem.AM); | ||
component.imply("hour", 12); | ||
break; | ||
case "namiddag": | ||
component.imply("meridiem", Meridiem.PM); | ||
component.imply("hour", 15); | ||
break; | ||
|
||
case "avond": | ||
component.imply("meridiem", Meridiem.PM); | ||
component.imply("hour", 20); | ||
break; | ||
} | ||
|
||
return component; | ||
} | ||
} |
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