Decimal TimeInputType::defaultValueForStepUp() const { DateComponents date; date.setMillisecondsSinceMidnight(convertToLocalTime(currentTimeMS())); double milliseconds = date.millisecondsSinceEpoch(); DCHECK(std::isfinite(milliseconds)); return Decimal::fromDouble(milliseconds); }
int BaseMultipleFieldsDateAndTimeInputType::fullYear(const String& source) const { DateComponents date; if (!parseToDateComponents(source, &date)) return DateTimeEditElement::LayoutParameters::undefinedYear(); return date.fullYear(); }
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(); }
String DateTimeInputType::sanitizeValue(const String& proposedValue) const { DateComponents date; if (!parseToDateComponents(proposedValue, &date)) return String(); return date.toString(); }
String PagePopupController::formatShortMonth(int year, int zeroBaseMonth) { if (!m_popupClient) return emptyString(); DateComponents date; date.setMonthsSinceEpoch((year - 1970) * 12.0 + zeroBaseMonth); return m_popupClient->locale().formatDateTime(date, Locale::FormatTypeShort); }
String MonthInputType::serializeWithMilliseconds(double value) const { DateComponents date; if (!date.setMillisecondsSinceEpochForMonth(value)) return String(); return serializeWithComponents(date); }
bool BaseMultipleFieldsDateAndTimeInputType::shouldHaveSecondField(const DateComponents& date) const { StepRange stepRange = createStepRange(AnyIsDefaultStep); return date.second() || date.millisecond() || !stepRange.minimum().remainder(static_cast<int>(msPerMinute)).isZero() || !stepRange.step().remainder(static_cast<int>(msPerMinute)).isZero(); }
String formatLocalizedDate(const DateComponents& dateComponents) { switch (dateComponents.type()) { case DateComponents::Date: { UDateFormat* dateFormat = createShortDateFormatter(); if (!dateFormat) break; double input = dateComponents.millisecondsSinceEpoch(); UErrorCode status = U_ZERO_ERROR; int32_t length = udat_format(dateFormat, input, 0, 0, 0, &status); if (status != U_BUFFER_OVERFLOW_ERROR) { udat_close(dateFormat); break; } Vector<UChar> buffer(length); status = U_ZERO_ERROR; udat_format(dateFormat, input, buffer.data(), length, 0, &status); udat_close(dateFormat); if (U_FAILURE(status)) break; return String::adopt(buffer); } case DateComponents::DateTime: case DateComponents::DateTimeLocal: case DateComponents::Month: case DateComponents::Time: case DateComponents::Week: case DateComponents::Invalid: break; } return String(); }
String formatMonth(const String& localeString, const String& isoString, bool useShortFormat) { OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); DateComponents date; unsigned end; date.parseMonth(isoString.characters(), isoString.length(), 0, end); return locale->formatDateTime(date, (useShortFormat ? Locale::FormatTypeShort : Locale::FormatTypeMedium)); }
bool DateTimeEditBuilder::shouldMillisecondFieldDisabled() const { if (m_millisecondRange.isSingleton() && m_millisecondRange.minimum == m_dateValue.millisecond()) return true; const Decimal decimalMsPerSecond(static_cast<int>(msPerSecond)); return stepRange().stepBase().abs().remainder(decimalMsPerSecond) == m_dateValue.millisecond() && stepRange().step().remainder(decimalMsPerSecond).isZero(); }
String formatWeek(const String& localeString, const String& isoString) { OwnPtr<LocaleMac> locale = LocaleMac::create(localeString); DateComponents date; unsigned end; date.parseWeek(isoString.characters(), isoString.length(), 0, end); return locale->formatDateTime(date); }
double MonthInputType::parseToDouble(const String& src, double defaultValue) const { DateComponents date; if (!parseToDateComponents(src, &date)) return defaultValue; double months = date.monthsSinceEpoch(); ASSERT(isfinite(months)); return months; }
double BaseDateAndTimeInputType::parseToDouble(const String& src, double defaultValue) const { DateComponents date; if (!parseToDateComponents(src, &date)) return defaultValue; double msec = date.millisecondsSinceEpoch(); ASSERT(isfinite(msec)); return msec; }
Decimal BaseDateAndTimeInputType::parseToNumber(const String& source, const Decimal& defaultValue) const { DateComponents date; if (!parseToDateComponents(source, &date)) return defaultValue; double msec = date.millisecondsSinceEpoch(); ASSERT(isfinite(msec)); return Decimal::fromDouble(msec); }
double MonthInputType::valueAsDate() const { DateComponents date; if (!parseToDateComponents(element().value(), &date)) return DateComponents::invalidMilliseconds(); double msec = date.millisecondsSinceEpoch(); ASSERT(std::isfinite(msec)); return msec; }
Decimal MonthInputType::parseToNumber(const String& src, const Decimal& defaultValue) const { DateComponents date; if (!parseToDateComponents(src, &date)) return defaultValue; double months = date.monthsSinceEpoch(); ASSERT(std::isfinite(months)); return Decimal::fromDouble(months); }
bool DateTimeEditBuilder::shouldSecondFieldDisabled() const { if (m_secondRange.isSingleton() && m_secondRange.minimum == m_dateValue.second()) return true; const Decimal decimalMsPerMinute(static_cast<int>(msPerMinute)); Decimal secondPartOfMinimum = (stepRange().stepBase().abs().remainder(decimalMsPerMinute) / static_cast<int>(msPerSecond)).floor(); return secondPartOfMinimum == m_dateValue.second() && stepRange().step().remainder(decimalMsPerMinute).isZero(); }
String PagePopupController::formatWeek(int year, int weekNumber, const String& localizedDateString) { if (!m_popupClient) return emptyString(); DateComponents week; bool setWeekResult = week.setWeek(year, weekNumber); ASSERT_UNUSED(setWeekResult, setWeekResult); String localizedWeek = m_popupClient->locale().formatDateTime(week); return m_popupClient->locale().queryString(WebLocalizedString::AXCalendarWeekDescription, localizedWeek, localizedDateString); }
void MHTMLArchive::generateMHTMLHeader( const String& boundary, const String& title, const String& mimeType, SharedBuffer& outputBuffer) { DateComponents now; now.setMillisecondsSinceEpochForDateTime(currentTimeMS()); // TODO(lukasza): Passing individual date/time components seems fragile. String dateString = makeRFC2822DateString( now.weekDay(), now.monthDay(), now.month(), now.fullYear(), now.hour(), now.minute(), now.second(), 0); StringBuilder stringBuilder; stringBuilder.appendLiteral("From: <Saved by Blink>\r\n"); stringBuilder.appendLiteral("Subject: "); // We replace non ASCII characters with '?' characters to match IE's behavior. stringBuilder.append(replaceNonPrintableCharacters(title)); stringBuilder.appendLiteral("\r\nDate: "); stringBuilder.append(dateString); stringBuilder.appendLiteral("\r\nMIME-Version: 1.0\r\n"); stringBuilder.appendLiteral("Content-Type: multipart/related;\r\n"); stringBuilder.appendLiteral("\ttype=\""); stringBuilder.append(mimeType); stringBuilder.appendLiteral("\";\r\n"); stringBuilder.appendLiteral("\tboundary=\""); stringBuilder.append(boundary); stringBuilder.appendLiteral("\"\r\n\r\n"); // We use utf8() below instead of ascii() as ascii() replaces CRLFs with ?? // (we still only have put ASCII characters in it). ASSERT(stringBuilder.toString().containsOnlyASCII()); CString asciiString = stringBuilder.toString().utf8(); outputBuffer.append(asciiString.data(), asciiString.length()); }
String BaseDateAndTimeInputType::serializeWithComponents(const DateComponents& date) const { Decimal step; if (!element()->getAllowedValueStep(&step)) return date.toString(); if (step.remainder(msecPerMinute).isZero()) return date.toString(DateComponents::None); if (step.remainder(msecPerSecond).isZero()) return date.toString(DateComponents::Second); return date.toString(DateComponents::Millisecond); }
String BaseDateAndTimeInputType::serializeWithComponents(const DateComponents& date) const { double step; if (!element()->getAllowedValueStep(&step)) return date.toString(); if (!fmod(step, msecPerMinute)) return date.toString(DateComponents::None); if (!fmod(step, msecPerSecond)) return date.toString(DateComponents::Second); return date.toString(DateComponents::Millisecond); }
Decimal TimeInputType::defaultValueForStepUp() const { double current = currentTimeMS(); int offset = calculateLocalTimeOffset(current).offset / msPerMinute; current += offset * msPerMinute; DateComponents date; date.setMillisecondsSinceMidnight(current); double milliseconds = date.millisecondsSinceEpoch(); ASSERT(std::isfinite(milliseconds)); return Decimal::fromDouble(milliseconds); }
static int currentFullYear() { double current = currentTimeMS(); double utcOffset = calculateUTCOffset(); double dstOffset = calculateDSTOffset(current, utcOffset); int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); current += offset * msPerMinute; DateComponents date; date.setMillisecondsSinceEpochForMonth(current); return date.fullYear(); }
int DateTimeYearFieldElement::defaultValueForStepDown() const { double current = currentTimeMS(); double utcOffset = calculateUTCOffset(); double dstOffset = calculateDSTOffset(current, utcOffset); int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); current += offset * msPerMinute; DateComponents date; date.setMillisecondsSinceEpochForMonth(current); return date.fullYear(); }
void DateTimeEditElement::setOnlyYearMonthDay(const DateComponents& date) { ASSERT(date.type() == DateComponents::Date); if (!m_editControlOwner) return; DateTimeFieldsState dateTimeFieldsState = valueAsDateTimeFieldsState(); dateTimeFieldsState.setYear(date.fullYear()); dateTimeFieldsState.setMonth(date.month() + 1); dateTimeFieldsState.setDayOfMonth(date.monthDay()); setValueAsDateTimeFieldsState(dateTimeFieldsState); m_editControlOwner->editControlValueChanged(); }
void BaseMultipleFieldsDateAndTimeInputType::pickerIndicatorChooseValue(const String& value) { if (element()->isValidValue(value)) { element()->setValue(value, DispatchInputAndChangeEvent); return; } if (!m_dateTimeEditElement) return; DateComponents date; unsigned end; if (date.parseDate(value.characters(), value.length(), 0, end) && end == value.length()) m_dateTimeEditElement->setOnlyYearMonthDay(date); }
Decimal MonthInputType::defaultValueForStepUp() const { double current = currentTimeMS(); double utcOffset = calculateUTCOffset(); double dstOffset = calculateDSTOffset(current, utcOffset); int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); current += offset * msPerMinute; DateComponents date; date.setMillisecondsSinceEpochForMonth(current); double months = date.monthsSinceEpoch(); ASSERT(std::isfinite(months)); return Decimal::fromDouble(months); }
double TimeInputType::defaultValueForStepUp() const { double current = currentTimeMS(); double utcOffset = calculateUTCOffset(); double dstOffset = calculateDSTOffset(current, utcOffset); int offset = static_cast<int>((utcOffset + dstOffset) / msPerMinute); current += offset * msPerMinute; DateComponents date; date.setMillisecondsSinceMidnight(current); double milliseconds = date.millisecondsSinceEpoch(); ASSERT(isfinite(milliseconds)); return milliseconds; }
bool DateTimeEditBuilder::shouldYearFieldDisabled() const { return m_parameters.minimum.type() != DateComponents::Invalid && m_parameters.maximum.type() != DateComponents::Invalid && m_parameters.minimum.fullYear() == m_parameters.maximum.fullYear() && m_parameters.minimum.fullYear() == m_dateValue.fullYear(); }
void MultipleFieldsTemporalInputTypeView::pickerIndicatorChooseValue( const String& value) { if (element().isValidValue(value)) { element().setValue(value, DispatchInputAndChangeEvent); return; } DateTimeEditElement* edit = this->dateTimeEditElement(); if (!edit) return; EventQueueScope scope; DateComponents date; unsigned end; if (date.parseDate(value, 0, end) && end == value.length()) edit->setOnlyYearMonthDay(date); element().dispatchFormControlChangeEvent(); }