Merge pull request #237 from soulcramer/show_anime_with_incomplete_date

Make anime with only start month available visible in list filtered by seasons
This commit is contained in:
Eduard Urbach 2019-09-06 08:18:19 +09:00 committed by GitHub
commit 0aa0a5ad4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -289,7 +289,7 @@ func (anime *Anime) AverageColor() string {
// Season returns the season the anime started airing in. // Season returns the season the anime started airing in.
func (anime *Anime) Season() string { func (anime *Anime) Season() string {
if !validate.Date(anime.StartDate) { if !validate.Date(anime.StartDate) && !validate.YearMonth(anime.StartDate) {
return "" return ""
} }

View File

@ -13,6 +13,9 @@ const (
// DateFormat is the format used for short dates that don't include the time. // DateFormat is the format used for short dates that don't include the time.
DateFormat = "2006-01-02" DateFormat = "2006-01-02"
// YearMonthFormat is the format used for validating dates that include the year and month.
YearMonthFormat = "2006-01"
// DateTimeFormat is the format used for long dates that include the time. // DateTimeFormat is the format used for long dates that include the time.
DateTimeFormat = time.RFC3339 DateTimeFormat = time.RFC3339
) )
@ -55,6 +58,16 @@ func Date(date string) bool {
return err == nil return err == nil
} }
// YearMonth tells you whether the date contain only the year and the month.
func YearMonth(date string) bool {
if date == "" || strings.HasPrefix(date, "0001") {
return false
}
_, err := time.Parse(YearMonthFormat, date)
return err == nil
}
// Email tests if the given email address is valid. // Email tests if the given email address is valid.
func Email(email string) bool { func Email(email string) bool {
// TODO: Add email check // TODO: Add email check