From 9f8af1c290f0455a251454545211f4551cdbd612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Wed, 4 Dec 2024 20:44:16 +0100 Subject: [PATCH] Fix: CET timestamps in the bot command When some hour was set via bot, it stored it as GMT, not as CET. Fixed for that cases: - ON 20:00 - ON 2024-12-04 20:00 --- internal/bot/controller.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/internal/bot/controller.go b/internal/bot/controller.go index b3ca5c0..dd13ba2 100644 --- a/internal/bot/controller.go +++ b/internal/bot/controller.go @@ -23,7 +23,8 @@ func ProcesarMensaje(update tgbotapi.Update, db *gorm.DB) { return } - now := time.Now() + loc, _ := time.LoadLocation("CET") + now := time.Now().In(loc) if len(parts) == 1 { // Sin fecha ni hora -> usar timestamp actual timestamp = now @@ -52,19 +53,19 @@ func ProcesarMensaje(update tgbotapi.Update, db *gorm.DB) { // Ambos fecha y hora proporcionados timestamp = time.Date( parsedDate.Year(), parsedDate.Month(), parsedDate.Day(), - parsedTime.Hour(), parsedTime.Minute(), 0, 0, now.Location(), + parsedTime.Hour(), parsedTime.Minute(), 0, 0, loc, ) } else if !parsedDate.IsZero() { // Solo fecha proporcionada -> usar las 00:00 como hora timestamp = time.Date( parsedDate.Year(), parsedDate.Month(), parsedDate.Day(), - 0, 0, 0, 0, now.Location(), + 0, 0, 0, 0, loc, ) } else if !parsedTime.IsZero() { // Solo hora proporcionada -> usar fecha actual timestamp = time.Date( now.Year(), now.Month(), now.Day(), - parsedTime.Hour(), parsedTime.Minute(), 0, 0, now.Location(), + parsedTime.Hour(), parsedTime.Minute(), 0, 0, loc, ) } else { log.Println("Formato de entrada inválido:", parts[1:])