Website Summary Files Commits Branches @commit @diff @stats
path: root / src / DateTime / DateTime.cpp
diff options
context:
space:
mode:
Commit2d83acdd639e4a404360a65b7af08e286645066c (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-01 09:10:49 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-05-01 09:10:49 +0300
Filese9e00b8db1ac8b348f0c5f7a15db4db65bb3fc2b /src/DateTime/DateTime.cpp
FMI-OOP-P1_TicketSystem-2d83acdd639e4a404360a65b7af08e286645066c.tar
FMI-OOP-P1_TicketSystem-2d83acdd639e4a404360a65b7af08e286645066c.tar.gz
FMI-OOP-P1_TicketSystem-2d83acdd639e4a404360a65b7af08e286645066c.zip
Parentd95a9e48364735bd21a9bbdc4bde289a426e059b (diff)
Autocommit at 01.05.2022 @ 09:10
1 files changed, 21 insertions, 3 deletions
-rw-r--r--src/DateTime/DateTime.cpp24
diff --git a/src/DateTime/DateTime.cpp b/src/DateTime/DateTime.cpp
index 41d54f5..56ddba1 100644
--- a/src/DateTime/DateTime.cpp
+++ b/src/DateTime/DateTime.cpp
@@ -7,6 +7,14 @@ bool DateTime::isLeapYear() {
return year % 400 == 0 || year % 100 != 0 || year % 4 == 0;
}
+unsigned short DateTime::daysInMonth() {
+ if (month == 2)
+ return 28 + isLeapYear();
+ if (month <= 7)
+ return 30 + month % 2;
+ return 31 - month % 2;
+}
+
/* Public */
DateTime::DateTime(unsigned short hour, unsigned short minute, unsigned short day, unsigned short month, unsigned short year) {
@@ -48,11 +56,21 @@ unsigned short DateTime::get_day() {
return day;
}
bool DateTime::set_day(unsigned short newDay) {
-
+ if (newDay == 0 || newDay > daysInMonth())
+ return false;
+ day = newDay;
+ return true;
}
-unsigned short get_month();
-bool set_month(unsigned short newMonth);
+unsigned short DateTime::get_month() {
+ return month;
+}
+bool DateTime::set_month(unsigned short newMonth) {
+ if (newMonth == 0 || newMonth > 12)
+ return false;
+ month = newMonth;
+ return true;
+}
unsigned short DateTime::get_year() {
return year;