Files
calendar/packages/lib/timeShift.ts
Kartik LabhshetwarGitHubcubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
8dc8d87ad0 feat: add time shift badge for recurring events with shifted local times (#25568)
* feat: highlight recurring bookings with time shift badge across DST

* Update packages/lib/__tests__/timeShift.test.ts

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>

* refactor: show time shift badge only on first shift in bookings view and occurrences

* refactor: update recurring bookings display logic and wrap booking title text

* refactor: add getFirstShiftFlags helper for time shift flags and update components

---------

Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
2025-12-11 20:18:00 +00:00

38 lines
1.0 KiB
TypeScript

import dayjs from "@calcom/dayjs";
/**
* Given a list of UTC datetimes and a target timezone, returns a boolean array
* indicating which occurrences have a *different local start time* (HH:mm)
* than the first occurrence in that timezone.
*
* The first occurrence is always `false` (baseline).
*/
export const getTimeShiftFlags = (options: { dates: (string | Date)[]; timezone: string }): boolean[] => {
const { dates, timezone } = options;
if (!dates.length) return [];
const first = dayjs(dates[0]).tz(timezone);
const baseHour = first.hour();
const baseMinute = first.minute();
return dates.map((date, index) => {
if (index === 0) return false;
const d = dayjs(date).tz(timezone);
return d.hour() !== baseHour || d.minute() !== baseMinute;
});
};
export const getFirstShiftFlags = (shiftFlags: boolean[]): boolean[] => {
let hasSeenShift = false;
return shiftFlags.map((flag) => {
if (!flag || hasSeenShift) return false;
hasSeenShift = true;
return true;
});
};
export default getTimeShiftFlags;