2024-02-22 15:36:14 +01:00
|
|
|
import { locale } from '$lib/stores/preferences.store';
|
2023-07-12 05:12:19 +03:00
|
|
|
import { DateTime, Interval } from 'luxon';
|
2024-02-22 15:36:14 +01:00
|
|
|
import { get } from 'svelte/store';
|
2023-07-12 05:12:19 +03:00
|
|
|
|
2024-02-22 15:36:14 +01:00
|
|
|
export const fromLocalDateTime = (localDateTime: string) =>
|
|
|
|
|
DateTime.fromISO(localDateTime, { zone: 'UTC', locale: get(locale) });
|
2023-10-06 08:12:09 -04:00
|
|
|
|
2023-07-12 05:12:19 +03:00
|
|
|
export const groupDateFormat: Intl.DateTimeFormatOptions = {
|
|
|
|
|
weekday: 'short',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
year: 'numeric',
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function formatGroupTitle(date: DateTime): string {
|
|
|
|
|
const today = DateTime.now().startOf('day');
|
|
|
|
|
|
|
|
|
|
// Today
|
|
|
|
|
if (today.hasSame(date, 'day')) {
|
|
|
|
|
return 'Today';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Yesterday
|
|
|
|
|
if (Interval.fromDateTimes(date, today).length('days') == 1) {
|
|
|
|
|
return 'Yesterday';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Last week
|
|
|
|
|
if (Interval.fromDateTimes(date, today).length('weeks') < 1) {
|
|
|
|
|
return date.toLocaleString({ weekday: 'long' });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// This year
|
|
|
|
|
if (today.hasSame(date, 'year')) {
|
|
|
|
|
return date.toLocaleString({
|
|
|
|
|
weekday: 'short',
|
|
|
|
|
month: 'short',
|
|
|
|
|
day: 'numeric',
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return date.toLocaleString(groupDateFormat);
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-17 11:00:55 -06:00
|
|
|
export type LayoutBox = {
|
|
|
|
|
top: number;
|
|
|
|
|
left: number;
|
|
|
|
|
width: number;
|
2024-03-03 17:12:52 -05:00
|
|
|
height: number;
|
2024-02-17 11:00:55 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export function calculateWidth(boxes: LayoutBox[]): number {
|
|
|
|
|
let width = 0;
|
|
|
|
|
for (const box of boxes) {
|
|
|
|
|
if (box.top < 100) {
|
|
|
|
|
width = box.left + box.width;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return width;
|
|
|
|
|
}
|