String BaseDateAndTimeInputType::serialize(const Decimal& value) const { if (!value.isFinite()) return String(); DateComponents date; if (!setMillisecondToDateComponents(value.toDouble(), &date)) return String(); return serializeWithComponents(date); }
void nsNumberControlFrame::SetValueOfAnonTextControl(const nsAString& aValue) { if (mHandlingInputEvent) { // We have been called while our HTMLInputElement is processing a DOM // 'input' event targeted at our anonymous text control. Our // HTMLInputElement has taken the value of our anon text control and // called SetValueInternal on itself to keep its own value in sync. As a // result SetValueInternal has called us. In this one case we do not want // to update our anon text control, especially since aValue will be the // sanitized value, and only the internal value should be sanitized (not // the value shown to the user, and certainly we shouldn't change it as // they type). return; } // Init to aValue so that we set aValue as the value of our text control if // aValue isn't a valid number (in which case the HTMLInputElement's validity // state will be set to invalid) or if aValue can't be localized: nsAutoString localizedValue(aValue); #ifdef ENABLE_INTL_API // Try and localize the value we will set: Decimal val = HTMLInputElement::StringToDecimal(aValue); if (val.isFinite()) { ICUUtils::LanguageTagIterForContent langTagIter(mContent); ICUUtils::LocalizeNumber(val.toDouble(), langTagIter, localizedValue); } #endif // We need to update the value of our anonymous text control here. Note that // this must be its value, and not its 'value' attribute (the default value), // since the default value is ignored once a user types into the text // control. HTMLInputElement::FromContent(mTextField)->SetValue(localizedValue); }
double BaseDateAndTimeInputType::valueAsDouble() const { const Decimal value = parseToNumber(element()->value(), Decimal::nan()); return value.isFinite() ? value.toDouble() : DateComponents::invalidMilliseconds(); }