String LocaleICU::dateFormat() { if (!m_dateFormat.isNull()) return m_dateFormat; if (!initializeShortDateFormat()) return "yyyy-MM-dd"; m_dateFormat = getDateFormatPattern(m_shortDateFormat); return m_dateFormat; }
String LocaleICU::dateFormat() { if (!m_dateFormat.isNull()) return m_dateFormat; if (!initializeShortDateFormat()) return ASCIILiteral("dd/MM/yyyy"); m_dateFormat = getDateFormatPattern(m_shortDateFormat); return m_dateFormat; }
void LocaleICU::initializeLocalizedDateFormatText() { if (!m_localizedDateFormatText.isNull()) return; m_localizedDateFormatText = emptyString(); if (!initializeShortDateFormat()) return; m_localizedDateFormatText = localizeFormat(getDateFormatPattern(m_shortDateFormat)); }
const Vector<String>& LocaleICU::monthLabels() { if (m_monthLabels) return *m_monthLabels; if (initializeShortDateFormat()) { m_monthLabels = createLabelVector(m_shortDateFormat, UDAT_MONTHS, UCAL_JANUARY, 12); if (m_monthLabels) return *m_monthLabels; } m_monthLabels = createFallbackMonthLabels(); return *m_monthLabels; }
const Vector<String>& LocaleICU::shortStandAloneMonthLabels() { if (!m_shortStandAloneMonthLabels.isEmpty()) return m_shortStandAloneMonthLabels; if (initializeShortDateFormat()) { if (OwnPtr<Vector<String> > labels = createLabelVector(m_shortDateFormat, UDAT_STANDALONE_SHORT_MONTHS, UCAL_JANUARY, 12)) { m_shortStandAloneMonthLabels = *labels; return m_shortStandAloneMonthLabels; } } m_shortStandAloneMonthLabels = shortMonthLabels(); return m_shortStandAloneMonthLabels; }
double ICULocale::parseLocalizedDate(const String& input) { if (!initializeShortDateFormat()) return numeric_limits<double>::quiet_NaN(); if (input.length() > static_cast<unsigned>(numeric_limits<int32_t>::max())) return numeric_limits<double>::quiet_NaN(); int32_t inputLength = static_cast<int32_t>(input.length()); UErrorCode status = U_ZERO_ERROR; int32_t parsePosition = 0; UDate date = udat_parse(m_shortDateFormat, input.characters(), inputLength, &parsePosition, &status); if (parsePosition != inputLength || U_FAILURE(status)) return numeric_limits<double>::quiet_NaN(); // UDate, which is an alias of double, is compatible with our expectation. return date; }
const Vector<String>& LocaleICU::shortMonthLabels() { if (!m_shortMonthLabels.isEmpty()) return m_shortMonthLabels; if (initializeShortDateFormat()) { if (OwnPtr<Vector<String>> labels = createLabelVector(m_shortDateFormat, UDAT_SHORT_MONTHS, UCAL_JANUARY, 12)) { m_shortMonthLabels = *labels; return m_shortMonthLabels; } } m_shortMonthLabels.reserveCapacity(WTF_ARRAY_LENGTH(WTF::monthName)); for (unsigned i = 0; i < WTF_ARRAY_LENGTH(WTF::monthName); ++i) m_shortMonthLabels.append(WTF::monthName[i]); return m_shortMonthLabels; }
String ICULocale::formatLocalizedDate(const DateComponents& dateComponents) { if (!initializeShortDateFormat()) return String(); double input = dateComponents.millisecondsSinceEpoch(); UErrorCode status = U_ZERO_ERROR; int32_t length = udat_format(m_shortDateFormat, input, 0, 0, 0, &status); if (status != U_BUFFER_OVERFLOW_ERROR) return String(); Vector<UChar> buffer(length); status = U_ZERO_ERROR; udat_format(m_shortDateFormat, input, buffer.data(), length, 0, &status); if (U_FAILURE(status)) return String(); return String::adopt(buffer); }
void LocaleICU::initializeCalendar() { if (m_weekDayShortLabels) return; if (!initializeShortDateFormat()) { m_firstDayOfWeek = 0; m_weekDayShortLabels = createFallbackWeekDayShortLabels(); return; } m_firstDayOfWeek = ucal_getAttribute(udat_getCalendar(m_shortDateFormat), UCAL_FIRST_DAY_OF_WEEK) - UCAL_SUNDAY; m_weekDayShortLabels = createLabelVector(m_shortDateFormat, UDAT_SHORT_WEEKDAYS, UCAL_SUNDAY, 7); if (!m_weekDayShortLabels) m_weekDayShortLabels = createFallbackWeekDayShortLabels(); }
void ICULocale::initializeLocalizedDateFormatText() { if (!m_localizedDateFormatText.isNull()) return; m_localizedDateFormatText = String(""); if (!initializeShortDateFormat()) return; UErrorCode status = U_ZERO_ERROR; int32_t length = udat_toPattern(m_shortDateFormat, TRUE, 0, 0, &status); if (status != U_BUFFER_OVERFLOW_ERROR) return; Vector<UChar> buffer(length); status = U_ZERO_ERROR; udat_toPattern(m_shortDateFormat, TRUE, buffer.data(), length, &status); if (U_FAILURE(status)) return; m_localizedDateFormatText = localizeFormat(buffer); }