mirror of https://github.com/Squidex/squidex.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
877 B
39 lines
877 B
/*
|
|
* Squidex Headless CMS
|
|
*
|
|
* @license
|
|
* Copyright (c) Squidex UG (haftungsbeschränkt). All rights reserved.
|
|
*/
|
|
|
|
import { enUS, it, nl, zhCN } from 'date-fns/locale';
|
|
|
|
export module DateHelper {
|
|
let locale: string | null;
|
|
|
|
export const FNSLOCALES = {
|
|
en: enUS,
|
|
it,
|
|
nl,
|
|
zh: zhCN,
|
|
};
|
|
|
|
export function setlocale(code: string | null) {
|
|
locale = code;
|
|
}
|
|
|
|
export function getLocale() {
|
|
return locale || 'en';
|
|
}
|
|
|
|
export function getUTCDate(date: Date) {
|
|
return new Date(date.getTime() + date.getTimezoneOffset() * 60 * 1000);
|
|
}
|
|
|
|
export function getLocalDate(date: Date) {
|
|
return new Date(date.getTime() - date.getTimezoneOffset() * 60 * 1000);
|
|
}
|
|
|
|
export function getFnsLocale(): Locale {
|
|
return DateHelper.FNSLOCALES[DateHelper.getLocale()] || enUS;
|
|
}
|
|
}
|
|
|