Mercurial > minori
view 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 |
line wrap: on
line source
#include "core/anime_season.h" #include "core/session.h" namespace Anime { static bool WinterStartsInDecember() { switch (session.config.service) { case Service::MyAnimeList: return false; default: return true; } } static Season::Name GetSeasonForMonth(Date::Month month) { if (WinterStartsInDecember()) { switch (month) { case Date::Month::Dec: case Date::Month::Jan: case Date::Month::Feb: return Season::Name::Winter; case Date::Month::Mar: case Date::Month::Apr: case Date::Month::May: return Season::Name::Spring; case Date::Month::Jun: case Date::Month::Jul: case Date::Month::Aug: return Season::Name::Summer; case Date::Month::Sep: case Date::Month::Oct: case Date::Month::Nov: return Season::Name::Autumn; default: return Season::Name::Unknown; } } else { switch (month) { case Date::Month::Jan: case Date::Month::Feb: case Date::Month::Mar: return Season::Name::Winter; case Date::Month::Apr: case Date::Month::May: case Date::Month::Jun: return Season::Name::Spring; case Date::Month::Jul: case Date::Month::Aug: case Date::Month::Sep: return Season::Name::Summer; case Date::Month::Oct: case Date::Month::Nov: case Date::Month::Dec: return Season::Name::Autumn; default: return Season::Name::Unknown; } } } Season::Season(Season::Name s, Date::Year y) { season = s; year = y; } Season::Season(const Date& date) { std::optional<Date::Month> month = date.GetMonth(); if (month) season = GetSeasonForMonth(month.value()); std::optional<Date::Year> y = date.GetYear(); if (y) year = y.value(); } bool Season::operator==(const Season& o) const { return (season == o.season && year == o.year); } bool Season::operator!=(const Season& o) const { return !(*this == o); } bool Season::operator<(const Season& o) const { return std::tie(season, year) < std::tie(o.season, o.year); } bool Season::operator>(const Season& o) const { return (o < *this); } bool Season::operator<=(const Season& o) const { return !(o > *this); } bool Season::operator>=(const Season& o) const { return !(*this < o); } }