Skip to content

Commit

Permalink
Added odd/even cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alordash committed Aug 22, 2021
1 parent 397c98f commit 08b5f31
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion lib/date-cases/parse-cases/common-parse-cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ const {
checkMonth,
checkYear,
processHour,
GetDaysToDayOfWeek
GetDaysToDayOfWeek,
getDateProperty
} = require('../parse-cases-processing');

const parseCases = [
Expand Down Expand Up @@ -335,6 +336,51 @@ const parseCases = [
parsedTimes.push(new ParsedTime(DateTypes.target, TimeTypes.months, now.getUTCMonth() + 1, indexes, context, prevalence, { validMode: ValidModes.certified }));
}
return parsedTimes;
}),
//Searchs for odd/even %timeType% cases
new ParseCase(60, function (parsedTimes, contextsData, prevalence) {
let matches = [...this.regchars.matchAll(/E{0,1}U[smhdOKy]/g)];
for (const match of matches) {
let i = this.expressions[match.index].regex_char == 'E' ? 1 : 0;
let even = (this.expressions[match.index + i].value & 1) == 0;
let indexes = markIndexes.call(this, match.index, 2 + i, true, true);
let context = processContexts(contextsData, indexes);
let next = this.expressions[match.index + i + 1];
let timeType;
switch (next.regex_char) {
case 's':
timeType = TimeTypes.seconds;
break;
case 'm':
timeType = TimeTypes.minutes;
break;
case 'h':
timeType = TimeTypes.hours;
break;
case 'd':
timeType = TimeTypes.dates;
break;
case 'O':
timeType = TimeTypes.dates;
break;
case 'K':
timeType = TimeTypes.months;
break;
case 'y':
timeType = TimeTypes.years;
break;
default:
break;
}
const now = new Date();
let time = getDateProperty(now, timeType, '1') + 1;
if (even != ((time & 1) == 0)) {
time++;
}
parsedTimes.push(new ParsedTime(DateTypes.target, timeType, time, indexes, context, prevalence, { validMode: ValidModes.certified }));
parsedTimes.push(new ParsedTime(DateTypes.period, timeType, 2, indexes, context, prevalence, { validMode: ValidModes.certified }));
}
return parsedTimes;
})
];

Expand Down

0 comments on commit 08b5f31

Please sign in to comment.