comparison 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
comparison
equal deleted inserted replaced
197:c4ca035c565d 198:bc1ae1810855
29 29
30 Date::Date(const nlohmann::json& json) { 30 Date::Date(const nlohmann::json& json) {
31 /* NOTE: this constructor is made for use with 31 /* NOTE: this constructor is made for use with
32 AniList FuzzyDate-style JSON. In the future, some other 32 AniList FuzzyDate-style JSON. In the future, some other
33 methods may be parsed and whatnot if necessary. */ 33 methods may be parsed and whatnot if necessary. */
34 if (json.contains("year") && json.at("year").is_number()) 34
35 SetYear(json.at("year").get<unsigned int>()); 35 if (json.contains("/year"_json_pointer) && json.at("/year"_json_pointer).is_number())
36 if (json.contains("month") && json.at("month").is_number()) 36 SetYear(json.at("/year"_json_pointer).get<unsigned int>());
37 SetMonth(json.at("month").get<unsigned int>()); 37 if (json.contains("/month"_json_pointer) && json.at("/month"_json_pointer).is_number())
38 if (json.contains("day") && json.at("day").is_number()) 38 SetMonth(json.at("/month"_json_pointer).get<unsigned int>());
39 SetDay(json.at("day").get<unsigned int>()); 39 if (json.contains("/day"_json_pointer) && json.at("/day"_json_pointer).is_number())
40 SetDay(json.at("/day"_json_pointer).get<unsigned int>());
40 } 41 }
41 42
42 void Date::VoidYear() { 43 void Date::VoidYear() {
43 year.reset(); 44 year.reset();
44 } 45 }
86 87
87 return QDate(year.value_or(2000), month.value_or(1), day.value_or(1)); 88 return QDate(year.value_or(2000), month.value_or(1), day.value_or(1));
88 } 89 }
89 90
90 nlohmann::json Date::GetAsAniListJson() const { 91 nlohmann::json Date::GetAsAniListJson() const {
91 nlohmann::json result = {}; 92 return {
92 93 {"year", year},
93 if (year.has_value()) 94 {"month", month},
94 result["year"] = year.value(); 95 {"day", day}
95 else 96 };
96 result["year"] = nullptr;
97
98 if (month.has_value())
99 result["month"] = month.value();
100 else
101 result["month"] = nullptr;
102
103 if (day.has_value())
104 result["day"] = day.value();
105 else
106 result["day"] = nullptr;
107
108 return result;
109 } 97 }