-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdate.h
168 lines (143 loc) · 4.63 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
//
// Created by joaog on 10/23/2020.
//
#ifndef PROJETO1_DATE_H
#define PROJETO1_DATE_H
#include <iostream>
#include <string>
using namespace std;
/**
* @brief Auxiliary class used to store, manipulate and read dates
*/
class Date
{
public:
/**
* @brief Creates an object containing today's date
*/
Date();
/**
* @brief Creates a date with given year, month and day by calling the setDate() method
* @param year Year of the date
* @param month Month of the date
* @param day Dar of the date
*/
Date(unsigned int year, unsigned int month, unsigned int day);
/**
* @brief Creates a date using the given string in the format "yyyy/mm/dd". Calls the setDate() method
* @param yearMonthDay String containing the date in the format "yyyy/mm/dd"
*/
Date(const string& yearMonthDay); // yearMonthDay must be in format "yyyy/mm/dd"
/**
* @brief Sets the date to the given year, month and day
* @throw DateIsNotValid If the date is not valid
* @param year Year of the date
* @param month Month of the date
* @param day Day of the date
*/
void setDate(unsigned int year, unsigned int month, unsigned int day);
/**
* @brief Gets the year of the date
* @throw DateIsNotValid If the date is not valid
* @return Unsigned int containing the year
*/
unsigned int getYear() const;
/**
* @brief Gets the month of the date
* @return Unsigned int containing the month
*/
unsigned int getMonth() const;
/**
* @brief Gets the day of the date
* @return Unsigned int containing the day
*/
unsigned int getDay() const;
/**
* @brief Gets the date in the format "yyyy/mm/dd"
* @return String containing the date
*/
string getDate() const; // returns the date in format "yyyy/mm/dd"
/**
* @brief Checks if the date is valid
* @return Returns true if the date is valid and false otherwise
*/
bool isValid() const;
/**
* @brief Gets how many years have passed since the date's day
* @return Unsigned int containing the age of the date
*/
unsigned int getAge() const;
/**
* @brief Checks if two dates are equal
* @param date Date used for comparison
* @return Returns true if the dates are equal and false otherwise
*/
bool operator==(const Date& date) const;
/**
* @brief Checks if two dates are different
* @param date Date used for comparison
* @return Returns true if the dates are different and false otherwise
*/
bool operator!=(const Date& date) const;
/**
* @brief Checks if this date is after a given date
* @param date Date used for comparison
* @return Returns true if this date is after the second one and false otherwise
*/
bool operator>(const Date& date);
/**
* @brief Checks if this date is before a given date
* @param date Date used for comparison
* @return Returns true if this date is before the second one and false otherwise
*/
bool operator<(const Date& date);
/**
* @brief Checks if this date is after or equal to a given date
* @param date Date used for comparison
* @return Returns true if this date is after or equal to the second one and false otherwise
*/
bool operator>=(const Date& date);
/**
* @brief Checks if this date is before or equal to a given date
* @param date Date used for comparison
* @return Returns true if this date is before or equal to the second one and false otherwise
*/
bool operator<=(const Date& date);
private:
/**
* @brief String containing the information of the Date in the format yyyy/mm/dd
*/
string datestring;
/**
* @brief Checks if the date's year is leap
* @return Returns true if the year is leap and false otherwise
*/
bool isleap() const;
/**
* @brief Calculates how many days the date's month (in the date's year) should have
* @return Integer containing the number of days this month should have
*/
int daysOfMonth() const;
};
/**
* @brief Exception which should be thrown when a date is not valid
*/
class DateIsNotValid{
private:
/**
* @brief String containing the date in the format yyyy/mm/dd
*/
string date;
public:
/**
* @brief Creates a DateIsNotValid exception with a given date
* @param date Date which was invalid
*/
DateIsNotValid(const string& date);
/**
* @brief Gets the date which was invalid
* @return String containing the invalid date (format not guarenteed)
*/
string what();
};
#endif //PROJETO1_DATE_H