diff options
Autocommit at 08.05.2022 @ 09:38
1 files changed, 10 insertions, 7 deletions
| -rw-r--r-- | src/Generic/Date/Date.cpp | 17 |
diff --git a/src/Generic/Date/Date.cpp b/src/Generic/Date/Date.cpp index 4961698..45996dc 100644 --- a/src/Generic/Date/Date.cpp +++ b/src/Generic/Date/Date.cpp @@ -20,14 +20,17 @@ unsigned short Date::daysInMonth() { Date::Date() : Date(01, 05, 2022) {} Date::Date(const char* str) : Date(0, 0, 0) { - for (unsigned i = 0; i < MAX_LINE_WIDTH && y == 0; i++) { - if (dateStr[i] != ' ') { - if (d == 0) d = atoi(dateStr + i); - else if (m == 0) m = atoi(dateStr + i); - else y = atoi(dateStr + i); - i++; - } + for (unsigned i = 0; str[i] != '\0' && year == 0; i++) { + if (str[i] != ' ') { + unsigned temp = atoi(str + i); + if (temp == 0) return; // can only happen with incorrect input + + if (day == 0) day = temp; + else if (month == 0) month = temp; + else year = temp; + i++; } + } } Date::Date(unsigned short day, unsigned short month, unsigned short year) { |
