Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kebien6020/0bfd54310b1a62ba880de9d15b7887b2 to your computer and use it in GitHub Desktop.
Save kebien6020/0bfd54310b1a62ba880de9d15b7887b2 to your computer and use it in GitHub Desktop.
int EstimateLastAiredEpisodeNumber(const Item& item) {
// Can't estimate for other types of anime
if (item.GetType() != kTv)
return 0;
// TV series air weekly, so the number of weeks that has passed since the day
// the series started airing gives us the last aired episode. Note that
// irregularities such as broadcasts being postponed due to sports events make
// this method unreliable.
const Date& date_start = item.GetDateStart();
if (date_start.year() && date_start.month() && date_start.day()) {
// To compensate for the fact that we don't know the airing hour,
// we substract one more day.
int date_diff = GetDateJapan() - date_start - 1;
if (date_diff > -1) {
const int episode_count = item.GetEpisodeCount();
const int number_of_weeks = date_diff / 7;
if (!IsValidEpisodeCount(episode_count) ||
number_of_weeks < episode_count) {
return number_of_weeks + 1;
} else {
return episode_count;
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment