Skip to content
Snippets Groups Projects
Commit 637d8747 authored by Daniel Naude's avatar Daniel Naude
Browse files

Add a deepCopy to TradingHours String function to prevent side effects

parent c546f41b
Branches
Tags v1.214.0
No related merge requests found
...@@ -9,6 +9,7 @@ import ( ...@@ -9,6 +9,7 @@ import (
"github.com/araddon/dateparse" "github.com/araddon/dateparse"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors" "gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/errors"
"gitlab.bob.co.za/bob-public-utils/bobgroup-go-utils/utils"
) )
const TimeZoneString = "Africa/Johannesburg" const TimeZoneString = "Africa/Johannesburg"
...@@ -337,7 +338,8 @@ func (t TradingHours) Validate() error { ...@@ -337,7 +338,8 @@ func (t TradingHours) Validate() error {
func (t TradingHours) String() string { func (t TradingHours) String() string {
var result strings.Builder var result strings.Builder
const numberOfDaysInWeek = 7 const numberOfDaysInWeek = 7
weekdays, publicHolidays := t[:numberOfDaysInWeek], t[numberOfDaysInWeek] copyOfT := utils.DeepCopy(t).(TradingHours)
weekdays, publicHolidays := copyOfT[:numberOfDaysInWeek], copyOfT[numberOfDaysInWeek]
weekdays = append(weekdays, weekdays[0]) // Add the first day (Sunday) to the end because we want Monday to be first in the string weekdays = append(weekdays, weekdays[0]) // Add the first day (Sunday) to the end because we want Monday to be first in the string
rangeStartIndex := 1 rangeStartIndex := 1
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment