Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/calendar-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@
}: {
event: CalendarEvent;
sourceEvent: MouseEvent | KeyboardEvent;
}): any;

Check warning on line 49 in src/calendar-utils.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
}

export interface CalendarEvent<MetaType = any> {

Check warning on line 52 in src/calendar-utils.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
id?: string | number;
start: Date;
end?: Date;
Expand Down Expand Up @@ -85,7 +85,7 @@
hourColumns: WeekViewHourColumn[];
}

export interface MonthViewDay<MetaType = any> extends WeekDay {

Check warning on line 88 in src/calendar-utils.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
inMonth: boolean;
events: CalendarEvent[];
backgroundColor?: string;
Expand Down Expand Up @@ -158,7 +158,13 @@
return 0;
}
const { addSeconds, getDay, addDays } = dateAdapter;
const endDate: Date = addSeconds(startDate, seconds - 1);
let endDate = addSeconds(startDate, seconds - 1);
if (precision === 'days') {
// otherwise when changing to DST hour may shift before the hour of the start date
const daysDiff = Math.round(seconds / SECONDS_IN_DAY);
endDate = addSeconds(addDays(startDate, daysDiff), -1);
}

const dayStart: number = getDay(startDate);
const dayEnd: number = getDay(endDate);
let result = 0; // Calculated in seconds
Expand Down Expand Up @@ -232,13 +238,8 @@
totalDaysInView: number;
}
): number {
const {
max,
differenceInSeconds,
addDays,
endOfDay,
differenceInDays,
} = dateAdapter;
const { max, differenceInSeconds, addDays, endOfDay, differenceInDays } =
dateAdapter;
let span: number = SECONDS_IN_DAY;
const begin: Date = max([event.start, startOfWeekDate]);

Expand Down Expand Up @@ -1175,7 +1176,7 @@

export function validateEvents(
events: CalendarEvent[],
log: (...args: any[]) => void

Check warning on line 1179 in src/calendar-utils.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected any. Specify a different type
): boolean {
let isValid = true;

Expand Down
48 changes: 46 additions & 2 deletions test/calendar-utils-dst.spec.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import './util/use-london-timezone';
import { getWeekView } from '../src/calendar-utils';
import { DEFAULT_TIMEZONE } from './util/use-london-timezone';
import { getWeekView, getAllDayWeekEvents } from '../src/calendar-utils';
import { adapterFactory as dateFnsAdapterFactory } from '../src/date-adapters/date-fns';
import { adapterFactory as momentAdapterFactory } from '../src/date-adapters/moment';
import { adapterFactory as luxonAdapterFactory } from '../src/date-adapters/luxon';
import { startOfDay } from 'date-fns';
import { startOfDay, setHours, setMinutes } from 'date-fns';
import { register } from 'timezone-mock';
import * as moment from 'moment';
import * as luxon from 'luxon';

Expand Down Expand Up @@ -71,3 +73,45 @@ describe('getTimezoneOffset', () => {
expect(luxonOffset).toBe(-60);
});
});

describe('getAllDayWeekEvents', () => {
beforeEach(() => {
// Mock Date/date-fns (uses native Date)
register('US/Eastern'); // Toronto uses Eastern timezone
});

afterEach(() => {
register(DEFAULT_TIMEZONE); // Restore default timezone for other tests
});

it('should correctly position an all-day event spanning from Friday before the DST change to the next Friday (Toronto) with excluded days [0, 6]', () => {
// View: March 3–15, 2026 so we see both Fridays (DST springs forward in Toronto on March 9)
const viewStart = new Date('2026-03-03');
const viewEnd = new Date('2026-03-15');

// Event spans Fri Mar 7 (before DST) – Fri Mar 14 (after DST), crossing the timezone change weekend
const event = {
title: 'Week spanning DST',
start: setMinutes(setHours(new Date('2026-03-07'), 8), 0),
end: setMinutes(setHours(new Date('2026-03-14'), 8), 0),
allDay: true,
};

const result = getAllDayWeekEvents(dateAdapter, {
viewStart,
viewEnd,
excluded: [0, 6], // Exclude Sunday and Saturday
events: [event],
});

expect(result).toHaveLength(1);
expect(result[0].row).toHaveLength(1);
// With excluded [0, 6], visible days are Mon 3, Tue 4, Wed 5, Thu 6, Fri 7, Mon 10, Tue 11, Wed 12, Thu 13, Fri 14
// Event spans Fri 7 → Fri 14 → offset 4 (Fri 7), span 6 (Fri 7, Mon 10, Tue 11, Wed 12, Thu 13, Fri 14)
expect(result[0].row[0].offset).toBe(4);
expect(result[0].row[0].span).toBe(6);
expect(result[0].row[0].startsBeforeWeek).toBe(false);
expect(result[0].row[0].endsAfterWeek).toBe(false);
expect(result[0].row[0].event).toEqual(event);
});
});
3 changes: 2 additions & 1 deletion test/util/use-london-timezone.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { register } from 'timezone-mock';

register('Europe/London');
export const DEFAULT_TIMEZONE = 'Europe/London';
register(DEFAULT_TIMEZONE);
Loading