Feature - enhanced date parse error

- When a date fails to parse, the expected format is displayed, as a reminder
  (thanks to Eric Fluger).
This commit is contained in:
Paul Beckingham 2011-01-14 22:56:52 -05:00
parent d4772fe060
commit 7ca51e78f0
2 changed files with 20 additions and 18 deletions

View file

@ -37,6 +37,8 @@
+ Added new holiday configuration file for Italy (thanks to Nicola Busanello). + Added new holiday configuration file for Italy (thanks to Nicola Busanello).
+ Eliminated dependency on ncurses. + Eliminated dependency on ncurses.
+ The dependency columns are now right-justified (thanks to Eric Fluger). + The dependency columns are now right-justified (thanks to Eric Fluger).
+ When a date fails to parse, the expected format is displayed, as a reminder
(thanks to Eric Fluger).
+ Fixed bug that caused the 'done' command to always exit with a non-zero + Fixed bug that caused the 'done' command to always exit with a non-zero
status (thanks to Steve Rader). status (thanks to Steve Rader).
+ Fixed bug that caused entry, end, start and wait dates to not use report- + Fixed bug that caused entry, end, start and wait dates to not use report-

View file

@ -113,7 +113,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
if (i >= input.length () || if (i >= input.length () ||
! isdigit (input[i])) ! isdigit (input[i]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (m)."; throw std::string ("\"") + input + "\" is not a valid date (m). Expected format '" + format + "'";
} }
if (i + 1 < input.length () && if (i + 1 < input.length () &&
@ -134,7 +134,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
if (i >= input.length () || if (i >= input.length () ||
! isdigit (input[i])) ! isdigit (input[i]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (d)."; throw std::string ("\"") + input + "\" is not a valid date (d). Expected format '" + format + "'";
} }
if (i + 1 < input.length () && if (i + 1 < input.length () &&
@ -157,7 +157,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (y)."; throw std::string ("\"") + input + "\" is not a valid date (y). Expected format '" + format + "'";
} }
year = atoi (input.substr (i, 2).c_str ()) + 2000; year = atoi (input.substr (i, 2).c_str ()) + 2000;
@ -169,7 +169,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (M)."; throw std::string ("\"") + input + "\" is not a valid date (M). Expected format '" + format + "'";
} }
month = atoi (input.substr (i, 2).c_str ()); month = atoi (input.substr (i, 2).c_str ());
@ -181,7 +181,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (D)."; throw std::string ("\"") + input + "\" is not a valid date (D). Expected format '" + format + "'";
} }
day = atoi (input.substr (i, 2).c_str ()); day = atoi (input.substr (i, 2).c_str ());
@ -193,7 +193,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (V)."; throw std::string ("\"") + input + "\" is not a valid date (V). Expected format '" + format + "'";
} }
i += 2; i += 2;
@ -207,7 +207,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 2]) || ! isdigit (input[i + 2]) ||
! isdigit (input[i + 3])) ! isdigit (input[i + 3]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (Y)."; throw std::string ("\"") + input + "\" is not a valid date (Y). Expected format '" + format + "'";
} }
year = atoi (input.substr (i, 4).c_str ()); year = atoi (input.substr (i, 4).c_str ());
@ -221,7 +221,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
isdigit (input[i + 1]) || isdigit (input[i + 1]) ||
isdigit (input[i + 2])) isdigit (input[i + 2]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (a)."; throw std::string ("\"") + input + "\" is not a valid date (a). Expected format '" + format + "'";
} }
i += 3; i += 3;
@ -233,7 +233,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
isdigit (input[i + 1]) || isdigit (input[i + 1]) ||
isdigit (input[i + 2])) isdigit (input[i + 2]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (b)."; throw std::string ("\"") + input + "\" is not a valid date (b). Expected format '" + format + "'";
} }
month = Date::monthOfYear (input.substr (i, 3).c_str()); month = Date::monthOfYear (input.substr (i, 3).c_str());
@ -247,7 +247,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
isdigit (input[i + 1]) || isdigit (input[i + 1]) ||
isdigit (input[i + 2])) isdigit (input[i + 2]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (A)."; throw std::string ("\"") + input + "\" is not a valid date (A). Expected format '" + format + "'";
} }
i += Date::dayName( Date::dayOfWeek (input.substr (i, 3).c_str()) ).size(); i += Date::dayName( Date::dayOfWeek (input.substr (i, 3).c_str()) ).size();
@ -259,7 +259,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
isdigit (input[i + 1]) || isdigit (input[i + 1]) ||
isdigit (input[i + 2])) isdigit (input[i + 2]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (B)."; throw std::string ("\"") + input + "\" is not a valid date (B). Expected format '" + format + "'";
} }
month = Date::monthOfYear (input.substr (i, 3).c_str()); month = Date::monthOfYear (input.substr (i, 3).c_str());
@ -271,7 +271,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
if (i >= input.length () || if (i >= input.length () ||
! isdigit (input[i])) ! isdigit (input[i]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (h)."; throw std::string ("\"") + input + "\" is not a valid date (h). Expected format '" + format + "'";
} }
if (i + 1 < input.length () && if (i + 1 < input.length () &&
@ -293,7 +293,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (H)."; throw std::string ("\"") + input + "\" is not a valid date (H). Expected format '" + format + "'";
} }
hour = atoi (input.substr (i, 2).c_str ()); hour = atoi (input.substr (i, 2).c_str ());
@ -305,7 +305,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (N)."; throw std::string ("\"") + input + "\" is not a valid date (N). Expected format '" + format + "'";
} }
minute = atoi (input.substr (i, 2).c_str ()); minute = atoi (input.substr (i, 2).c_str ());
@ -317,7 +317,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
! isdigit (input[i + 0]) || ! isdigit (input[i + 0]) ||
! isdigit (input[i + 1])) ! isdigit (input[i + 1]))
{ {
throw std::string ("\"") + input + "\" is not a valid date (S)."; throw std::string ("\"") + input + "\" is not a valid date (S). Expected format '" + format + "'";
} }
second = atoi (input.substr (i, 2).c_str ()); second = atoi (input.substr (i, 2).c_str ());
@ -328,7 +328,7 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
if (i >= input.length () || if (i >= input.length () ||
input[i] != format[f]) input[i] != format[f])
{ {
throw std::string ("\"") + input + "\" is not a valid date (DEFAULT)."; throw std::string ("\"") + input + "\" is not a valid date. Expected format '" + format + "'";
} }
++i; ++i;
break; break;
@ -344,10 +344,10 @@ Date::Date (const std::string& input, const std::string& format /* = "m/d/Y" */)
} }
if (i < input.length ()) if (i < input.length ())
throw std::string ("\"") + input + "\" is not a valid date in " + format + " format."; throw std::string ("\"") + input + "\" is not a valid date. Expected format '" + format + "'";
if (!valid (month, day, year)) if (!valid (month, day, year))
throw std::string ("\"") + input + "\" is not a valid date (VALID)."; throw std::string ("\"") + input + "\" is not a valid date but is in a valid format.";
// Convert to epoch. // Convert to epoch.
struct tm t = {0}; struct tm t = {0};