-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdate.h
67 lines (53 loc) · 1.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
#ifndef _DATE_H_
#define _DATE_H_
/* Date has a get_text() function which takes a string format as an argument.
* The format defaults to "#M #d, #Y".
* The following characters get replaced:
* #Y - Four-digit year.
* #y - Two-digit year.
* #M - Name of month.
* #m - Month number.
* #d - Day number.
* ## - Literal #.
* All other characters are left verbatim.
*/
#include <string>
#include <istream>
std::string month_name(int month);
int days_in_month(int month);
class Date
{
public:
Date();
~Date();
Date(const Date& copy);
Date(int _year, int _month, int _day);
std::string save_data();
bool load_data(std::istream& data);
bool operator==(const Date& other) const;
bool operator!=(const Date& other) const;
Date& operator+=(const Date& rhs);
Date& operator-=(const Date& rhs);
int get_year();
int get_month();
int get_day();
std::string get_month_name();
std::string get_text(std::string format = "");
void advance(int days = 1);
void standardize(); // Ensure day < 30/31, month < 12, etc
private:
int year;
int month;
int day;
};
inline Date operator+(Date lhs, const Date& rhs)
{
lhs += rhs;
return lhs;
}
inline Date operator-(Date lhs, const Date& rhs)
{
lhs -= rhs;
return lhs;
}
#endif