UNPKG

@redocly/theme

Version:

Shared UI components lib

34 lines (32 loc) 1.1 kB
/** * Formats a date string to localized short date format (e.g., "Dec 12, 2025") * @param dateString - ISO date string or null * @param locale - Locale string (e.g., "en-US") * @returns Formatted date string or empty string if dateString is null */ export function toLocalizedShortDate(dateString: string | null, locale: string): string { if (!dateString) return ''; const date = new Date(dateString); return date.toLocaleDateString(locale, { month: 'short', day: 'numeric', year: 'numeric', }); } /** * Formats a date string to localized short date-time format (e.g., "Dec 12, 3:45 PM") * @param dateString - ISO date string or null * @param locale - Locale string (e.g., "en-US") * @returns Formatted date-time string or empty string if dateString is null */ export function toLocalizedShortDateTime(dateString: string | null, locale: string): string { if (!dateString) return ''; const date = new Date(dateString); return date.toLocaleString(locale, { month: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit', hour12: true, }); }