2022-09-16 23:17:45 +00:00
|
|
|
import { getCanonicalLocale } from "@nextcloud/l10n";
|
|
|
|
|
2022-09-12 19:15:28 +00:00
|
|
|
/** Get JS date object from dayId */
|
2022-09-13 01:33:24 +00:00
|
|
|
export function dayIdToDate(dayId: number){
|
|
|
|
return new Date(dayId*86400*1000);
|
2022-09-12 19:15:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/** Get month name from number */
|
2022-09-16 23:17:45 +00:00
|
|
|
export function getShortDateStr(date: Date) {
|
|
|
|
return date.toLocaleDateString(getCanonicalLocale(), {
|
2022-09-12 19:15:28 +00:00
|
|
|
month: 'short',
|
2022-09-16 23:17:45 +00:00
|
|
|
year: 'numeric',
|
|
|
|
timeZone: 'UTC',
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Get long date string with optional year if same as current */
|
|
|
|
export function getLongDateStr(date: Date, skipYear=false) {
|
|
|
|
return date.toLocaleDateString(getCanonicalLocale(), {
|
|
|
|
weekday: 'long',
|
|
|
|
month: 'long',
|
|
|
|
day: 'numeric',
|
|
|
|
year: (skipYear && date.getUTCFullYear() === new Date().getUTCFullYear()) ? undefined : 'numeric',
|
2022-09-12 19:15:28 +00:00
|
|
|
timeZone: 'UTC',
|
|
|
|
});
|
|
|
|
}
|