Skip to content

Commit

Permalink
fix(rules): update week date extraction for watchtower
Browse files Browse the repository at this point in the history
  • Loading branch information
rhahao committed Aug 8, 2024
1 parent aafe90f commit 42a5ad4
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 32 additions & 17 deletions src/common/parsing_rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,14 @@ export const extractWTStudyDate = (src: string, lang: string) => {
const monthNames = getMonthNames(lang);

for (const splitted of split) {
const results = <{ month: number; index: number }[]>[];

for (const month of monthNames) {
const obj = {
month: month.index,
index: -1,
};

const monthLang = month.name.toLowerCase();
let searchKey = `(${monthLang})`;

Expand All @@ -153,29 +160,37 @@ export const extractWTStudyDate = (src: string, lang: string) => {
const array2 = regex.exec(splitted);

if (Array.isArray(array2)) {
if (array2.index < 29) {
const regex = /\d+/g;
const match = textSearch.match(regex);
obj.index = array2.index;
}

if (lang === 'J') {
varDay = +match![2];
}
results.push(obj);
}

if (lang !== 'J') {
varDay = +match![0];
}
const monthsParsed = results.filter((item) => item.index !== -1).sort((a, b) => a.index - b.index);

monthIndex = month.index;
if (monthsParsed.length > 0) {
const firstMonth = monthsParsed.at(0);

const findYear = /\b\d{4}\b/;
const array3 = findYear.exec(dateValue);
if (array3 !== null) {
varYear = +array3[0];
}
const regex = /\d+/g;
const match = textSearch.match(regex);

break outerLoop;
}
if (lang === 'J') {
varDay = +match![2];
}

if (lang !== 'J') {
varDay = +match![0];
}

monthIndex = firstMonth?.month;

const findYear = /\b\d{4}\b/;
const array3 = findYear.exec(dateValue);
if (array3 !== null) {
varYear = +array3[0];
}

break outerLoop;
}
}
}
Expand Down

0 comments on commit 42a5ad4

Please sign in to comment.