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()); }
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 DateTimeSymbolicMonthFieldElement::setValueAsDate(const DateComponents& date) { setValueAsInteger(date.month()); }
void DateTimeEditBuilder::visitField(DateTimeFormat::FieldType fieldType, int count) { const int countForAbbreviatedMonth = 3; const int countForFullMonth = 4; const int countForNarrowMonth = 5; Document& document = m_editElement.document(); switch (fieldType) { case DateTimeFormat::FieldTypeDayOfMonth: { RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeDayFieldElement::create(document, m_editElement, m_parameters.placeholderForDay, m_dayRange); m_editElement.addField(field); if (shouldDayOfMonthFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeHour11: { DateTimeNumericFieldElement::Step step = createStep(msPerHour, msPerHour * 12); RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeHour11FieldElement::create(document, m_editElement, m_hour23Range, step); m_editElement.addField(field); if (shouldHourFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeHour12: { DateTimeNumericFieldElement::Step step = createStep(msPerHour, msPerHour * 12); RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeHour12FieldElement::create(document, m_editElement, m_hour23Range, step); m_editElement.addField(field); if (shouldHourFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeHour23: { DateTimeNumericFieldElement::Step step = createStep(msPerHour, msPerDay); RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeHour23FieldElement::create(document, m_editElement, m_hour23Range, step); m_editElement.addField(field); if (shouldHourFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeHour24: { DateTimeNumericFieldElement::Step step = createStep(msPerHour, msPerDay); RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeHour24FieldElement::create(document, m_editElement, m_hour23Range, step); m_editElement.addField(field); if (shouldHourFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeMinute: { DateTimeNumericFieldElement::Step step = createStep(msPerMinute, msPerHour); RefPtrWillBeRawPtr<DateTimeNumericFieldElement> field = DateTimeMinuteFieldElement::create(document, m_editElement, m_minuteRange, step); m_editElement.addField(field); if (shouldMinuteFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeMonth: // Fallthrough. case DateTimeFormat::FieldTypeMonthStandAlone: { int minMonth = 0, maxMonth = 11; if (m_parameters.minimum.type() != DateComponents::Invalid && m_parameters.maximum.type() != DateComponents::Invalid && m_parameters.minimum.fullYear() == m_parameters.maximum.fullYear() && m_parameters.minimum.month() <= m_parameters.maximum.month()) { minMonth = m_parameters.minimum.month(); maxMonth = m_parameters.maximum.month(); } RefPtrWillBeRawPtr<DateTimeFieldElement> field; switch (count) { case countForNarrowMonth: // Fallthrough. case countForAbbreviatedMonth: field = DateTimeSymbolicMonthFieldElement::create(document, m_editElement, fieldType == DateTimeFormat::FieldTypeMonth ? m_parameters.locale.shortMonthLabels() : m_parameters.locale.shortStandAloneMonthLabels(), minMonth, maxMonth); break; case countForFullMonth: field = DateTimeSymbolicMonthFieldElement::create(document, m_editElement, fieldType == DateTimeFormat::FieldTypeMonth ? m_parameters.locale.monthLabels() : m_parameters.locale.standAloneMonthLabels(), minMonth, maxMonth); break; default: field = DateTimeMonthFieldElement::create(document, m_editElement, m_parameters.placeholderForMonth, DateTimeNumericFieldElement::Range(minMonth + 1, maxMonth + 1)); break; } m_editElement.addField(field); if (minMonth == maxMonth && minMonth == m_dateValue.month() && m_dateValue.type() != DateComponents::Month) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypePeriod: { RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeAMPMFieldElement::create(document, m_editElement, m_parameters.locale.timeAMPMLabels()); m_editElement.addField(field); if (shouldAMPMFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeSecond: { DateTimeNumericFieldElement::Step step = createStep(msPerSecond, msPerMinute); RefPtrWillBeRawPtr<DateTimeNumericFieldElement> field = DateTimeSecondFieldElement::create(document, m_editElement, m_secondRange, step); m_editElement.addField(field); if (shouldSecondFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } if (needMillisecondField()) { visitLiteral(m_parameters.locale.localizedDecimalSeparator()); visitField(DateTimeFormat::FieldTypeFractionalSecond, 3); } return; } case DateTimeFormat::FieldTypeFractionalSecond: { DateTimeNumericFieldElement::Step step = createStep(1, msPerSecond); RefPtrWillBeRawPtr<DateTimeNumericFieldElement> field = DateTimeMillisecondFieldElement::create(document, m_editElement, m_millisecondRange, step); m_editElement.addField(field); if (shouldMillisecondFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } case DateTimeFormat::FieldTypeWeekOfYear: { DateTimeNumericFieldElement::Range range(DateComponents::minimumWeekNumber, DateComponents::maximumWeekNumber); if (m_parameters.minimum.type() != DateComponents::Invalid && m_parameters.maximum.type() != DateComponents::Invalid && m_parameters.minimum.fullYear() == m_parameters.maximum.fullYear() && m_parameters.minimum.week() <= m_parameters.maximum.week()) { range.minimum = m_parameters.minimum.week(); range.maximum = m_parameters.maximum.week(); } m_editElement.addField(DateTimeWeekFieldElement::create(document, m_editElement, range)); return; } case DateTimeFormat::FieldTypeYear: { DateTimeYearFieldElement::Parameters yearParams; if (m_parameters.minimum.type() == DateComponents::Invalid) { yearParams.minimumYear = DateComponents::minimumYear(); yearParams.minIsSpecified = false; } else { yearParams.minimumYear = m_parameters.minimum.fullYear(); yearParams.minIsSpecified = true; } if (m_parameters.maximum.type() == DateComponents::Invalid) { yearParams.maximumYear = DateComponents::maximumYear(); yearParams.maxIsSpecified = false; } else { yearParams.maximumYear = m_parameters.maximum.fullYear(); yearParams.maxIsSpecified = true; } if (yearParams.minimumYear > yearParams.maximumYear) { std::swap(yearParams.minimumYear, yearParams.maximumYear); std::swap(yearParams.minIsSpecified, yearParams.maxIsSpecified); } yearParams.placeholder = m_parameters.placeholderForYear; RefPtrWillBeRawPtr<DateTimeFieldElement> field = DateTimeYearFieldElement::create(document, m_editElement, yearParams); m_editElement.addField(field); if (shouldYearFieldDisabled()) { field->setValueAsDate(m_dateValue); field->setDisabled(); } return; } default: return; } }
String LocaleWin::formatDate(const DateComponents& dateComponents) { ensureShortDateTokens(); return formatDate(m_shortDateTokens, m_baseYear, dateComponents.fullYear(), dateComponents.month(), dateComponents.monthDay()); }