Skip to content

Commit 3a6e84c

Browse files
authored
Merge branch 'main' into filestore-test-server
2 parents 6c2400d + efa0bdd commit 3a6e84c

File tree

7 files changed

+1137
-366
lines changed

7 files changed

+1137
-366
lines changed

config/configuration.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,67 @@ 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) {
51+
5052
if loc == nil {
51-
panic("time: missing Location in call to NewTimeRangeInLocation")
53+
return nil, errors.New("time: missing Location in call to NewTimeRangeInLocation")
5254
}
5355

54-
return &TimeRange{startTime: start, endTime: end, loc: loc}
56+
return &TimeRange{
57+
startTime: start,
58+
endTime: end,
59+
weekdays: weekdays,
60+
loc: loc,
61+
}, nil
5562
}
5663

5764
// NewUTCWeekRange returns a weekly TimeRange.
58-
func NewUTCWeekRange(startTime, endTime TimeOfDay, startDay, endDay time.Weekday) *TimeRange {
65+
func NewUTCWeekRange(startTime, endTime TimeOfDay, startDay, endDay time.Weekday) (*TimeRange, error) {
5966
return NewWeekRangeInLocation(startTime, endTime, startDay, endDay, time.UTC)
6067
}
6168

6269
// 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)
70+
func NewWeekRangeInLocation(startTime, endTime TimeOfDay, startDay, endDay time.Weekday, loc *time.Location) (*TimeRange, error) {
71+
r, err := NewTimeRangeInLocation(startTime, endTime, []time.Weekday{}, loc)
72+
if err != nil {
73+
return nil, err
74+
}
6575
r.startDay = &startDay
6676
r.endDay = &endDay
6777

68-
return r
78+
return r, nil
6979
}
7080

7181
func (r *TimeRange) isInTimeRange(t time.Time) bool {
7282
t = t.In(r.loc)
7383
ts := NewTimeOfDay(t.Clock()).d
7484

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

0 commit comments

Comments
 (0)