All months have 30 days.
jintori opened this issue · comments
I use 4.0.9-beta / react.
option
from: moment("2021-01-01", "YYYY-MM-DD"),
to: moment("2023-12-31", "YYYY-MM-DD"),
columnUnit: "day",
columnOffset: 1,
headers: [
{ unit: "month", format: "MM", offset: 1, sticky: true },
{ unit: "day", format: "DD", offset: 1, sticky: true }
],
...
How can i fix it?
Thanks in advance.
Maybe the same thing: #123
Looks like the grouping render is not taking logical start and ends of periods to make its blocks.
I think this is correct. Below code returns the start of the year (for example).
If your startdate is after that the first column will still start at the first of that year.
export function startOf(date: number, unit: string): number {
let d = new Date(date);
let y = d.getFullYear();
let m = d.getMonth();
let dt = d.getDate();
switch (unit) {
case 'y':
case 'year':
return startOfDate(y, 0, 1);
}
}
function startOfDate(y: number, m: number, d: number, week=false) {
if (y < 100 && y >= 0) {
return new Date(y + 400, m, d).valueOf() - 31536000000;
} else if (week){
return getFirstDayOfWeek(new Date(y,m,d).valueOf()).valueOf();
} else {
return new Date(y, m, d).valueOf();
}
}
However I think there is another problem with column width if units are 'week', 'month', 'year'. The problem is that getDuration
returns incorrect durations for these units. For headers with unit = 'week' this was somewhat fixed with #48 but columnWidth
is was not part of the fix and can still be wrong. Even 'days' can be wrong depending on timezone as stated in #113.
@ANovokmet @V-Py I propose to change the 'getDuration' function for units > 'hour' to also take the end date of the preceding column and calculate the duration until full unit / next column to fix these issues alltogether. Each header column row is passed the width for one minute (or other static) and could then calculate the width, duration etc. for each of its columns depending on multiples of that. If the width is smaller than can be displayed that row should show an error.