From e9284e319a1b73ba9afe49f5c5b8cae9605d674c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sun, 8 May 2022 09:33:17 +0300 Subject: Autocommit at 08.05.2022 @ 09:33 --- src/Generic/Date/Date.cpp | 11 +++++++++++ src/Generic/Date/Date.h | 1 + src/UserInterface/VenueConsoleUI.cpp | 17 ++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/Generic/Date/Date.cpp b/src/Generic/Date/Date.cpp index b9f24d3..4961698 100644 --- a/src/Generic/Date/Date.cpp +++ b/src/Generic/Date/Date.cpp @@ -19,6 +19,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++; + } + } +} + Date::Date(unsigned short day, unsigned short month, unsigned short year) { this->day = day; this->month = month; diff --git a/src/Generic/Date/Date.h b/src/Generic/Date/Date.h index f8d5e21..a7c0ecb 100644 --- a/src/Generic/Date/Date.h +++ b/src/Generic/Date/Date.h @@ -14,6 +14,7 @@ class Date { public: Date(); + Date(const char* str); Date(unsigned short day, unsigned short month, unsigned short year); unsigned short get_day() const; diff --git a/src/UserInterface/VenueConsoleUI.cpp b/src/UserInterface/VenueConsoleUI.cpp index b4fd2a2..d4ab1b9 100644 --- a/src/UserInterface/VenueConsoleUI.cpp +++ b/src/UserInterface/VenueConsoleUI.cpp @@ -202,11 +202,18 @@ void command_reservationsList() { char dateStr[MAX_LINE_WIDTH]; inputLineSubBox("Enter event date: ", dateStr, MAX_LINE_WIDTH); - Date date; - if (strcmp(dateStr, "ALL") == 0) - date = Date(0, 0, 0); - else - date = Date(atoi(dateStr), atoi(dateStr + 2), atoi(dateStr + 4)); + unsigned d = 0, m = 0, y = 0; + if (strcmp(dateStr, "ALL") != 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++; + } + } + } + Date date(d, m, y); StatusCode s = es->reportReservations(name, date); handleStatusCode(s, reportsMenu); -- cgit v1.3.1-26-gb76a