Skip to content

Commit

Permalink
Fixed "until %day_of_week%" case
Browse files Browse the repository at this point in the history
  • Loading branch information
alordash committed Jan 15, 2021
1 parent 97ab2f8 commit 138185c
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions lib/date-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,14 @@ const numberAndWordParseCases = [
for (const match of matches) {
let indexes = markIndexes.call(this, match.index, match[0].length, true, false);
let context = processContexts(contextsData, indexes);
parsedTimes.push(new ParsedTime(DateTypes.target, TimeTypes.dates, 1, indexes, context, prevalence, { validMode: ValidModes.notValid }));
let value = this.expressions[match.index].value;;
if(value == 0) {
value = 1;
} else {
const now = new Date();
value = now.getDate() + GetDaysToDayOfWeek(value);
}
parsedTimes.push(new ParsedTime(DateTypes.target, TimeTypes.dates, value, indexes, context, prevalence, { validMode: ValidModes.notValid }));
}
return parsedTimes;
}),
Expand Down Expand Up @@ -621,6 +628,15 @@ function processHour(hour, partOfDay) {
}
}

function GetDaysToDayOfWeek(dayOfWeek) {
let now = new Date();
let dif = dayOfWeek - (now.getDay() + 1);
if (dif < 0) {
dif += 7;
}
return dif;
}

const parseCases = [
//Searchs for DD.MM().Y-YYYY) cases
new ParseCase(75, function (parsedTimes, contextsData, prevalence) {
Expand Down Expand Up @@ -685,16 +701,13 @@ const parseCases = [
const length = match[0].length;
let value = this.expressions[match.index + length - 1].value;
if (value != 0) {
let now = new Date();
let dif = value - (now.getDay() + 1);
if (dif < 0) {
dif += 7;
}
let dif = GetDaysToDayOfWeek(value);
if (match[0][0] == 'F' && dif == 0) {
dif += 7;
}
let indexes = markIndexes.call(this, match.index, length, true, true);
let context = processContexts(contextsData, indexes);
const now = new Date();
parsedTimes.push(new ParsedTime(DateTypes.target, TimeTypes.dates, now.getDate() + dif, indexes, context, prevalence, { validMode: ValidModes.certified }));
}
}
Expand Down

0 comments on commit 138185c

Please sign in to comment.