void DateTimeHourFieldElementBase::setValueAsDateTimeFieldsState(const DateTimeFieldsState& dateTimeFieldsState) { if (!dateTimeFieldsState.hasHour()) { setEmptyValue(); return; } const int hour12 = dateTimeFieldsState.hour(); if (hour12 < 1 || hour12 > 12) { setEmptyValue(); return; } const int hour11 = hour12 == 12 ? 0 : hour12; const int hour23 = dateTimeFieldsState.ampm() == DateTimeFieldsState::AMPMValuePM ? hour11 + 12 : hour11; setValueAsInteger(hour23); }
void DateTimeHourFieldElement::setValueAsDateTimeFieldsState(const DateTimeFieldsState& dateTimeFieldsState) { if (!dateTimeFieldsState.hasHour()) { setEmptyValue(); return; } const int hour12 = dateTimeFieldsState.hour(); if (hour12 < 1 || hour12 > 12) { setEmptyValue(); return; } switch (maximum()) { case 11: DateTimeNumericFieldElement::setValueAsInteger(hour12 % 12); return; case 12: DateTimeNumericFieldElement::setValueAsInteger(hour12); return; case 23: if (dateTimeFieldsState.ampm() == DateTimeFieldsState::AMPMValuePM) DateTimeNumericFieldElement::setValueAsInteger((hour12 + 12) % 24); else DateTimeNumericFieldElement::setValueAsInteger(hour12 % 12); return; case 24: if (dateTimeFieldsState.ampm() == DateTimeFieldsState::AMPMValuePM) DateTimeNumericFieldElement::setValueAsInteger(hour12 == 12 ? 12 : hour12 + 12); else DateTimeNumericFieldElement::setValueAsInteger(hour12); return; default: ASSERT_NOT_REACHED(); } }