From 72ddedf86f34b28bf5faabf7d1fdd2bf54126164 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 8 May 2022 09:38:19 +0300 Subject: Autocommit at 08.05.2022 @ 09:38 --- src/Generic/Date/Date.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/Generic/Date/Date.cpp') 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) { -- cgit v1.3.1-23-gd82d