-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDate.hpp
142 lines (121 loc) · 2.72 KB
/
Date.hpp
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
//
// Date.hpp
// Maw Kit
//
// Created by Lluís Ulzurrun de Asanza Sàez on 29/02/16.
//
//
#ifndef Date_hpp
#define Date_hpp
#include <ctime>
namespace MK {
/// `Date` class is a wrapper for day-precision dates.
class Date {
public:
/// Enumeration holding months.
enum class Month {
January = 0, ///< January
February = 1, ///< February
March = 2, ///< March
April = 3, ///< April
May = 4, ///< May
June = 5, ///< June
July = 6, ///< July
August = 7, ///< August
September = 8, ///< September
October = 9, ///< October
November = 10, ///< November
December = 11 ///< December
};
/**
* Returns today's date.
*
* @return Date representing today.
*/
static const Date Today();
/**
* Returns the first day of Easter of this year.
*
* @return First day of Easter.
*/
static const Date EasterStart();
/**
* Returns the last day of Easter of this year.
*
* @return Last day of Easter.
*/
static const Date EasterEnd();
/**
* Returns the first day of Christmas of this year.
*
* @return First day of Christmas.
*/
static const Date ChristmasStart();
/**
* Returns the last day of Christmas of this year.
*
* @return Last day of Christmas.
*/
static const Date ChristmasEnd();
/**
* Returns a new date object given its UNIX timestamp.
*
* @param timestamp UNIX timestamp.
*/
Date( std::time_t timestamp );
/**
* Returns a new date object for given day, month and year.
*
* @param day Day.
* @param month Month.
* @param year Year.
*/
Date( unsigned short day, Month month, unsigned long long year );
/**
* Returns day component of this date.
*
* @return Day component of this date.
*/
const unsigned short getDay() const;
/**
* Returns month component of this date.
*
* @return Month component of this date.
*/
const Month getMonth() const;
/**
* Returns year component of this date.
*
* @return Year component of this date.
*/
const unsigned long long getYear() const;
/**
* Returns whether left hand side happened before right hand side.
*
* @param rhs Right hand side.
*
* @return `true` if left hand side happened before right hand side.
*/
inline bool operator<( const Date &rhs ) const;
/**
* Returns whether given dates are equal or not.
*
* @param rhs Right hand side.
*
* @return `true` if both dates are equal.
*/
inline bool operator==( const Date &rhs ) const;
/**
* Returns UNIX timestamp for given date.
*
* @return UNIX timestamp for given date.
*/
std::time_t getTimestamp() const;
protected:
/**
* Timestamp of this date.
*/
std::time_t unixTimestamp;
};
}; // namespace MK
#endif /* Date_hpp */