Mercurial > minori
diff src/core/date.cc @ 198:bc1ae1810855
dep/animia: switch from using classes to global functions
the old idea was ok, but sort of hackish; this method doesn't use classes
at all, and this way (especially important!) we can do wayland stuff AND x11
at the same time, which wasn't really possible without stupid workarounds in
the other method
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Sun, 24 Dec 2023 02:59:42 -0500 |
parents | c4ca035c565d |
children | 862d0d8619f6 |
line wrap: on
line diff
--- a/src/core/date.cc Fri Dec 08 11:19:54 2023 -0500 +++ b/src/core/date.cc Sun Dec 24 02:59:42 2023 -0500 @@ -31,12 +31,13 @@ /* NOTE: this constructor is made for use with AniList FuzzyDate-style JSON. In the future, some other methods may be parsed and whatnot if necessary. */ - if (json.contains("year") && json.at("year").is_number()) - SetYear(json.at("year").get<unsigned int>()); - if (json.contains("month") && json.at("month").is_number()) - SetMonth(json.at("month").get<unsigned int>()); - if (json.contains("day") && json.at("day").is_number()) - SetDay(json.at("day").get<unsigned int>()); + + if (json.contains("/year"_json_pointer) && json.at("/year"_json_pointer).is_number()) + SetYear(json.at("/year"_json_pointer).get<unsigned int>()); + if (json.contains("/month"_json_pointer) && json.at("/month"_json_pointer).is_number()) + SetMonth(json.at("/month"_json_pointer).get<unsigned int>()); + if (json.contains("/day"_json_pointer) && json.at("/day"_json_pointer).is_number()) + SetDay(json.at("/day"_json_pointer).get<unsigned int>()); } void Date::VoidYear() { @@ -88,22 +89,9 @@ } nlohmann::json Date::GetAsAniListJson() const { - nlohmann::json result = {}; - - if (year.has_value()) - result["year"] = year.value(); - else - result["year"] = nullptr; - - if (month.has_value()) - result["month"] = month.value(); - else - result["month"] = nullptr; - - if (day.has_value()) - result["day"] = day.value(); - else - result["day"] = nullptr; - - return result; + return { + {"year", year}, + {"month", month}, + {"day", day} + }; }