Mercurial > minori
comparison src/core/anime_season.cc @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
| author | Paper <paper@tflc.us> |
|---|---|
| date | Fri, 25 Jul 2025 10:16:02 -0400 |
| parents | 6b0768158dcd |
| children | 963047512d34 |
comparison
equal
deleted
inserted
replaced
| 368:6d37a998cf91 | 369:47c9f8502269 |
|---|---|
| 1 #include "core/anime_season.h" | 1 #include "core/anime_season.h" |
| 2 #include "core/session.h" | 2 #include "core/session.h" |
| 3 | 3 |
| 4 namespace Anime { | 4 namespace Anime { |
| 5 | 5 |
| 6 static bool WinterStartsInDecember() { | 6 static bool WinterStartsInDecember() |
| 7 { | |
| 7 switch (session.config.service) { | 8 switch (session.config.service) { |
| 8 case Service::MyAnimeList: | 9 case Service::MyAnimeList: return false; |
| 9 return false; | 10 default: return true; |
| 10 default: | |
| 11 return true; | |
| 12 } | 11 } |
| 13 } | 12 } |
| 14 | 13 |
| 15 static Season::Name GetSeasonForMonth(Date::Month month) { | 14 static Season::Name GetSeasonForMonth(Date::Month month) |
| 15 { | |
| 16 if (WinterStartsInDecember()) { | 16 if (WinterStartsInDecember()) { |
| 17 switch (month) { | 17 switch (month) { |
| 18 case Date::Month::Dec: case Date::Month::Jan: case Date::Month::Feb: | 18 case Date::Month::Dec: |
| 19 return Season::Name::Winter; | 19 case Date::Month::Jan: |
| 20 case Date::Month::Mar: case Date::Month::Apr: case Date::Month::May: | 20 case Date::Month::Feb: return Season::Name::Winter; |
| 21 return Season::Name::Spring; | 21 case Date::Month::Mar: |
| 22 case Date::Month::Jun: case Date::Month::Jul: case Date::Month::Aug: | 22 case Date::Month::Apr: |
| 23 return Season::Name::Summer; | 23 case Date::Month::May: return Season::Name::Spring; |
| 24 case Date::Month::Sep: case Date::Month::Oct: case Date::Month::Nov: | 24 case Date::Month::Jun: |
| 25 return Season::Name::Autumn; | 25 case Date::Month::Jul: |
| 26 case Date::Month::Aug: return Season::Name::Summer; | |
| 27 case Date::Month::Sep: | |
| 28 case Date::Month::Oct: | |
| 29 case Date::Month::Nov: return Season::Name::Autumn; | |
| 26 default: return Season::Name::Unknown; | 30 default: return Season::Name::Unknown; |
| 27 } | 31 } |
| 28 } else { | 32 } else { |
| 29 switch (month) { | 33 switch (month) { |
| 30 case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: | 34 case Date::Month::Jan: |
| 31 return Season::Name::Winter; | 35 case Date::Month::Feb: |
| 32 case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun: | 36 case Date::Month::Mar: return Season::Name::Winter; |
| 33 return Season::Name::Spring; | 37 case Date::Month::Apr: |
| 34 case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep: | 38 case Date::Month::May: |
| 35 return Season::Name::Summer; | 39 case Date::Month::Jun: return Season::Name::Spring; |
| 36 case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec: | 40 case Date::Month::Jul: |
| 37 return Season::Name::Autumn; | 41 case Date::Month::Aug: |
| 42 case Date::Month::Sep: return Season::Name::Summer; | |
| 43 case Date::Month::Oct: | |
| 44 case Date::Month::Nov: | |
| 45 case Date::Month::Dec: return Season::Name::Autumn; | |
| 38 default: return Season::Name::Unknown; | 46 default: return Season::Name::Unknown; |
| 39 } | 47 } |
| 40 } | 48 } |
| 41 } | 49 } |
| 42 | 50 |
| 43 Season::Season(Season::Name s, Date::Year y) { | 51 Season::Season(Season::Name s, Date::Year y) |
| 52 { | |
| 44 season = s; | 53 season = s; |
| 45 year = y; | 54 year = y; |
| 46 } | 55 } |
| 47 | 56 |
| 48 Season::Season(const Date& date) { | 57 Season::Season(const Date &date) |
| 58 { | |
| 49 std::optional<Date::Month> month = date.GetMonth(); | 59 std::optional<Date::Month> month = date.GetMonth(); |
| 50 if (month) | 60 if (month) |
| 51 season = GetSeasonForMonth(month.value()); | 61 season = GetSeasonForMonth(month.value()); |
| 52 | 62 |
| 53 std::optional<Date::Year> y = date.GetYear(); | 63 std::optional<Date::Year> y = date.GetYear(); |
| 54 if (y) | 64 if (y) |
| 55 year = y.value(); | 65 year = y.value(); |
| 56 } | 66 } |
| 57 | 67 |
| 58 bool Season::operator==(const Season& o) const { | 68 bool Season::operator==(const Season &o) const |
| 69 { | |
| 59 return (season == o.season && year == o.year); | 70 return (season == o.season && year == o.year); |
| 60 } | 71 } |
| 61 | 72 |
| 62 bool Season::operator!=(const Season& o) const { | 73 bool Season::operator!=(const Season &o) const |
| 74 { | |
| 63 return !(*this == o); | 75 return !(*this == o); |
| 64 } | 76 } |
| 65 | 77 |
| 66 bool Season::operator<(const Season& o) const { | 78 bool Season::operator<(const Season &o) const |
| 79 { | |
| 67 return std::tie(season, year) < std::tie(o.season, o.year); | 80 return std::tie(season, year) < std::tie(o.season, o.year); |
| 68 } | 81 } |
| 69 | 82 |
| 70 bool Season::operator>(const Season& o) const { | 83 bool Season::operator>(const Season &o) const |
| 84 { | |
| 71 return (o < *this); | 85 return (o < *this); |
| 72 } | 86 } |
| 73 | 87 |
| 74 bool Season::operator<=(const Season& o) const { | 88 bool Season::operator<=(const Season &o) const |
| 89 { | |
| 75 return !(o > *this); | 90 return !(o > *this); |
| 76 } | 91 } |
| 77 | 92 |
| 78 bool Season::operator>=(const Season& o) const { | 93 bool Season::operator>=(const Season &o) const |
| 94 { | |
| 79 return !(*this < o); | 95 return !(*this < o); |
| 80 } | 96 } |
| 81 | 97 |
| 82 Season& Season::operator++() { | 98 Season &Season::operator++() |
| 99 { | |
| 83 switch (season) { | 100 switch (season) { |
| 84 case Season::Name::Winter: season = Season::Name::Spring; break; | 101 case Season::Name::Winter: season = Season::Name::Spring; break; |
| 85 case Season::Name::Spring: season = Season::Name::Summer; break; | 102 case Season::Name::Spring: season = Season::Name::Summer; break; |
| 86 case Season::Name::Summer: season = Season::Name::Autumn; break; | 103 case Season::Name::Summer: season = Season::Name::Autumn; break; |
| 87 case Season::Name::Autumn: season = Season::Name::Winter; year++; break; | 104 case Season::Name::Autumn: |
| 105 season = Season::Name::Winter; | |
| 106 year++; | |
| 107 break; | |
| 88 default: season = Season::Name::Unknown; break; | 108 default: season = Season::Name::Unknown; break; |
| 89 } | 109 } |
| 90 | 110 |
| 91 return *this; | 111 return *this; |
| 92 } | 112 } |
| 93 | 113 |
| 94 Season& Season::operator--() { | 114 Season &Season::operator--() |
| 115 { | |
| 95 switch (season) { | 116 switch (season) { |
| 96 case Season::Name::Winter: season = Season::Name::Autumn; year--; break; | 117 case Season::Name::Winter: |
| 118 season = Season::Name::Autumn; | |
| 119 year--; | |
| 120 break; | |
| 97 case Season::Name::Spring: season = Season::Name::Winter; break; | 121 case Season::Name::Spring: season = Season::Name::Winter; break; |
| 98 case Season::Name::Summer: season = Season::Name::Spring; break; | 122 case Season::Name::Summer: season = Season::Name::Spring; break; |
| 99 case Season::Name::Autumn: season = Season::Name::Summer; break; | 123 case Season::Name::Autumn: season = Season::Name::Summer; break; |
| 100 default: season = Season::Name::Unknown; break; | 124 default: season = Season::Name::Unknown; break; |
| 101 } | 125 } |
| 102 | 126 |
| 103 return *this; | 127 return *this; |
| 104 } | 128 } |
| 105 | 129 |
| 106 } | 130 } // namespace Anime |
