UNPKG

@awsui/components-react

Version:

On July 19th, 2022, we launched [Cloudscape Design System](https://cloudscape.design). Cloudscape is an evolution of AWS-UI. It consists of user interface guidelines, front-end components, design resources, and development tools for building intuitive, en

56 lines 1.85 kB
export function setDayIndex(date, dayIndex) { const diff = dayIndex - date.getDay(); date.setDate(date.getDate() + diff); } export function renderDayName(locale, dayIndex, mode) { const tempDate = new Date(); setDayIndex(tempDate, dayIndex); return tempDate.toLocaleDateString(locale, { weekday: mode }); } export function renderMonthAndYear(locale, baseDate) { const result = baseDate.toLocaleDateString(locale, { year: 'numeric', month: 'long', }); return result; } export function renderYear(locale, date) { return date.toLocaleDateString(locale, { year: 'numeric', }); } const dayLabelCache = new Map(); export function getDateLabel(locale, date, mode = 'full') { const cacheKey = locale + date.getTime() + mode; const cachedValue = dayLabelCache.get(cacheKey); if (cachedValue) { return cachedValue; } const value = date.toLocaleDateString(locale, { weekday: mode === 'full' ? 'long' : undefined, month: 'long', day: 'numeric', year: 'numeric', }); dayLabelCache.set(cacheKey, value); return value; } export function renderTimeLabel(locale, date, format) { let options = {}; if (format === 'hh') { options = { hour: '2-digit' }; } if (format === 'hh:mm') { options = { hour: '2-digit', minute: '2-digit' }; } const value = date.toLocaleTimeString(locale, options); return value; } export function renderDateAnnouncement({ date, isCurrent, locale, granularity = 'day', currentLabel, }) { const formattedDate = granularity === 'month' ? renderMonthAndYear(locale, date) : getDateLabel(locale, date, 'short'); if (isCurrent && currentLabel) { return `${formattedDate}. ${currentLabel}`; } return formattedDate; } //# sourceMappingURL=intl.js.map