-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDate.cpp
More file actions
32 lines (29 loc) · 892 Bytes
/
Copy pathDate.cpp
File metadata and controls
32 lines (29 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "Date.h"
int Year[10] = { 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004 };
bool Date::isLeapYear(int year) {
if (year % 400 == 0) return 1;
else if (year % 100 == 0) return 0;
else if (year % 4 == 0) return 1;
else return 0;
}
int Date::checkMonth(int month, int year) {
if (isLeapYear(year)) {
int maxDay[12]{ 31,29,31,30,31,30,31,31,30,31,30,31 };
return maxDay[month - 1];
}
else {
int maxDay[12]{ 31,28,31,30,31,30,31,31,30,31,30,31 };
return maxDay[month - 1];
}
}
wstring Date::toString() {
wstringstream builder;
builder << this->_day << "/" << this->_month << "/" << this->_year;
return builder.str();
}
Date::Date() {
auto intGen = RNG::instance();
this->_year = Year[intGen->next() % 10];
this->_month = intGen->next() % 12 + 1;
this->_day = intGen->next() % checkMonth(this->_month, this->_year) + 1;
}