@redocly/theme
Version:
Shared UI components lib
39 lines • 1.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.toLocalizedShortDate = toLocalizedShortDate;
exports.toLocalizedShortDateTime = toLocalizedShortDateTime;
/**
* 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
*/
function toLocalizedShortDate(dateString, locale) {
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
*/
function toLocalizedShortDateTime(dateString, locale) {
if (!dateString)
return '';
const date = new Date(dateString);
return date.toLocaleString(locale, {
month: 'short',
day: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true,
});
}
//# sourceMappingURL=date.js.map