From 54564f8333364eb5e720e525ea288591f2a3ad6a Mon Sep 17 00:00:00 2001 From: ccremer Date: Tue, 8 Nov 2022 16:41:57 +0100 Subject: [PATCH] Fix crash for employee report --- pkg/web/employeereport/employeereport_controller.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/web/employeereport/employeereport_controller.go b/pkg/web/employeereport/employeereport_controller.go index 9181327..cd7fdd2 100644 --- a/pkg/web/employeereport/employeereport_controller.go +++ b/pkg/web/employeereport/employeereport_controller.go @@ -164,9 +164,10 @@ func (c *EmployeeReport) fetchLeaves(ctx context.Context) error { } func (c *EmployeeReport) calculateMonthlyReport(_ context.Context) error { + tz := c.getTimeZone() reporter := timesheet.NewReporter(c.Attendances, c.Leaves, &c.Employee, c.Contracts). SetRange(c.Start, c.Stop.AddDate(0, 0, 1)). - SetTimeZone(controller.TimezoneOrDefault(c.NextPayslip.TimeZone, controller.DefaultTimeZone)) + SetTimeZone(tz) report, err := reporter.CalculateReport() c.Result = report return err @@ -194,3 +195,12 @@ func (c *EmployeeReport) ignoreNoContractFound(_ context.Context, err error) err } return err } + +func (c *EmployeeReport) getTimeZone() *time.Location { + if c.NextPayslip != nil && !c.NextPayslip.TimeZone.IsEmpty() { + // timezone from payslip has precedence. + return c.NextPayslip.TimeZone.Location() + } + // last resort to default TZ. + return controller.DefaultTimeZone +}