Mercurial > minori
annotate src/core/anime_season.cc @ 353:2f094656e775
sys/x11/settings: misc fixups
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sun, 14 Jul 2024 23:27:43 -0400 |
parents | 6b0768158dcd |
children |
rev | line source |
---|---|
281 | 1 #include "core/anime_season.h" |
327
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
2 #include "core/session.h" |
281 | 3 |
4 namespace Anime { | |
5 | |
327
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
6 static bool WinterStartsInDecember() { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
7 switch (session.config.service) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
8 case Service::MyAnimeList: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
9 return false; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
10 default: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
11 return true; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
12 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
13 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
14 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
15 static Season::Name GetSeasonForMonth(Date::Month month) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
16 if (WinterStartsInDecember()) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
17 switch (month) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
18 case Date::Month::Dec: case Date::Month::Jan: case Date::Month::Feb: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
19 return Season::Name::Winter; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
20 case Date::Month::Mar: case Date::Month::Apr: case Date::Month::May: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
21 return Season::Name::Spring; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
22 case Date::Month::Jun: case Date::Month::Jul: case Date::Month::Aug: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
23 return Season::Name::Summer; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
24 case Date::Month::Sep: case Date::Month::Oct: case Date::Month::Nov: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
25 return Season::Name::Autumn; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
26 default: return Season::Name::Unknown; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
27 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
28 } else { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
29 switch (month) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
30 case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
31 return Season::Name::Winter; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
32 case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
33 return Season::Name::Spring; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
34 case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
35 return Season::Name::Summer; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
36 case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec: |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
37 return Season::Name::Autumn; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
38 default: return Season::Name::Unknown; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
39 } |
281 | 40 } |
41 } | |
42 | |
327
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
43 Season::Season(Season::Name s, Date::Year y) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
44 season = s; |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
45 year = y; |
281 | 46 } |
327
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
47 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
48 Season::Season(const Date& date) { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
49 std::optional<Date::Month> month = date.GetMonth(); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
50 if (month) |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
51 season = GetSeasonForMonth(month.value()); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
52 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
53 std::optional<Date::Year> y = date.GetYear(); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
54 if (y) |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
55 year = y.value(); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
56 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
57 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
58 bool Season::operator==(const Season& o) const { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
59 return (season == o.season && year == o.year); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
60 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
61 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
62 bool Season::operator!=(const Season& o) const { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
63 return !(*this == o); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
64 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
65 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
66 bool Season::operator<(const Season& o) const { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
67 return std::tie(season, year) < std::tie(o.season, o.year); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
68 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
69 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
70 bool Season::operator>(const Season& o) const { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
71 return (o < *this); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
72 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
73 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
74 bool Season::operator<=(const Season& o) const { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
75 return !(o > *this); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
76 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
77 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
78 bool Season::operator>=(const Season& o) const { |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
79 return !(*this < o); |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
80 } |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
81 |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
82 Season& Season::operator++() { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
83 switch (season) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
84 case Season::Name::Winter: season = Season::Name::Spring; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
85 case Season::Name::Spring: season = Season::Name::Summer; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
86 case Season::Name::Summer: season = Season::Name::Autumn; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
87 case Season::Name::Autumn: season = Season::Name::Winter; year++; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
88 default: season = Season::Name::Unknown; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
89 } |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
90 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
91 return *this; |
327
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
92 } |
348
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
93 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
94 Season& Season::operator--() { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
95 switch (season) { |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
96 case Season::Name::Winter: season = Season::Name::Autumn; year--; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
97 case Season::Name::Spring: season = Season::Name::Winter; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
98 case Season::Name::Summer: season = Season::Name::Spring; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
99 case Season::Name::Autumn: season = Season::Name::Summer; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
100 default: season = Season::Name::Unknown; break; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
101 } |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
102 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
103 return *this; |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
104 } |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
105 |
6b0768158dcd
text: redesign almost every widget
Paper <paper@paper.us.eu.org>
parents:
327
diff
changeset
|
106 } |