comparison src/core/date.cpp @ 63:3d2decf093bb

*: fix many clang warnings
author Paper <mrpapersonic@gmail.com>
date Sun, 01 Oct 2023 06:39:47 -0400
parents 75c804f713b2
children 6f7385bd334c
comparison
equal deleted inserted replaced
62:4c6dd5999b39 63:3d2decf093bb
1 #include "core/date.h" 1 #include "core/date.h"
2 #include "core/json.h" 2 #include "core/json.h"
3 #include <QDate> 3 #include <QDate>
4 #include <QDebug> 4 #include <QDebug>
5 #include <algorithm>
5 #include <cstdint> 6 #include <cstdint>
6 #include <tuple> 7 #include <tuple>
7 8
8 /* An implementation of AniList's "fuzzy date" */ 9 /* An implementation of AniList's "fuzzy date" */
9 10
10 #define MIN(A, B) \ 11 #define CLAMP(x, low, high) (std::max(low, std::min(high, x)))
11 ({ \
12 __typeof__(A) __a = (A); \
13 __typeof__(B) __b = (B); \
14 __a < __b ? __a : __b; \
15 })
16 #define MAX(A, B) \
17 ({ \
18 __typeof__(A) __a = (A); \
19 __typeof__(B) __b = (B); \
20 __a < __b ? __b : __a; \
21 })
22
23 #define CLAMP(x, low, high) \
24 ({ \
25 __typeof__(x) __x = (x); \
26 __typeof__(low) __low = (low); \
27 __typeof__(high) __high = (high); \
28 __x > __high ? __high : (__x < __low ? __low : __x); \
29 })
30 12
31 Date::Date() { 13 Date::Date() {
32 } 14 }
33 15
34 Date::Date(unsigned int y) { 16 Date::Date(unsigned int y) {
58 void Date::VoidDay() { 40 void Date::VoidDay() {
59 day.reset(); 41 day.reset();
60 } 42 }
61 43
62 void Date::SetYear(unsigned int y) { 44 void Date::SetYear(unsigned int y) {
63 year.reset(new unsigned int(MAX(0U, y))); 45 year.reset(new unsigned int(y));
64 } 46 }
65 47
66 void Date::SetMonth(unsigned int m) { 48 void Date::SetMonth(unsigned int m) {
67 month.reset(new unsigned int(CLAMP(m, 1U, 12U))); 49 month.reset(new unsigned int(CLAMP(m, 1U, 12U)));
68 } 50 }