[Manager] Fix time verification to allow '24:00' value in Preferences dialog

Time verification simplification.

Signed-off-by: Vitalii Koshura <lestat.de.lionkur@gmail.com>
This commit is contained in:
Charlie Fenton 2018-07-04 13:59:00 +03:00 committed by Vitalii Koshura
parent f368579c54
commit 8ff7f01a1f
No known key found for this signature in database
GPG Key ID: CE0DB1726070A5A3
1 changed files with 6 additions and 22 deletions

View File

@ -1006,33 +1006,17 @@ bool CDlgAdvPreferences::IsValidFloatValueBetween(const wxString& value, double
/* checks if the value is a valid time */
bool CDlgAdvPreferences::IsValidTimeValue(const wxString& value) {
for(unsigned int i=0; i < value.Length();i++) {
if(!IsValidTimeChar(value[i])) {
for (unsigned int i = 0; i < value.Length(); i++) {
if (!IsValidTimeChar(value[i])) {
return false;
}
}
//verify correct format and range of time values
int h = -1, m = -1;
//verify the format itself
int parsed = sscanf(value.c_str(), "%d:%d", &h, &m);
if (parsed != 2) {
return false;
}
//verify hours
if (h < 0 || h > 23) {
return false;
}
//verify minutes
if (m < 0 || m > 59) {
return false;
}
//all chars are valid, now what is with the value as a whole ?
if (value == wxT("24:00")) return true;
wxDateTime dt;
const wxChar* stopChar = dt.ParseFormat(value,wxT("%H:%M"));
if(stopChar==NULL && value != wxT("24:00")) {
// conversion failed
return false;
}
const wxChar* stopChar = dt.ParseFormat(value, wxT("%H:%M"));
if (stopChar == NULL) return false; // conversion failed
if (*stopChar != '\0') return false; // conversion failed
return true;
}