Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 1:1ae666fdf9e2 | 2:23d0d9319a00 |
|---|---|
| 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 } |
