comparison src/date.cpp @ 6:1d82f6e04d7d

Update: add first parts to the settings dialog
author Paper <mrpapersonic@gmail.com>
date Wed, 16 Aug 2023 00:49:17 -0400
parents 23d0d9319a00
children
comparison
equal deleted inserted replaced
5:51ae25154b70 6:1d82f6e04d7d
1 #include "date.h" 1 #include "date.h"
2 #include <QDate> 2 #include <QDate>
3 #include <cstdint> 3 #include <cstdint>
4 #include <tuple>
4 5
5 #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) 6 #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 #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
7 8
8 #define CLAMP(x, low, high) ({\ 9 #define CLAMP(x, low, high) ({\
35 36
36 void Date::SetDay(int8_t d) { 37 void Date::SetDay(int8_t d) {
37 day = CLAMP(d, 1, 31); 38 day = CLAMP(d, 1, 31);
38 } 39 }
39 40
40 int32_t Date::GetYear() { 41 int32_t Date::GetYear() const {
41 return year; 42 return year;
42 } 43 }
43 44
44 int8_t Date::GetMonth() { 45 int8_t Date::GetMonth() const {
45 return month; 46 return month;
46 } 47 }
47 48
48 int8_t Date::GetDay() { 49 int8_t Date::GetDay() const {
49 return day; 50 return day;
51 }
52
53 bool Date::operator< (const Date& other) const {
54 int o_y = other.GetYear(), o_m = other.GetMonth(), o_d = other.GetDay();
55 return std::tie(year, month, day)
56 < std::tie(o_y, o_m, o_d);
57 }
58
59 bool Date::operator> (const Date& other) const {
60 return other < (*this);
61 }
62
63 bool Date::operator<= (const Date& other) const {
64 return !((*this) > other);
65 }
66
67 bool Date::operator>= (const Date& other) const {
68 return !((*this) < other);
50 } 69 }
51 70
52 QDate Date::GetAsQDate() { 71 QDate Date::GetAsQDate() {
53 return QDate(year, month, day); 72 return QDate(year, month, day);
54 } 73 }