diff src/core/date.cc @ 197:c4ca035c565d

*: misc. patches
author Paper <mrpapersonic@gmail.com>
date Fri, 08 Dec 2023 11:19:54 -0500
parents f0ff06a45c42
children bc1ae1810855
line wrap: on
line diff
--- a/src/core/date.cc	Thu Dec 07 16:28:11 2023 -0500
+++ b/src/core/date.cc	Fri Dec 08 11:19:54 2023 -0500
@@ -8,11 +8,6 @@
 
 /* An implementation of AniList's "fuzzy date" */
 
-template<typename T>
-bool CLAMP(T x, T low, T high) {
-	return std::max(low, std::min(high, x));
-}
-
 Date::Date() {
 }
 
@@ -57,52 +52,33 @@
 }
 
 void Date::SetYear(unsigned int y) {
-	year = y;
+	year.emplace(y);
 }
 
 void Date::SetMonth(unsigned int m) {
-	month = CLAMP(m, 1U, 12U);
+	month.emplace(std::clamp(m, 1U, 12U));
 }
 
 void Date::SetDay(unsigned int d) {
-	day = CLAMP(d, 1U, 31U);
+	day.emplace(std::clamp(d, 1U, 31U));
 }
 
-unsigned int Date::GetYear() const {
-	return year.value_or(-1);
+std::optional<unsigned int> Date::GetYear() const {
+	return year;
 }
 
-unsigned int Date::GetMonth() const {
-	return month.value_or(-1);
+std::optional<unsigned int> Date::GetMonth() const {
+	return month;
 }
 
-unsigned int Date::GetDay() const {
-	return day.value_or(-1);
+std::optional<unsigned int> Date::GetDay() const {
+	return day;
 }
 
 bool Date::IsValid() const {
 	return year.has_value() && month.has_value() && day.has_value();
 }
 
-bool Date::operator<(const Date& other) const {
-	const unsigned int y = GetYear(), m = GetMonth(), d = GetDay();
-	const unsigned int o_y = other.GetYear(), o_m = other.GetMonth(), o_d = other.GetDay();
-
-	return (y < o_y && m < o_m && d < 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() const {
 	/* QDate doesn't support "missing" values (for good reason),
 	 * so we do our best and return what we can.