Mercurial > minori
annotate src/core/anime_season.cc @ 327:b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
ToLocalString has also been altered to take in both season
and year because lots of locales actually treat formatting
seasons differently! most notably is Russian which adds a
suffix at the end to notate seasons(??)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 13 Jun 2024 01:49:18 -0400 |
parents | 10096c5489e3 |
children | 6b0768158dcd |
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 |
b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
Paper <paper@paper.us.eu.org>
parents:
326
diff
changeset
|
82 } |