From 78b8353eec0aa5c5a9fad2563162c2d786d922ce Mon Sep 17 00:00:00 2001 From: Oscar Hemelaar Date: Mon, 31 Jul 2023 18:14:11 +0200 Subject: [PATCH] hotfix: panic due to location object Shows this error message: panic: time: missing Location in call to Time.In This really doesn't feel like it should be the fix but somehow it does work, so I'll share that and hope someone who knows go can help provide a better fix --- server/command.go | 3 ++- server/occurrence.go | 4 ++-- server/scheduler.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/command.go b/server/command.go index 3c3e869..1f1759d 100755 --- a/server/command.go +++ b/server/command.go @@ -2,6 +2,7 @@ package main import ( "strings" + "time" "github.com/mattermost/mattermost-server/v6/model" "github.com/mattermost/mattermost-server/v6/plugin" @@ -31,7 +32,7 @@ func (p *Plugin) ExecuteCommand(c *plugin.Context, args *model.CommandArgs) (*mo } T, locale := p.translation(user) - location := p.location(user) + location, _ := time.LoadLocation(p.location(user).String()) command := strings.Trim(args.Command, " ") if strings.Trim(command, " ") == "/"+CommandTrigger { diff --git a/server/occurrence.go b/server/occurrence.go index d5a0ee5..95daf1a 100755 --- a/server/occurrence.go +++ b/server/occurrence.go @@ -592,7 +592,7 @@ func (p *Plugin) at(when string, user *model.User) (times []time.Time, err error func (p *Plugin) atEN(when string, user *model.User) (times []time.Time, err error) { T, _ := p.translation(user) - location := p.location(user) + location, _ := time.LoadLocation(p.location(user).String()) whenTrim := strings.Trim(when, " ") whenSplit := strings.Split(whenTrim, " ") @@ -1254,7 +1254,7 @@ func (p *Plugin) formatWhenEN(username string, when string, occurrence string, s return "" } T, _ := p.translation(user) - location := p.location(user) + location, _ := time.LoadLocation(p.location(user).String()) now := time.Now().In(location) t, _ := time.Parse(time.RFC3339, occurrence) diff --git a/server/scheduler.go b/server/scheduler.go index ed9d574..7e1e451 100755 --- a/server/scheduler.go +++ b/server/scheduler.go @@ -16,7 +16,7 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* return nil, uErr } T, _ := p.translation(user) - location := p.location(user) + location, _ := time.LoadLocation(p.location(user).String()) if pErr := p.ParseRequest(request); pErr != nil { p.API.LogError(pErr.Error())