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

Refactor TradingHours to allow for closed days where trading does not take place

parent d8e1d9cf
No related branches found
No related tags found
No related merge requests found
......@@ -289,6 +289,11 @@ func (t TradingHours) Validate() error {
}
for _, day := range t {
if day.StartTime == "" || day.EndTime == "" {
// Allow empty trading hours for a day to represent closed
continue
}
if !TimeBefore(day.StartTime, day.EndTime) {
return errors.Error("Start time must be before end time")
}
......@@ -336,6 +341,9 @@ func (t TradingHours) String() string {
rangeStartIndex := 1
for i := 1; i < len(t); i++ {
var times string
if t[i].StartTime != "" && t[i].EndTime != "" {
startTime, err := time.Parse("15:04", t[i].StartTime)
if err != nil {
return ""
......@@ -346,10 +354,13 @@ func (t TradingHours) String() string {
return ""
}
times := startTime.Format("3:04pm") + "-" + endTime.Format("3:04pm")
times = startTime.Format("3:04pm") + "-" + endTime.Format("3:04pm")
if t[i].StartTime == "00:00" && t[i].EndTime == "23:59" {
times = "All day"
}
} else {
times = "Closed"
}
// If we're at the last element or the next day doesn't have the same times, we end the current range
if i == len(t)-1 || t[i].StartTime != t[i+1].StartTime || t[i].EndTime != t[i+1].EndTime {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment