2
|
1 #include "date.h"
|
|
2 #include <QDate>
|
|
3 #include <cstdint>
|
|
4
|
|
5 #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
|
|
6 #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
|
|
7
|
|
8 #define CLAMP(x, low, high) ({\
|
|
9 __typeof__(x) __x = (x); \
|
|
10 __typeof__(low) __low = (low);\
|
|
11 __typeof__(high) __high = (high);\
|
|
12 __x > __high ? __high : (__x < __low ? __low : __x);\
|
|
13 })
|
|
14
|
|
15 Date::Date() {
|
|
16 }
|
|
17
|
|
18 Date::Date(int32_t y) {
|
|
19 year = MAX(0, y);
|
|
20 }
|
|
21
|
|
22 Date::Date(int32_t y, int8_t m, int8_t d) {
|
|
23 year = MAX(0, y);
|
|
24 month = CLAMP(m, 1, 12);
|
|
25 day = CLAMP(d, 1, 31);
|
|
26 }
|
|
27
|
|
28 void Date::SetYear(int32_t y) {
|
|
29 year = MAX(0, y);
|
|
30 }
|
|
31
|
|
32 void Date::SetMonth(int8_t m) {
|
|
33 month = CLAMP(m, 1, 12);
|
|
34 }
|
|
35
|
|
36 void Date::SetDay(int8_t d) {
|
|
37 day = CLAMP(d, 1, 31);
|
|
38 }
|
|
39
|
|
40 int32_t Date::GetYear() {
|
|
41 return year;
|
|
42 }
|
|
43
|
|
44 int8_t Date::GetMonth() {
|
|
45 return month;
|
|
46 }
|
|
47
|
|
48 int8_t Date::GetDay() {
|
|
49 return day;
|
|
50 }
|
|
51
|
|
52 QDate Date::GetAsQDate() {
|
|
53 return QDate(year, month, day);
|
|
54 }
|