void DateTimeHourFieldElement::populateDateTimeFieldsState(DateTimeFieldsState& dateTimeFieldsState) { if (!hasValue()) { dateTimeFieldsState.setHour(DateTimeFieldsState::emptyValue); return; } const int value = valueAsInteger(); switch (maximum()) { case 11: dateTimeFieldsState.setHour(value ? value : 12); return; case 12: dateTimeFieldsState.setHour(value); return; case 23: dateTimeFieldsState.setHour(value ? value % 12 : 12); dateTimeFieldsState.setAMPM(value >= 12 ? DateTimeFieldsState::AMPMValuePM : DateTimeFieldsState::AMPMValueAM); return; case 24: if (value == 24) { dateTimeFieldsState.setHour(12); dateTimeFieldsState.setHour(DateTimeFieldsState::AMPMValueAM); return; } dateTimeFieldsState.setHour(value == 12 ? 12 : value % 12); dateTimeFieldsState.setAMPM(value >= 12 ? DateTimeFieldsState::AMPMValuePM : DateTimeFieldsState::AMPMValueAM); return; default: ASSERT_NOT_REACHED(); } }
void DateTimeAMPMFieldElement::populateDateTimeFieldsState(DateTimeFieldsState& dateTimeFieldsState) { if (hasValue()) dateTimeFieldsState.setAMPM(valueAsInteger() ? DateTimeFieldsState::AMPMValuePM : DateTimeFieldsState::AMPMValueAM); else dateTimeFieldsState.setAMPM(DateTimeFieldsState::AMPMValueEmpty); }
void DateTimeHour24FieldElement::populateDateTimeFieldsState(DateTimeFieldsState& dateTimeFieldsState) { if (!hasValue()) { dateTimeFieldsState.setHour(DateTimeFieldsState::emptyValue); return; } const int value = valueAsInteger(); if (value == 24) { dateTimeFieldsState.setHour(12); dateTimeFieldsState.setAMPM(DateTimeFieldsState::AMPMValueAM); } else { dateTimeFieldsState.setHour(value == 12 ? 12 : value % 12); dateTimeFieldsState.setAMPM(value >= 12 ? DateTimeFieldsState::AMPMValuePM : DateTimeFieldsState::AMPMValueAM); } }
DateTimeFieldsState DateTimeFieldsState::restoreFormControlState(const FormControlState& state) { DateTimeFieldsState dateTimeFieldsState; dateTimeFieldsState.setYear(getNumberFromFormControlState(state, 0)); dateTimeFieldsState.setMonth(getNumberFromFormControlState(state, 1)); dateTimeFieldsState.setDayOfMonth(getNumberFromFormControlState(state, 2)); dateTimeFieldsState.setHour(getNumberFromFormControlState(state, 3)); dateTimeFieldsState.setMinute(getNumberFromFormControlState(state, 4)); dateTimeFieldsState.setSecond(getNumberFromFormControlState(state, 5)); dateTimeFieldsState.setMillisecond(getNumberFromFormControlState(state, 6)); dateTimeFieldsState.setWeekOfYear(getNumberFromFormControlState(state, 7)); dateTimeFieldsState.setAMPM(getAMPMFromFormControlState(state, 8)); return dateTimeFieldsState; }