diff --git a/src/run.js b/src/run.js index 778ad72..92689c9 100644 --- a/src/run.js +++ b/src/run.js @@ -85,8 +85,8 @@ function getTimeForLocation(text, location) { */ function getDatesForLocation(text, location) { const regexpDatesString = new RegExp( - `${location}.*
((\\d+.\\d+).*)

`, - "i" + `${location}.*
((\\d+. [a-z– ]+).*)

`, + "gmi" ); let datesStringMatches = text.match(regexpDatesString); @@ -97,7 +97,7 @@ function getDatesForLocation(text, location) { // TODO make regex stop at first capture const datesString = datesStringMatches?.[0]?.split("

")?.[0]; - const regexpDates = /(\d+\.\d+)+/g; + const regexpDates = /(\d+. [a-z]+)+/g; const dates = String(datesString)?.match(regexpDates); if (dates == null || dates?.length === 0) diff --git a/src/utils.js b/src/utils.js index 8ed1712..dfb0d4d 100644 --- a/src/utils.js +++ b/src/utils.js @@ -8,6 +8,20 @@ These are the available arguments: print Prints results help Prints this message`; +const monthStrings = [ + "jan", + "feb", + "mars", + "apr", + "mai", + "juni", + "juli", + "sept", + "okt", + "nov", + "des", +]; + /** * Converts string DD.MM to JS date object. * @param {string} dateString @@ -15,15 +29,16 @@ These are the available arguments: */ function websiteDateToTime(dateString) { const date = new Date(); - const dayAndMonthString = dateString?.match(/(\d+).(\d+)/); + const dayAndMonthString = dateString?.match(/(\d+)(. )([a-z]+)/); - if (dayAndMonthString == null || dayAndMonthString.length < 3) + if (dayAndMonthString == null || dayAndMonthString.length < 4) throw new Error("Unable to created string from unparsable date."); const day = Number(dayAndMonthString[1]); - const month = Number(dayAndMonthString[2]); + const monthIndex = monthStrings.findIndex(m => m === dayAndMonthString[3]) + const month = Number(monthIndex); - date.setMonth(Number(month - 1)); + date.setMonth(Number(month)); date.setDate(Number(day)); return date; @@ -58,11 +73,11 @@ function timeToWebsiteDate(date) { */ function validateArguments(place, lookAhead) { const placeUndefined = place === undefined; - const help = (place === "-h" || place === "--help") - const numberIsNotNumber = isNaN(Number(lookAhead)) - const validation = [placeUndefined, help, numberIsNotNumber] + const help = place === "-h" || place === "--help"; + const numberIsNotNumber = isNaN(Number(lookAhead)); + const validation = [placeUndefined, help, numberIsNotNumber]; - if (!validation.every(v => v === false)) { + if (!validation.every((v) => v === false)) { console.log(HELP_TEXT); process.exit(0); }