comparison 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
comparison
equal deleted inserted replaced
326:10096c5489e3 327:b5d6c27c308f
1 #include "core/anime_season.h" 1 #include "core/anime_season.h"
2 #include "core/session.h"
2 3
3 namespace Anime { 4 namespace Anime {
4 5
5 SeriesSeason GetSeasonForMonth(Date::Month month) { 6 static bool WinterStartsInDecember() {
6 switch (month) { 7 switch (session.config.service) {
7 case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: 8 case Service::MyAnimeList:
8 default: 9 return false;
9 return SeriesSeason::Winter; 10 default:
10 case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun: 11 return true;
11 return SeriesSeason::Spring;
12 case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep:
13 return SeriesSeason::Summer;
14 case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec:
15 return SeriesSeason::Fall;
16 } 12 }
17 } 13 }
18 14
15 static Season::Name GetSeasonForMonth(Date::Month month) {
16 if (WinterStartsInDecember()) {
17 switch (month) {
18 case Date::Month::Dec: case Date::Month::Jan: case Date::Month::Feb:
19 return Season::Name::Winter;
20 case Date::Month::Mar: case Date::Month::Apr: case Date::Month::May:
21 return Season::Name::Spring;
22 case Date::Month::Jun: case Date::Month::Jul: case Date::Month::Aug:
23 return Season::Name::Summer;
24 case Date::Month::Sep: case Date::Month::Oct: case Date::Month::Nov:
25 return Season::Name::Autumn;
26 default: return Season::Name::Unknown;
27 }
28 } else {
29 switch (month) {
30 case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar:
31 return Season::Name::Winter;
32 case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun:
33 return Season::Name::Spring;
34 case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep:
35 return Season::Name::Summer;
36 case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec:
37 return Season::Name::Autumn;
38 default: return Season::Name::Unknown;
39 }
40 }
19 } 41 }
42
43 Season::Season(Season::Name s, Date::Year y) {
44 season = s;
45 year = y;
46 }
47
48 Season::Season(const Date& date) {
49 std::optional<Date::Month> month = date.GetMonth();
50 if (month)
51 season = GetSeasonForMonth(month.value());
52
53 std::optional<Date::Year> y = date.GetYear();
54 if (y)
55 year = y.value();
56 }
57
58 bool Season::operator==(const Season& o) const {
59 return (season == o.season && year == o.year);
60 }
61
62 bool Season::operator!=(const Season& o) const {
63 return !(*this == o);
64 }
65
66 bool Season::operator<(const Season& o) const {
67 return std::tie(season, year) < std::tie(o.season, o.year);
68 }
69
70 bool Season::operator>(const Season& o) const {
71 return (o < *this);
72 }
73
74 bool Season::operator<=(const Season& o) const {
75 return !(o > *this);
76 }
77
78 bool Season::operator>=(const Season& o) const {
79 return !(*this < o);
80 }
81
82 }