-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Date.h
77 lines (53 loc) · 2.24 KB
/
Date.h
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef DATE_H_
#define DATE_H_
// A class representing a Paradox - style date.
//
// Construction
// * Default construction gives a date of 0001 - 01 - 01
// * Can directly specify year, month, day
// * Can directly specify year, month, day, and if this is an AUC(years after the founding of Rome, used in Imperator) format date or not
// *Can pass a paradox - style string specifying the date
// * Can pass a paradox - style string specifying the date, and if this is an AUC(years after the founding of Rome, used in Imperator) format date or not
//
// Comparison
// * Dates can be compared using all the standard comparators.Additionally, the difference between two dates(in years) can be found.
//
// Modification
// * Dates can be increased by months or years, and can be decreased by years.In all cases these must be whole - number changes to months or years.
//
// Output
// * Dates can be output to a stream or converted to a string.
#include <string>
namespace CommonItems
{
[[nodiscard]] int DaysInMonth(int month);
} // namespace CommonItems
class date
{
public:
date() = default;
explicit date(const int year, const int month, const int day, const bool AUC): year(AUC ? convertAUCtoAD(year) : year), month(month), day(day) {}
explicit date(const int year, const int month, const int day): date(year, month, day, false) {}
explicit date(std::string init, bool AUC);
explicit date(const std::string& init): date(init, false) {}
void ChangeByDays(int days);
void ChangeByMonths(int months);
void increaseByMonths(int months);
void ChangeByYears(int years) { year += years; }
void addYears(int years) { ChangeByYears(years); }
void subtractYears(int years) { ChangeByYears(-years); }
auto operator<=>(const date& rhs) const = default;
[[nodiscard]] auto getYear() const { return year; }
[[nodiscard]] auto getMonth() const { return month; }
[[nodiscard]] auto getDay() const { return day; }
[[nodiscard]] float diffInYears(const date& rhs) const;
[[nodiscard]] std::string toString() const;
friend std::ostream& operator<<(std::ostream& out, const date& date);
private:
[[nodiscard]] int calculateDayInYear() const;
[[nodiscard]] static int convertAUCtoAD(int yearAUC);
int year = 1;
int month = 1;
int day = 1;
};
#endif // _DATE_H