Mercurial > minori
view src/date.cpp @ 2:23d0d9319a00
Update
Also converted everything to LF from CRLF
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sat, 12 Aug 2023 03:16:26 -0400 |
parents | |
children | 1d82f6e04d7d |
line wrap: on
line source
#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); }