annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #include "date.h"
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #include <QDate>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 #include <cstdint>
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #define MIN(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __a : __b; })
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #define MAX(A,B) ({ __typeof__(A) __a = (A); __typeof__(B) __b = (B); __a < __b ? __b : __a; })
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #define CLAMP(x, low, high) ({\
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 __typeof__(x) __x = (x); \
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 __typeof__(low) __low = (low);\
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 __typeof__(high) __high = (high);\
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 __x > __high ? __high : (__x < __low ? __low : __x);\
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 })
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 Date::Date() {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 Date::Date(int32_t y) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 year = MAX(0, y);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 Date::Date(int32_t y, int8_t m, int8_t d) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 year = MAX(0, y);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 month = CLAMP(m, 1, 12);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 day = CLAMP(d, 1, 31);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 void Date::SetYear(int32_t y) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 year = MAX(0, y);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 void Date::SetMonth(int8_t m) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 month = CLAMP(m, 1, 12);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 void Date::SetDay(int8_t d) {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 day = CLAMP(d, 1, 31);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 int32_t Date::GetYear() {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 return year;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44 int8_t Date::GetMonth() {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 return month;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 int8_t Date::GetDay() {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 return day;
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50 }
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52 QDate Date::GetAsQDate() {
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 return QDate(year, month, day);
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54 }