From 32649a83149b26853986c437d28e0ac49402cc18 Mon Sep 17 00:00:00 2001 From: Soulcramer Date: Thu, 5 Sep 2019 14:05:20 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Make=20anime=20with=20only=20start?= =?UTF-8?q?=20month=20available=20visible=20in=20list=20filtered=20by=20se?= =?UTF-8?q?asons?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arn/Anime.go | 2 +- arn/validate/Validate.go | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/arn/Anime.go b/arn/Anime.go index a4e6cbe3..a06478c4 100644 --- a/arn/Anime.go +++ b/arn/Anime.go @@ -289,7 +289,7 @@ func (anime *Anime) AverageColor() string { // Season returns the season the anime started airing in. func (anime *Anime) Season() string { - if !validate.Date(anime.StartDate) { + if !validate.Date(anime.StartDate) && !validate.YearMonth(anime.StartDate) { return "" } diff --git a/arn/validate/Validate.go b/arn/validate/Validate.go index 604d7f16..5d38d745 100644 --- a/arn/validate/Validate.go +++ b/arn/validate/Validate.go @@ -13,6 +13,9 @@ const ( // DateFormat is the format used for short dates that don't include the time. 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 = time.RFC3339 ) @@ -55,6 +58,16 @@ func Date(date string) bool { 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. func Email(email string) bool { // TODO: Add email check