mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
fix jumping into march 01 from january 29
This commit is contained in:
@@ -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),
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user