Skip to content

Commit

Permalink
Merge pull request connamara#854 from gbirchmeier/weekdaysFixes
Browse files Browse the repository at this point in the history
fix warnings/release notes for Weekdays setting
  • Loading branch information
gbirchmeier authored May 29, 2024
2 parents c609125 + 08ddfc3 commit 0758ce0
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
26 changes: 13 additions & 13 deletions QuickFIXn/SessionSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class SessionSchedule
public DayOfWeek? EndDay { get; }

private readonly bool _isWeekdaysSession;
private readonly HashSet<DayOfWeek> _weekdays;
private readonly HashSet<DayOfWeek> _weekdays = new();

public bool NonStopSession { get; }

Expand Down Expand Up @@ -90,7 +90,7 @@ public DateTime NextEndTime(DateTime utc)
if (NonStopSession)
throw new InvalidOperationException("NonStopSession is set; this statement should be unreachable");

TimeSpan vEndTime = EndTime ?? throw new QuickFix.ConfigError("EndTime is null");
TimeSpan vEndTime = EndTime ?? throw new ConfigError("EndTime is null");

if (utc.Kind != DateTimeKind.Utc)
throw new ArgumentException("Only UTC time is supported", nameof(utc));
Expand Down Expand Up @@ -133,10 +133,10 @@ private bool CheckDay(DateTime dt)
if (NonStopSession)
throw new InvalidOperationException("NonStopSession is set; this statement should be unreachable");

DayOfWeek vStartDay = StartDay ?? throw new QuickFix.ConfigError("StartDay is null");
DayOfWeek vEndDay = EndDay ?? throw new QuickFix.ConfigError("EndDay is null");
TimeSpan vStartTime = StartTime ?? throw new QuickFix.ConfigError("StartTime is null");
TimeSpan vEndTime = EndTime ?? throw new QuickFix.ConfigError("EndTime is null");
DayOfWeek vStartDay = StartDay ?? throw new ConfigError("StartDay is null");
DayOfWeek vEndDay = EndDay ?? throw new ConfigError("EndDay is null");
TimeSpan vStartTime = StartTime ?? throw new ConfigError("StartTime is null");
TimeSpan vEndTime = EndTime ?? throw new ConfigError("EndTime is null");

if (vStartDay < vEndDay)
{
Expand Down Expand Up @@ -177,8 +177,8 @@ private bool CheckTime(TimeSpan time)
if (NonStopSession)
return true;

TimeSpan vStartTime = StartTime ?? throw new QuickFix.ConfigError("StartTime is null");
TimeSpan vEndTime = EndTime ?? throw new QuickFix.ConfigError("EndTime is null");
TimeSpan vStartTime = StartTime ?? throw new ConfigError("StartTime is null");
TimeSpan vEndTime = EndTime ?? throw new ConfigError("EndTime is null");

if (vStartTime.CompareTo(vEndTime) < 0)
{
Expand All @@ -195,8 +195,8 @@ private bool CheckWeekdays(DateTime dt)
if (NonStopSession)
throw new InvalidOperationException("NonStopSession is set; this statement should be unreachable");

TimeSpan vStartTime = StartTime ?? throw new QuickFix.ConfigError("StartTime is null");
TimeSpan vEndTime = EndTime ?? throw new QuickFix.ConfigError("EndTime is null");
TimeSpan vStartTime = StartTime ?? throw new ConfigError("StartTime is null");
TimeSpan vEndTime = EndTime ?? throw new ConfigError("EndTime is null");

TimeSpan tod = dt.TimeOfDay;

Expand All @@ -216,7 +216,7 @@ private bool CheckWeekdays(DateTime dt)
return _weekdays.Contains(targetDay);
}

private DayOfWeek PreviousDay(DayOfWeek d) {
private static DayOfWeek PreviousDay(DayOfWeek d) {
return d == DayOfWeek.Sunday
? DayOfWeek.Saturday
: d - 1;
Expand Down Expand Up @@ -252,10 +252,10 @@ public SessionSchedule(SettingsDictionary settings)
}

if (!settings.Has(SessionSettings.START_DAY) && settings.Has(SessionSettings.END_DAY))
throw new QuickFix.ConfigError("EndDay used without StartDay");
throw new ConfigError("EndDay used without StartDay");

if (settings.Has(SessionSettings.START_DAY) && !settings.Has(SessionSettings.END_DAY))
throw new QuickFix.ConfigError("StartDay used without EndDay");
throw new ConfigError("StartDay used without EndDay");

if (settings.Has(SessionSettings.START_DAY) && settings.Has(SessionSettings.END_DAY))
{
Expand Down
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ What's New
* Also refactor the heck out of DateTimeConverter & tests: many functions renamed/deprecated
* #847 - remove setting MillisecondsInTimeStamp (gbirchmeier)
* Use TimestampPrecision instead (same as QF/j)
* #844 - implement "Weekdays" setting (MichalUssuri/gbirchmeier)

**Non-breaking changes**
* #400 - added DDTool, a C#-based codegen, and deleted Ruby-based generator (gbirchmeier)
Expand All @@ -83,6 +82,7 @@ What's New
Programming Model (APM), in order to catch unobserved SocketExceptions (nmandzyk)
* Cleanup/nullable-ize SocketInitiatorThread (gbirchmeier)
* #839 - change ScreenLog to output FIX messages with "|" instead of non-visible SOH (gbirchmeier)
* #844 - implement "Weekdays" setting (MichalUssuri/gbirchmeier)

### v1.11.2:
* same as v1.11.1, but I fixed the readme in the pushed nuget packages
Expand Down
4 changes: 2 additions & 2 deletions UnitTests/SettingsDictionaryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void TestGetDay()

d.SetString("DAY_X", "invalid");
var ex = Assert.Throws(typeof(ArgumentException), delegate { d.GetDay("DAY_X"); });
StringAssert.Contains("Cannot recognize this day: 'invalid'", ex.Message);
StringAssert.Contains("Cannot recognize this day: 'invalid'", ex!.Message);
}

[Test]
Expand All @@ -130,7 +130,7 @@ public void TestSetDay() {
Assert.That(d.GetString("DAY4"), Is.EqualTo("Thursday"));

var ex = Assert.Throws(typeof(ArgumentException), delegate { d.SetDay("X", (DayOfWeek)9); });
StringAssert.Contains("Not a valid DayOfWeek value", ex.Message);
StringAssert.Contains("Not a valid DayOfWeek value", ex!.Message);
}

[Test]
Expand Down

0 comments on commit 0758ce0

Please sign in to comment.