Skip to content

Commit 4409144

Browse files
committed
Add Weekdays configuration option to sessions
Update TimeRange to include weekdays - add weekdays slice as field to TimeRange - update constructor to remove possible panic, instead return error - update tests now the TimeRange constructor now returns an error - convert tests to table test format Update sessionFactory to set weekdays property - update code that creates TimeRange to handle errors - read and set the Weekdays value if provided, erroring if it is given with StartDay/EndDay. Update session_test to handle timerange error
1 parent 7945e4b commit 4409144

File tree

7 files changed

+1130
-369
lines changed

7 files changed

+1130
-369
lines changed

config/configuration.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package config
22

33
//NOTE: Additions to this file should be made to both config/doc.go and http://www.quickfixgo.org/docs/
44

5-
//Const configuration settings
5+
// Const configuration settings
66
const (
77
BeginString string = "BeginString"
88
SenderCompID string = "SenderCompID"
@@ -35,6 +35,7 @@ const (
3535
EndTime string = "EndTime"
3636
StartDay string = "StartDay"
3737
EndDay string = "EndDay"
38+
Weekdays string = "Weekdays"
3839
TimeZone string = "TimeZone"
3940
DataDictionary string = "DataDictionary"
4041
TransportDataDictionary string = "TransportDataDictionary"

config/doc.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,22 @@ Time of day that this FIX session becomes deactivated. Valid Values:
8484
8585
StartDay
8686
87-
For week long sessions, the starting day of week for the session. Use in combination with StartTime. Valid Values:
87+
For week long sessions, the starting day of week for the session. Use in combination with StartTime. Incompatible with Weekdays. Valid Values:
8888
8989
Full day of week in English, or 3 letter abbreviation (i.e. Monday and Mon are valid)
9090
9191
EndDay
9292
93-
For week long sessions, the ending day of week for the session. Use in combination with EndTime. Valid Values:
93+
For week long sessions, the ending day of week for the session. Use in combination with EndTime. Incompatible with Weekdays. Valid Values:
9494
9595
Full day of week in English, or 3 letter abbreviation (i.e. Monday and Mon are valid)
9696
97+
Weekdays
98+
99+
For daily sessions that are only active on specific days of the week. Use in combination with StartTime and EndTime. Incompatible with StartDay and EndDay. Valid Values:
100+
101+
Comma delimited list of days of the week in English, or 3 letter abbreviation (e.g. "Monday,Tuesday,Wednesday" or "Mon,Tue,Wed" would both be valid values)
102+
97103
EnableLastMsgSeqNumProcessed
98104
99105
Add the last message sequence number processed in the header (optional tag 369). Valid Values:

internal/time_range.go

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,65 @@ func ParseTimeOfDay(str string) (TimeOfDay, error) {
3636
//TimeRange represents a time band in a given time zone
3737
type TimeRange struct {
3838
startTime, endTime TimeOfDay
39+
weekdays []time.Weekday
3940
startDay, endDay *time.Weekday
4041
loc *time.Location
4142
}
4243

4344
//NewUTCTimeRange returns a time range in UTC
44-
func NewUTCTimeRange(start, end TimeOfDay) *TimeRange {
45-
return NewTimeRangeInLocation(start, end, time.UTC)
45+
func NewUTCTimeRange(start, end TimeOfDay, weekdays []time.Weekday) (*TimeRange, error) {
46+
return NewTimeRangeInLocation(start, end, weekdays, time.UTC)
4647
}
4748

4849
//NewTimeRangeInLocation returns a time range in a given location
49-
func NewTimeRangeInLocation(start, end TimeOfDay, loc *time.Location) *TimeRange {
50+
func NewTimeRangeInLocation(start, end TimeOfDay, weekdays []time.Weekday, loc *time.Location) (*TimeRange, error) {
5051
if loc == nil {
51-
panic("time: missing Location in call to NewTimeRangeInLocation")
52+
return nil, errors.New("time: missing Location in call to NewTimeRangeInLocation")
5253
}
5354

54-
return &TimeRange{startTime: start, endTime: end, loc: loc}
55+
return &TimeRange{
56+
startTime: start,
57+
endTime: end,
58+
weekdays: weekdays,
59+
loc: loc,
60+
}, nil
5561
}
5662

5763
//NewUTCWeekRange returns a weekly TimeRange
58-
func NewUTCWeekRange(startTime, endTime TimeOfDay, startDay, endDay time.Weekday) *TimeRange {
64+
func NewUTCWeekRange(startTime, endTime TimeOfDay, startDay, endDay time.Weekday) (*TimeRange, error) {
5965
return NewWeekRangeInLocation(startTime, endTime, startDay, endDay, time.UTC)
6066
}
6167

62-
//NewWeekRangeInLocation returns a time range in a given location
63-
func NewWeekRangeInLocation(startTime, endTime TimeOfDay, startDay, endDay time.Weekday, loc *time.Location) *TimeRange {
64-
r := NewTimeRangeInLocation(startTime, endTime, loc)
68+
func NewWeekRangeInLocation(startTime, endTime TimeOfDay, startDay, endDay time.Weekday, loc *time.Location) (*TimeRange, error) {
69+
r, err := NewTimeRangeInLocation(startTime, endTime, []time.Weekday{}, loc)
70+
if err != nil {
71+
return nil, err
72+
}
6573
r.startDay = &startDay
6674
r.endDay = &endDay
6775

68-
return r
76+
return r, nil
6977
}
7078

7179
func (r *TimeRange) isInTimeRange(t time.Time) bool {
7280
t = t.In(r.loc)
7381
ts := NewTimeOfDay(t.Clock()).d
7482

83+
if len(r.weekdays) > 0 {
84+
found := false
85+
86+
for _, weekday := range r.weekdays {
87+
if t.Weekday() == weekday {
88+
found = true
89+
break
90+
}
91+
}
92+
93+
if !found {
94+
return false
95+
}
96+
}
97+
7598
if r.startTime.d < r.endTime.d {
7699
return r.startTime.d <= ts && ts <= r.endTime.d
77100
}

0 commit comments

Comments
 (0)