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
This commit is contained in:
Óscar M. Lage 2024-12-04 20:44:16 +01:00
parent b4e38376ea
commit 9f8af1c290

View File

@ -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:])