Mercurial > minori
view src/date.cpp @ 7:07a9095eaeed
Update
Refactored some code, moved some around
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 24 Aug 2023 23:11:38 -0400 |
parents | 1d82f6e04d7d |
children |
line wrap: on
line source
#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); }