Skip to content

Commit

Permalink
Changes theDayBeforeYesterday and theDayAfterTomorrow casual referenc…
Browse files Browse the repository at this point in the history
…es to theDayBefore and theDayAfter
  • Loading branch information
Mikhail Mikhailov committed Jun 28, 2022
1 parent bdcecb6 commit 824f832
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 22 deletions.
27 changes: 7 additions & 20 deletions src/common/casualReferences.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ParsingComponents, ReferenceWithTimezone } from "../results";
import dayjs from "dayjs";
import { assignSimilarDate, assignSimilarTime, assignTheNextDay, implySimilarTime } from "../utils/dayjs";
import { assignSimilarDate, assignSimilarTime, implySimilarTime } from "../utils/dayjs";
import { Meridiem } from "../index";

export function now(reference: ReferenceWithTimezone): ParsingComponents {
Expand All @@ -26,37 +26,24 @@ export function today(reference: ReferenceWithTimezone): ParsingComponents {
* The previous day. Imply the same time.
*/
export function yesterday(reference: ReferenceWithTimezone): ParsingComponents {
let targetDate = dayjs(reference.instant);
const component = new ParsingComponents(reference, {});
targetDate = targetDate.add(-1, "day");
assignSimilarDate(component, targetDate);
implySimilarTime(component, targetDate);
return component;
return theDayBefore(reference, 1);
}

export function theDayBeforeYesterday(reference: ReferenceWithTimezone): ParsingComponents {
let targetDate = dayjs(reference.instant);
const component = new ParsingComponents(reference, {});
targetDate = targetDate.add(-2, "day");
assignSimilarDate(component, targetDate);
implySimilarTime(component, targetDate);
return component;
export function theDayBefore(reference: ReferenceWithTimezone, numDay: number): ParsingComponents {
return theDayAfter(reference, -numDay);
}

/**
* The following day with dayjs.assignTheNextDay()
*/
export function tomorrow(reference: ReferenceWithTimezone): ParsingComponents {
const targetDate = dayjs(reference.instant);
const component = new ParsingComponents(reference, {});
assignTheNextDay(component, targetDate);
return component;
return theDayAfter(reference, 1);
}

export function theDayAfterTomorrow(reference: ReferenceWithTimezone): ParsingComponents {
export function theDayAfter(reference: ReferenceWithTimezone, nDays: number): ParsingComponents {
let targetDate = dayjs(reference.instant);
const component = new ParsingComponents(reference, {});
targetDate = targetDate.add(2, "day");
targetDate = targetDate.add(nDays, "day");
assignSimilarDate(component, targetDate);
implySimilarTime(component, targetDate);
return component;
Expand Down
4 changes: 2 additions & 2 deletions src/locales/ru/parsers/RUCasualDateParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export default class RUCasualDateParser extends AbstractParserWithWordBoundaryCh
return references.tomorrow(context.reference);

case "послезавтра":
return references.theDayAfterTomorrow(context.reference);
return references.theDayAfter(context.reference, 2);

case "позавчера":
return references.theDayBeforeYesterday(context.reference);
return references.theDayBefore(context.reference, 2);
}

return component;
Expand Down

0 comments on commit 824f832

Please sign in to comment.