From 28c3809036ef6d0f406c6408e35f8ea7aba42314 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Sat, 23 Jan 2021 20:18:10 +0530 Subject: [PATCH] MM-31353: Fix incorrect time truncation logic (#16776) As mentioned in the documentation: > Truncate operates on the time as an absolute duration since the zero time; it does not operate on the presentation form of the time. Thus, Truncate(Hour) may return a time with a non-zero minute, depending on the time's Location. As a result, truncating for anything more than an hour is buggy and should not be done. The correct way is to construct the date object using the day, month and year. https://mattermost.atlassian.net/browse/MM-31353 ```release-notes Fixed a bug in product notices where a date constraint might fail to match, and would lead to the notice not being fetched ``` --- app/product_notices.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/product_notices.go b/app/product_notices.go index 2586cc5c6c..7e91cc4628 100644 --- a/app/product_notices.go +++ b/app/product_notices.go @@ -83,12 +83,13 @@ func noticeMatchesConditions(config *model.Config, preferences store.PreferenceS // check if notice date range matches current if cnd.DisplayDate != nil { - now := time.Now().UTC().Truncate(time.Hour * 24) + y, m, d := time.Now().UTC().Date() + trunc := time.Date(y, m, d, 0, 0, 0, 0, time.UTC) c, err2 := date_constraints.NewConstraint(*cnd.DisplayDate) if err2 != nil { return false, errors.Wrapf(err2, "Cannot parse date range %s", *cnd.DisplayDate) } - if !c.Check(&now) { + if !c.Check(&trunc) { return false, nil } }