String Locale::formatDateTime(const DateComponents& date, FormatType formatType) { if (date.getType() == DateComponents::Invalid) return String(); DateTimeStringBuilder builder(*this, date); switch (date.getType()) { case DateComponents::Time: builder.build(formatType == FormatTypeShort ? shortTimeFormat() : timeFormat()); break; case DateComponents::Date: builder.build(dateFormat()); break; case DateComponents::Month: builder.build(formatType == FormatTypeShort ? shortMonthFormat() : monthFormat()); break; case DateComponents::Week: builder.build(weekFormatInLDML()); break; case DateComponents::DateTime: case DateComponents::DateTimeLocal: builder.build(formatType == FormatTypeShort ? dateTimeFormatWithoutSeconds() : dateTimeFormatWithSeconds()); break; case DateComponents::Invalid: ASSERT_NOT_REACHED(); break; } return builder.toString(); }
static String valueToDateTimeString(double value, AtomicString type) { DateComponents components; if (type == InputTypeNames::date) components.setMillisecondsSinceEpochForDate(value); else if (type == InputTypeNames::datetime_local) components.setMillisecondsSinceEpochForDateTimeLocal(value); else if (type == InputTypeNames::month) components.setMonthsSinceEpoch(value); else if (type == InputTypeNames::time) components.setMillisecondsSinceMidnight(value); else if (type == InputTypeNames::week) components.setMillisecondsSinceEpochForWeek(value); else NOTREACHED(); return components.getType() == DateComponents::Invalid ? String() : components.toString(); }