From b434c4172fb385312d57cf1909a4ac219fb2339d Mon Sep 17 00:00:00 2001 From: nquidox Date: Fri, 26 Sep 2025 20:15:51 +0300 Subject: [PATCH] factor out --- internal/api/merch/helper.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 internal/api/merch/helper.go diff --git a/internal/api/merch/helper.go b/internal/api/merch/helper.go new file mode 100644 index 0000000..704cbbd --- /dev/null +++ b/internal/api/merch/helper.go @@ -0,0 +1,19 @@ +package merch + +import ( + "strconv" + "time" +) + +func getPeriod(days string) time.Time { + daysInt, err := strconv.Atoi(days) + if err != nil { + daysInt = 7 + } + + if daysInt > 365 { + daysInt = 7 + } + + return time.Now().UTC().Add(-(time.Duration(daysInt) * time.Hour * 24)) +}