Newer
Older
import { get } from 'svelte/store';
export function getFullMonth(id: number): string {
switch (id) {
case 0:
default:
return '??';
}
}
export function displayDate(date: Date): string {
if (date === null) return '';
const now = new Date();
const hours = date.getHours().toString();
const minutes = date.getMinutes().toString().padStart(2, '0');
} else if (now.getFullYear() === date.getFullYear()) {
return date.getDate() + ' ' + getFullMonth(date.getMonth()) + ' ' + hours + ':' + minutes;
} else {
return (
date.getDate() +
' ' +
getFullMonth(date.getMonth()) +
' ' +
date.getFullYear() +
' ' +
export function displayTime(date: Date): string {
if (date === null) return '??';
const now = new Date();
const hours = date.getHours().toString();
const minutes = date.getMinutes().toString().padStart(2, '0');
if (
now.getDate() === date.getDate() &&
now.getFullYear() === date.getFullYear() &&
now.getMonth() === date.getMonth()
) {
const day = date.getDate().toString();
if (now.getFullYear() === date.getFullYear()) {
return day + ' ' + month + ' ' + hours + ':' + minutes;
const year = date.getFullYear().toString();
return day + ' ' + month + ' ' + year + ' ' + hours + ':' + minutes;
export function displayDuration(start: Date, end: Date): string | null {
const duration = end.getTime() - start.getTime();
const hours = Math.floor(duration / (1000 * 60 * 60));
const minutes = Math.floor((duration % (1000 * 60 * 60)) / (1000 * 60));
if (hours < 0 || minutes < 0) return null;
if (hours === 0) return minutes + 'm';
else return hours + 'h ' + minutes + 'm';
}
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
export function parseToLocalDate(dateStr: string): Date {
const isDST = isInDST(new Date(dateStr + 'Z'));
const offset = isDST ? '+02:00' : '+01:00';
return new Date(dateStr + offset);
}
function isInDST(date: Date): boolean {
const year = date.getUTCFullYear();
// Calculate the last Sunday in March
const startOfDST = new Date(Date.UTC(year, 2, 31));
const startDay = startOfDST.getUTCDay();
const lastSundayMarch = 31 - startDay;
const startOfDSTDate = new Date(Date.UTC(year, 2, lastSundayMarch, 1));
// Calculate the last Sunday in October
const endOfDST = new Date(Date.UTC(year, 9, 31));
const endDay = endOfDST.getUTCDay();
const lastSundayOctober = 31 - endDay;
const endOfDSTDate = new Date(Date.UTC(year, 9, lastSundayOctober, 1));
return date >= startOfDSTDate && date < endOfDSTDate;
}