Mercurial > minori
diff 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 |
line wrap: on
line diff
--- a/src/date.cpp Sat Aug 12 13:10:34 2023 -0400 +++ b/src/date.cpp Wed Aug 16 00:49:17 2023 -0400 @@ -1,54 +1,73 @@ -#include "date.h" -#include <QDate> -#include <cstdint> - -#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) -#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) - -#define CLAMP(x, low, high) ({\ - __typeof__(x) __x = (x); \ - __typeof__(low) __low = (low);\ - __typeof__(high) __high = (high);\ - __x > __high ? __high : (__x < __low ? __low : __x);\ - }) - -Date::Date() { -} - -Date::Date(int32_t y) { - year = MAX(0, y); -} - -Date::Date(int32_t y, int8_t m, int8_t d) { - year = MAX(0, y); - month = CLAMP(m, 1, 12); - day = CLAMP(d, 1, 31); -} - -void Date::SetYear(int32_t y) { - year = MAX(0, y); -} - -void Date::SetMonth(int8_t m) { - month = CLAMP(m, 1, 12); -} - -void Date::SetDay(int8_t d) { - day = CLAMP(d, 1, 31); -} - -int32_t Date::GetYear() { - return year; -} - -int8_t Date::GetMonth() { - return month; -} - -int8_t Date::GetDay() { - return day; -} - -QDate Date::GetAsQDate() { - return QDate(year, month, day); -} +#include "date.h" +#include <QDate> +#include <cstdint> +#include <tuple> + +#define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; }) +#define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; }) + +#define CLAMP(x, low, high) ({\ + __typeof__(x) __x = (x); \ + __typeof__(low) __low = (low);\ + __typeof__(high) __high = (high);\ + __x > __high ? __high : (__x < __low ? __low : __x);\ + }) + +Date::Date() { +} + +Date::Date(int32_t y) { + year = MAX(0, y); +} + +Date::Date(int32_t y, int8_t m, int8_t d) { + year = MAX(0, y); + month = CLAMP(m, 1, 12); + day = CLAMP(d, 1, 31); +} + +void Date::SetYear(int32_t y) { + year = MAX(0, y); +} + +void Date::SetMonth(int8_t m) { + month = CLAMP(m, 1, 12); +} + +void Date::SetDay(int8_t d) { + day = CLAMP(d, 1, 31); +} + +int32_t Date::GetYear() const { + return year; +} + +int8_t Date::GetMonth() const { + return month; +} + +int8_t Date::GetDay() const { + return day; +} + +bool Date::operator< (const Date& other) const { + int o_y = other.GetYear(), o_m = other.GetMonth(), o_d = other.GetDay(); + return std::tie(year, month, day) + < std::tie(o_y, o_m, o_d); +} + +bool Date::operator> (const Date& other) const { + return other < (*this); +} + +bool Date::operator<= (const Date& other) const { + return !((*this) > other); +} + +bool Date::operator>= (const Date& other) const { + return !((*this) < other); +} + +QDate Date::GetAsQDate() { + return QDate(year, month, day); +}