From 9154ccf212fbf6d63558fe797f55f982ae21bd73 Mon Sep 17 00:00:00 2001 From: Primexz Date: Mon, 24 Jun 2024 18:13:17 +0200 Subject: [PATCH] fix: calculate correct next fiat deposit day --- bot/calculations.go | 14 +++++++++++--- bot/time.go | 4 ---- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bot/calculations.go b/bot/calculations.go index 8bad00f..2ecb427 100644 --- a/bot/calculations.go +++ b/bot/calculations.go @@ -7,10 +7,18 @@ import ( ) func computeNextFiatDepositDay() time.Time { - date := addMonthsToTime(1, time.Now()) + now := time.Now() - //get the first day of the month - return date.AddDate(0, 0, -date.Day()+1) + year := now.Year() + month := now.Month() + 1 + + if month > 12 { + month = 1 + year++ + } + + firstOfNextMonth := time.Date(year, month, 1, 0, 0, 0, 0, time.Local) + return firstOfNextMonth } func (b *Bot) calculateTimeOfNextOrder() { diff --git a/bot/time.go b/bot/time.go index 6b8a42a..f7c598e 100644 --- a/bot/time.go +++ b/bot/time.go @@ -5,10 +5,6 @@ import ( "time" ) -func addMonthsToTime(months int, time time.Time) time.Time { - return time.AddDate(0, months, 0) -} - func fmtDuration(d time.Duration) string { hour := int(d.Hours()) minute := int(d.Minutes()) % 60