Mercurial > minori
diff src/core/date.cc @ 196:f0ff06a45c42
date: use std::optional for values
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Thu, 07 Dec 2023 16:28:11 -0500 |
parents | 9613d72b097e |
children | c4ca035c565d |
line wrap: on
line diff
--- a/src/core/date.cc Thu Dec 07 11:14:01 2023 -0500 +++ b/src/core/date.cc Thu Dec 07 16:28:11 2023 -0500 @@ -45,43 +45,43 @@ } void Date::VoidYear() { - year.Void(); + year.reset(); } void Date::VoidMonth() { - month.Void(); + month.reset(); } void Date::VoidDay() { - day.Void(); + day.reset(); } void Date::SetYear(unsigned int y) { - year.Set(y); + year = y; } void Date::SetMonth(unsigned int m) { - month.Set(CLAMP(m, 1U, 12U)); + month = CLAMP(m, 1U, 12U); } void Date::SetDay(unsigned int d) { - day.Set(CLAMP(d, 1U, 31U)); + day = CLAMP(d, 1U, 31U); } unsigned int Date::GetYear() const { - return year.Get(); + return year.value_or(-1); } unsigned int Date::GetMonth() const { - return month.Get(); + return month.value_or(-1); } unsigned int Date::GetDay() const { - return day.Get(); + return day.value_or(-1); } bool Date::IsValid() const { - return year.Enabled() && month.Enabled() && day.Enabled(); + return year.has_value() && month.has_value() && day.has_value(); } bool Date::operator<(const Date& other) const { @@ -108,24 +108,24 @@ * so we do our best and return what we can. */ - return QDate(year.Enabled() ? year.Get() : 2000, month.Enabled() ? month.Get() : 1, day.Enabled() ? day.Get() : 1); + return QDate(year.value_or(2000), month.value_or(1), day.value_or(1)); } nlohmann::json Date::GetAsAniListJson() const { nlohmann::json result = {}; - if (year.Enabled()) - result["year"] = year.Get(); + if (year.has_value()) + result["year"] = year.value(); else result["year"] = nullptr; - if (month.Enabled()) - result["month"] = month.Get(); + if (month.has_value()) + result["month"] = month.value(); else result["month"] = nullptr; - if (day.Enabled()) - result["day"] = day.Get(); + if (day.has_value()) + result["day"] = day.value(); else result["day"] = nullptr;