| import { siteConfig } from "../config";
|
|
|
| export function formatDateToYYYYMMDD(date: Date): string {
|
| return date.toISOString().substring(0, 10);
|
| }
|
|
|
|
|
| export function formatDateI18n(
|
| dateInput: Date | string,
|
| includeTime?: boolean,
|
| ): string {
|
| const date = typeof dateInput === "string" ? new Date(dateInput) : dateInput;
|
| const lang = siteConfig.lang || "en";
|
|
|
|
|
| const options: Intl.DateTimeFormatOptions = {
|
| year: "numeric",
|
| month: "long",
|
| day: "numeric",
|
| };
|
|
|
| if (includeTime) {
|
| options.hour = "2-digit";
|
| options.minute = "2-digit";
|
| options.second = "2-digit";
|
| }
|
|
|
|
|
| if (siteConfig.timezone) {
|
| (options as Intl.DateTimeFormatOptions).timeZone = siteConfig.timezone;
|
| }
|
|
|
|
|
| const localeMap: Record<string, string> = {
|
| zh_CN: "zh-CN",
|
| zh_TW: "zh-TW",
|
| en: "en-US",
|
| ja: "ja-JP",
|
| ko: "ko-KR",
|
| es: "es-ES",
|
| th: "th-TH",
|
| vi: "vi-VN",
|
| tr: "tr-TR",
|
| id: "id-ID",
|
| fr: "fr-FR",
|
| de: "de-DE",
|
| ru: "ru-RU",
|
| ar: "ar-SA",
|
| };
|
|
|
| const locale = localeMap[lang] || "en-US";
|
| return includeTime
|
| ? date.toLocaleString(locale, options)
|
| : date.toLocaleDateString(locale, options);
|
| }
|
|
|
|
|
| export function formatDateI18nWithTime(dateInput: Date | string): string {
|
| return formatDateI18n(dateInput, true);
|
| }
|
|
|