Jump to time option in room timeline (#2377)

* add time and date picker components

* add time utils

* add jump to time in room timeline

* fix typo causing crash in safari
This commit is contained in:
Ajay Bura 2025-07-15 18:11:33 +05:30 committed by GitHub
parent c462a3b8d5
commit 50cc78788f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 637 additions and 0 deletions

View file

@ -9,12 +9,26 @@ export const today = (ts: number): boolean => dayjs(ts).isToday();
export const yesterday = (ts: number): boolean => dayjs(ts).isYesterday();
export const timeHour = (ts: number): string => dayjs(ts).format('hh');
export const timeMinute = (ts: number): string => dayjs(ts).format('mm');
export const timeAmPm = (ts: number): string => dayjs(ts).format('A');
export const timeDay = (ts: number): string => dayjs(ts).format('D');
export const timeMon = (ts: number): string => dayjs(ts).format('MMM');
export const timeMonth = (ts: number): string => dayjs(ts).format('MMMM');
export const timeYear = (ts: number): string => dayjs(ts).format('YYYY');
export const timeHourMinute = (ts: number): string => dayjs(ts).format('hh:mm A');
export const timeDayMonYear = (ts: number): string => dayjs(ts).format('D MMM YYYY');
export const timeDayMonthYear = (ts: number): string => dayjs(ts).format('D MMMM YYYY');
export const daysInMonth = (month: number, year: number): number =>
dayjs(`${year}-${month}-1`).daysInMonth();
export const dateFor = (year: number, month: number, day: number): number =>
dayjs(`${year}-${month}-${day}`).valueOf();
export const inSameDay = (ts1: number, ts2: number): boolean => {
const dt1 = new Date(ts1);
const dt2 = new Date(ts2);
@ -33,3 +47,37 @@ export const minuteDifference = (ts1: number, ts2: number): number => {
diff /= 60;
return Math.abs(Math.round(diff));
};
export const hour24to12 = (hour24: number): number => {
const h = hour24 % 12;
if (h === 0) return 12;
return h;
};
export const hour12to24 = (hour: number, pm: boolean): number => {
if (hour === 12) {
return pm ? 12 : 0;
}
return pm ? hour + 12 : hour;
};
export const secondsToMs = (seconds: number) => seconds * 1000;
export const minutesToMs = (minutes: number) => minutes * secondsToMs(60);
export const hoursToMs = (hour: number) => hour * minutesToMs(60);
export const daysToMs = (days: number) => days * hoursToMs(24);
export const getToday = () => {
const nowTs = Date.now();
const date = dayjs(nowTs);
return dateFor(date.year(), date.month() + 1, date.date());
};
export const getYesterday = () => {
const nowTs = Date.now() - daysToMs(1);
const date = dayjs(nowTs);
return dateFor(date.year(), date.month() + 1, date.date());
};