Commit fe38cb8a authored by Claudio Cambra's avatar Claudio Cambra
Browse files

Replace construction of date string with just using date numbers to build date with fixed year

On some locales (e.g. `de_AT.UTF-8`) the QML date's `fromLocaleString` method is completely borked

Therefore, rather than use this parsing method, we just create a new date from the numbers we acquire from the user's provided date string
parent dca467e3
Pipeline #199638 failed with stage
in 8 minutes and 59 seconds
......@@ -163,6 +163,8 @@ function parseDateString(dateString) {
const dateStringDelimiter = dateStringDelimiterMatches[0];
const localisedDateFormatSplit = Qt.locale().dateFormat(Locale.NarrowFormat).split(dateStringDelimiter);
const localisedDateDayPosition = localisedDateFormatSplit.findIndex((x) => /d/gi.test(x));
const localisedDateMonthPosition = localisedDateFormatSplit.findIndex((x) => /m/gi.test(x));
const localisedDateYearPosition = localisedDateFormatSplit.findIndex((x) => /y/gi.test(x));
let splitDateString = dateString.split(dateStringDelimiter);
......@@ -183,9 +185,11 @@ function parseDateString(dateString) {
}
fullyWrittenYear = fullyWrittenYear.join("");
let fixedSplitDateString = splitDateString;
fixedSplitDateString[localisedDateYearPosition] = fullyWrittenYear;
const fixedDateString = fixedSplitDateString.join(dateStringDelimiter);
const fixedYearNum = Number(fullyWrittenYear);
const monthIndexNum = Number(splitDateString[localisedDateMonthPosition]) - 1;
const dayNum = Number(splitDateString[localisedDateDayPosition]);
return Date.fromLocaleDateString(Qt.locale(), fixedDateString, Locale.NarrowFormat);
console.log(new Date(fixedYearNum, monthIndexNum, dayNum))
return new Date(fixedYearNum, monthIndexNum, dayNum);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment