fix jumping into march 01 from january 29

This commit is contained in:
Johann Hoffmann
2025-02-06 13:18:19 +01:00
parent a0ddde4978
commit fc06ffe0e5
2 changed files with 15 additions and 1 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ export default {
this.syncOnNextChange = false;
this.focusDate.set(this.date);
} else {
this.focusDate.m += dir;
this.focusDate.moveMonthInDirection(dir)
}
this.$emit('change:range', {
start: new Date(this.focusDate.y, this.focusDate.m, 1),
+14
View File
@@ -1,6 +1,11 @@
import {user_locale} from "../plugin/Phrasen.js";
import CalendarDates from "./CalendarDates.js";
const monthDayRanges = []
for(let i = 1; i < 13; i++) {
monthDayRanges.push(new Date(1995, i, 0).getDate())
}
class CalendarDate {
constructor(y, m, d) {
this.weekStart = CalendarDate.getWeekStart();
@@ -210,6 +215,15 @@ class CalendarDate {
cleanup(){
if(this.watchLocale && this.watchLocale.stop) this.watchLocale.stop(); // TODO: ?
}
moveMonthInDirection (dir) {
// avoid setting date in wrong month if we try to create a date which does not exist like 30th of february
const newM = this.m + dir
const maxDaysTarget = monthDayRanges[newM]
if (this.d > maxDaysTarget) this.d = maxDaysTarget
this.m = newM // calls _clean which sets a new Date
}
}
/**
* Returns the weekday number (Date.getDay()) on which the week starts depending on the locale.