예제 #1
0
Decimal TimeInputType::defaultValueForStepUp() const {
  DateComponents date;
  date.setMillisecondsSinceMidnight(convertToLocalTime(currentTimeMS()));
  double milliseconds = date.millisecondsSinceEpoch();
  DCHECK(std::isfinite(milliseconds));
  return Decimal::fromDouble(milliseconds);
}
예제 #2
0
int BaseMultipleFieldsDateAndTimeInputType::fullYear(const String& source) const
{
    DateComponents date;
    if (!parseToDateComponents(source, &date))
        return DateTimeEditElement::LayoutParameters::undefinedYear();
    return date.fullYear();
}
예제 #3
0
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();
}
예제 #4
0
String DateTimeInputType::sanitizeValue(const String& proposedValue) const
{
    DateComponents date;
    if (!parseToDateComponents(proposedValue, &date))
        return String();
    return date.toString();
}
예제 #5
0
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);
}
예제 #6
0
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();
}
예제 #8
0
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();
}
예제 #9
0
 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();
}
예제 #11
0
 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);
 }
예제 #12
0
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;
}
예제 #13
0
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;
}
예제 #14
0
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);
}
예제 #15
0
double MonthInputType::valueAsDate() const
{
    DateComponents date;
    if (!parseToDateComponents(element().value(), &date))
        return DateComponents::invalidMilliseconds();
    double msec = date.millisecondsSinceEpoch();
    ASSERT(std::isfinite(msec));
    return msec;
}
예제 #16
0
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();
}
예제 #18
0
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);
}
예제 #19
0
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());
}
예제 #20
0
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);
}
예제 #21
0
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);
}
예제 #22
0
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);
}
예제 #23
0
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();
}
예제 #24
0
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();
}
예제 #26
0
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);
}
예제 #27
0
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);
}
예제 #28
0
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();
}