Skip to content
Snippets Groups Projects

Refactor TradingHours struct and validation

Merged Daniel Naude requested to merge trading_hours into main
+ 5
8
@@ -325,8 +325,6 @@ func formatTimestampsWithTimeZoneInSlice(fieldValue reflect.Value, location *tim
return nil
}
// TradingHours represents an array of (StartTime,EndTime) pairs, one for each day of the week.
// The array is 0 indexed, with 0 being Sunday and 6 being Saturday and 7 being public holidays.
type TradingHours struct {
Monday TradingHoursDay `json:"monday"`
Tuesday TradingHoursDay `json:"tuesday"`
@@ -373,14 +371,9 @@ func (day TradingHoursDay) Validate() error {
return nil
}
if !TimeBefore(day.StartTime, day.EndTime) {
return errors.Error("start time must be before end time")
}
if len(day.StartTime) != 5 || len(day.EndTime) != 5 {
return errors.Error("time must be in the format HH:MM")
}
startHourMinSlice := strings.Split(day.StartTime, ":")
if len(startHourMinSlice) != 2 {
return errors.Error("time must be in the format HH:MM")
@@ -409,6 +402,10 @@ func (day TradingHoursDay) Validate() error {
return errors.Error("end minute must be 0, 30 or 59")
}
if !TimeBefore(day.StartTime, day.EndTime) {
return errors.Error("start time must be before end time")
}
return nil
}
@@ -460,7 +457,7 @@ type TradingHoursDay struct {
}
func (day TradingHoursDay) String() string {
if day.StartTime == "" && day.EndTime == "" {
if day.StartTime == "" || day.EndTime == "" {
return "Closed"
}
Loading