diff --git a/QuickFIXn/SessionSchedule.cs b/QuickFIXn/SessionSchedule.cs index 909209c59..1a0434da7 100755 --- a/QuickFIXn/SessionSchedule.cs +++ b/QuickFIXn/SessionSchedule.cs @@ -1,5 +1,6 @@ #nullable enable using System; +using System.Collections.Generic; namespace QuickFix { @@ -12,6 +13,9 @@ public class SessionSchedule public DayOfWeek? StartDay { get; } public DayOfWeek? EndDay { get; } + private readonly bool _isWeekdaysSession; + private readonly HashSet _weekdays; + public bool NonStopSession { get; } public bool UseLocalTime { get; } @@ -28,9 +32,7 @@ public class SessionSchedule public bool IsNewSession(DateTime oldtimeUtc, DateTime testtimeUtc) { if (NonStopSession) - { return false; - } if (oldtimeUtc.Kind != DateTimeKind.Utc) throw new ArgumentException("Only UTC time is supported", nameof(oldtimeUtc)); @@ -72,6 +74,9 @@ public bool IsSessionTime(DateTime utc) DateTime adjusted = AdjustUtcDateTime(utc); + if (_isWeekdaysSession) + return CheckWeekdays(adjusted); + return WeeklySession ? CheckDay(adjusted) : CheckTime(adjusted.TimeOfDay); } @@ -83,7 +88,7 @@ public bool IsSessionTime(DateTime utc) public DateTime NextEndTime(DateTime utc) { if (NonStopSession) - throw new NotSupportedException("NonStopSession"); + throw new InvalidOperationException("NonStopSession is set; this statement should be unreachable"); TimeSpan vEndTime = EndTime ?? throw new QuickFix.ConfigError("EndTime is null"); @@ -93,7 +98,14 @@ public DateTime NextEndTime(DateTime utc) DateTime d = AdjustUtcDateTime(utc); DateTime end = DateTime.MinValue; - if (WeeklySession) + + if (_isWeekdaysSession) + { + end = new DateTime(d.Year, d.Month, d.Day, vEndTime.Hours, vEndTime.Minutes, vEndTime.Seconds, d.Kind); + if (DateTime.Compare(d, end) > 0) // d is later than end + end = end.AddDays(1); + } + else if (WeeklySession) { end = new DateTime(d.Year, d.Month, d.Day, vEndTime.Hours, vEndTime.Minutes, vEndTime.Seconds, d.Kind); while (end.DayOfWeek != EndDay) @@ -114,12 +126,12 @@ public DateTime NextEndTime(DateTime utc) /// /// return true if time falls within StartTime/EndTime /// - /// + /// /// - private bool CheckDay(DateTime time) + private bool CheckDay(DateTime dt) { if (NonStopSession) - throw new InvalidOperationException("NonStopSession is set -- this should never be called."); + 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"); @@ -128,31 +140,31 @@ private bool CheckDay(DateTime time) if (vStartDay < vEndDay) { - if (time.DayOfWeek < vStartDay || time.DayOfWeek > vEndDay) + if (dt.DayOfWeek < vStartDay || dt.DayOfWeek > vEndDay) return false; - if (time.DayOfWeek < vEndDay) - return (vStartDay < time.DayOfWeek) || (vStartTime.CompareTo(time.TimeOfDay) <= 0); + if (dt.DayOfWeek < vEndDay) + return (vStartDay < dt.DayOfWeek) || (vStartTime.CompareTo(dt.TimeOfDay) <= 0); - return (time.DayOfWeek < vEndDay) || (vEndTime.CompareTo(time.TimeOfDay) >= 0); + return (dt.DayOfWeek < vEndDay) || (vEndTime.CompareTo(dt.TimeOfDay) >= 0); } if (vEndDay < vStartDay) { - if (vEndDay < time.DayOfWeek && time.DayOfWeek < vStartDay) + if (vEndDay < dt.DayOfWeek && dt.DayOfWeek < vStartDay) return false; - if (time.DayOfWeek < vStartDay) - return (time.DayOfWeek < vEndDay) || (vEndTime.CompareTo(time.TimeOfDay) >= 0); + if (dt.DayOfWeek < vStartDay) + return (dt.DayOfWeek < vEndDay) || (vEndTime.CompareTo(dt.TimeOfDay) >= 0); - return (time.DayOfWeek > vStartDay) || (vStartTime.CompareTo(time.TimeOfDay) <= 0); + return (dt.DayOfWeek > vStartDay) || (vStartTime.CompareTo(dt.TimeOfDay) <= 0); } //start day must be same as end day if (vStartTime >= vEndTime) - return time.DayOfWeek != vStartDay || CheckTime(time.TimeOfDay); + return dt.DayOfWeek != vStartDay || CheckTime(dt.TimeOfDay); - return time.DayOfWeek == vStartDay && CheckTime(time.TimeOfDay); + return dt.DayOfWeek == vStartDay && CheckTime(dt.TimeOfDay); } /// @@ -170,29 +182,74 @@ private bool CheckTime(TimeSpan time) if (vStartTime.CompareTo(vEndTime) < 0) { - return (time.CompareTo(vStartTime) >= 0 && - time.CompareTo(vEndTime) <= 0); + return time.CompareTo(vStartTime) >= 0 && + time.CompareTo(vEndTime) <= 0; } - if (vStartTime.CompareTo(vEndTime) > 0) - { - return time.CompareTo(vStartTime) >= 0 || - time.CompareTo(vEndTime) <= 0; + return time.CompareTo(vStartTime) >= 0 || + time.CompareTo(vEndTime) <= 0; + } + + 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 tod = dt.TimeOfDay; + + // session spans midnight + if (vStartTime.CompareTo(vEndTime) < 0) { + return _weekdays.Contains(dt.DayOfWeek) && + tod.CompareTo(vStartTime) >= 0 && + tod.CompareTo(vEndTime) < 0; } - return true; + // session doesn't span midnight + if (tod.CompareTo(vEndTime) >= 0 && tod.CompareTo(vStartTime) < 0) + return false; + var targetDay = tod.CompareTo(vStartTime) >= 0 + ? dt.DayOfWeek + : PreviousDay(dt.DayOfWeek); + return _weekdays.Contains(targetDay); + } + + private DayOfWeek PreviousDay(DayOfWeek d) { + return d == DayOfWeek.Sunday + ? DayOfWeek.Saturday + : d - 1; } /// /// /// - public SessionSchedule(QuickFix.SettingsDictionary settings) + public SessionSchedule(SettingsDictionary settings) { - if (settings.Has(SessionSettings.NON_STOP_SESSION)) - NonStopSession = settings.GetBool(SessionSettings.NON_STOP_SESSION); + if (settings.IsBoolPresentAndTrue(SessionSettings.NON_STOP_SESSION)) { + NonStopSession = true; + + if (settings.Has(SessionSettings.START_DAY) + || settings.Has(SessionSettings.END_DAY) + || settings.Has(SessionSettings.START_TIME) + || settings.Has(SessionSettings.END_TIME)) + { + throw new ConfigError( + "NonStopSession is not compatible with StartDay/EndDay and StartTime/EndTime"); + } - if (NonStopSession) return; + } + + if (settings.Has(SessionSettings.WEEKDAYS)) + { + _isWeekdaysSession = true; + if (settings.Has(SessionSettings.START_DAY) || settings.Has(SessionSettings.END_DAY) ) + throw new ConfigError("StartDay/EndDay are not compatible with 'Weekdays' setting"); + + _weekdays = settings.GetDays(SessionSettings.WEEKDAYS); + } if (!settings.Has(SessionSettings.START_DAY) && settings.Has(SessionSettings.END_DAY)) throw new QuickFix.ConfigError("EndDay used without StartDay"); diff --git a/QuickFIXn/SessionSettings.cs b/QuickFIXn/SessionSettings.cs index 1a1634cbf..6cb5f49d1 100755 --- a/QuickFIXn/SessionSettings.cs +++ b/QuickFIXn/SessionSettings.cs @@ -27,6 +27,7 @@ public class SessionSettings public const string TIME_ZONE = "TimeZone"; public const string START_DAY = "StartDay"; public const string END_DAY = "EndDay"; + public const string WEEKDAYS = "Weekdays"; public const string START_TIME = "StartTime"; public const string END_TIME = "EndTime"; public const string HEARTBTINT = "HeartBtInt"; diff --git a/QuickFIXn/SettingsDictionary.cs b/QuickFIXn/SettingsDictionary.cs index fc744e3ec..b5b0365d2 100755 --- a/QuickFIXn/SettingsDictionary.cs +++ b/QuickFIXn/SettingsDictionary.cs @@ -150,8 +150,25 @@ public bool IsBoolPresentAndTrue(string key) { return Has(key) && GetBool(key); } + public HashSet GetDays(string key) + { + string[] weekdayNameArray = GetString(key).Split(","); + var result = new HashSet(weekdayNameArray.Length); + foreach (var weekDayName in weekdayNameArray) + { + string abbr = weekDayName.Trim().Substring(0, 2).ToUpper(); + result.Add(DeduceDay(abbr)); + } + + return result; + } + public DayOfWeek GetDay(string key) { - string abbr = GetString(key).Substring(0, 2).ToUpperInvariant(); + return DeduceDay(GetString(key)); + } + + private static DayOfWeek DeduceDay(string dayStr) { + string abbr = dayStr.Substring(0, 2).ToUpperInvariant(); return abbr switch { "SU" => DayOfWeek.Sunday, @@ -161,7 +178,7 @@ public DayOfWeek GetDay(string key) { "TH" => DayOfWeek.Thursday, "FR" => DayOfWeek.Friday, "SA" => DayOfWeek.Saturday, - _ => throw new ConfigError($"Illegal value {GetString(key)} for {key}") + _ => throw new ArgumentException($"Cannot recognize this day: '{dayStr}'") }; } @@ -199,21 +216,19 @@ public void SetBool(string key, bool val) SetString(key, BoolConverter.Convert(val)); } - public void SetDay(string key, DayOfWeek val) - { - switch(val) - { - case DayOfWeek.Sunday: SetString(key, "SU"); break; - case DayOfWeek.Monday: SetString(key, "MO"); break; - case DayOfWeek.Tuesday: SetString(key, "TU"); break; - case DayOfWeek.Wednesday: SetString(key, "WE"); break; - case DayOfWeek.Thursday: SetString(key, "TH"); break; - case DayOfWeek.Friday: SetString(key, "FR"); break; - case DayOfWeek.Saturday: SetString(key, "SA"); break; - default: throw new ConfigError($"Illegal value {val} for {key}"); + public void SetDay(string key, DayOfWeek val) { + if (Enum.IsDefined(val)) { + SetString(key, val.ToString()); + return; } + throw new ArgumentException("Not a valid DayOfWeek value"); } + /// + /// returns true if this SettingsDictionary has a value set for this key + /// + /// + /// public bool Has(string key) { return _data.ContainsKey(key.ToUpperInvariant()); diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index c7a7e644b..ba834e8eb 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -60,6 +60,7 @@ 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) diff --git a/UnitTests/SessionScheduleTests.cs b/UnitTests/SessionScheduleTests.cs index eaa9d9cff..fd1d52441 100755 --- a/UnitTests/SessionScheduleTests.cs +++ b/UnitTests/SessionScheduleTests.cs @@ -1,8 +1,7 @@ using System; -using System.Collections.Generic; using System.Linq; -using System.Text; using NUnit.Framework; +using QuickFix; namespace UnitTests { @@ -14,14 +13,13 @@ public class SessionScheduleTests /// Windows/*nix-agnostic time zone ID /// (because it would be too easy if they could settle on a standard list of ids, right?) /// - public string EASTERN_STANDARD_TIME_ZONE_ID + private static string EasternStandardTimeZoneId { get { - if (!TimeZoneInfo.GetSystemTimeZones().Any(x => x.Id == "Eastern Standard Time")) - return "US/Eastern"; - else - return "Eastern Standard Time"; + return TimeZoneInfo.GetSystemTimeZones().Any(x => x.Id == "Eastern Standard Time") + ? "Eastern Standard Time" + : "US/Eastern"; } } @@ -29,58 +27,95 @@ public string EASTERN_STANDARD_TIME_ZONE_ID /// Windows/*nix-agnostic time zone ID /// (because it would be too easy if they could settle on a standard list of ids, right?) /// - public string PACIFIC_STANDARD_TIME_ZONE_ID + private static string PacificStandardTimeZoneId { get { - if (!TimeZoneInfo.GetSystemTimeZones().Any(x => x.Id == "Pacific Standard Time")) - return "US/Pacific"; - else - return "Pacific Standard Time"; + return TimeZoneInfo.GetSystemTimeZones().Any(x => x.Id == "Pacific Standard Time") + ? "Pacific Standard Time" + : "US/Pacific"; } } #endregion - const string FMT = "yyyyMMdd-HH:mm:ss"; + private const string DtFmt = "yyyyMMdd-HH:mm:ss"; [Test] - public void testRequiredArgs() + public void TestCtor_BasicDailySchedule() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - Assert.Throws(typeof(QuickFix.ConfigError), delegate { new QuickFix.SessionSchedule(settings); }); + SettingsDictionary settings = new SettingsDictionary(); + var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("No value for key: StartTime", ex.Message); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - Assert.Throws(typeof(QuickFix.ConfigError), delegate { new QuickFix.SessionSchedule(settings); }); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("No value for key: EndTime", ex.Message); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:0blkajsdf"); - Assert.Throws(typeof(QuickFix.ConfigError), delegate { new QuickFix.SessionSchedule(settings); }); + settings.SetString(SessionSettings.END_TIME, "00:0blkajsdf"); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("String '00:0blkajsdf' was not recognized as a valid TimeSpan", ex.Message); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); - Assert.DoesNotThrow(delegate { new QuickFix.SessionSchedule(settings); }); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); + Assert.DoesNotThrow(delegate { new SessionSchedule(settings); }); } [Test] - public void testOptArgs() + public void TestCtor_WeeklongSession() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Thursday); - Assert.Throws(typeof(QuickFix.ConfigError), delegate { new QuickFix.SessionSchedule(settings); }); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Thursday); + var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("StartDay used without EndDay", ex.Message); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); - Assert.DoesNotThrow(delegate { new QuickFix.SessionSchedule(settings); }); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); + Assert.DoesNotThrow(delegate { new SessionSchedule(settings); }); } [Test] - public void testDailyIsSessionTimeAllDay() + public void TestCtor_WeekdaysSession() { + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.WEEKDAYS, "Sun,Tue,Fri"); + + var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("No value for key: StartTime", ex.Message); + + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); + Assert.DoesNotThrow(delegate { new SessionSchedule(settings); }); + + settings.SetString(SessionSettings.START_DAY, "Tue"); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("StartDay/EndDay are not compatible with 'Weekdays' setting", ex.Message); + } + + [Test] + public void TestCtor_NonStopSession() { + SettingsDictionary settings = new SettingsDictionary(); + settings.SetBool(SessionSettings.NON_STOP_SESSION, true); + Assert.DoesNotThrow(delegate { new SessionSchedule(settings); }); + + settings.SetString(SessionSettings.START_DAY, "Monday"); + var ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("NonStopSession is not compatible with StartDay/EndDay and StartTime/EndTime", ex.Message); + + settings = new SettingsDictionary(); + settings.SetBool(SessionSettings.NON_STOP_SESSION, true); + settings.SetString(SessionSettings.START_TIME, "05:00:00"); + ex = Assert.Throws(typeof(ConfigError), delegate { new SessionSchedule(settings); }); + StringAssert.Contains("NonStopSession is not compatible with StartDay/EndDay and StartTime/EndTime", ex.Message); + } + + [Test] + public void TestDailyIsSessionTimeAllDay() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 9, 43, 0, DateTimeKind.Utc))); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 18, 9, 43, 0, DateTimeKind.Utc))); @@ -89,15 +124,15 @@ public void testDailyIsSessionTimeAllDay() } [Test] - public void testWeeklySessionSameDayAllWeek() + public void TestWeeklySessionSameDayAllWeek() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Monday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Monday); + SessionSchedule sched = new SessionSchedule(settings); //a sunday Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 16, 9, 43, 0, DateTimeKind.Utc))); @@ -115,15 +150,15 @@ public void testWeeklySessionSameDayAllWeek() } [Test] - public void testWeeklySessionSameDayMostWeek() + public void TestWeeklySessionSameDayMostWeek() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "05:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "05:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Monday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Monday); + SessionSchedule sched = new SessionSchedule(settings); //a sunday Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 16, 23, 59, 59, DateTimeKind.Utc))); @@ -139,17 +174,16 @@ public void testWeeklySessionSameDayMostWeek() Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 18, 0, 0, 0, DateTimeKind.Utc))); } - //admittedly contrived, but full coverage [Test] - public void testWeeklySessionSameDayOneDay() + public void TestWeeklySessionSameDayOneDay() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "05:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "05:00:00"); - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Monday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Monday); + SessionSchedule sched = new SessionSchedule(settings); //a sunday Assert.IsFalse(sched.IsSessionTime(new DateTime(2011, 10, 16, 23, 59, 59, DateTimeKind.Utc))); @@ -167,17 +201,17 @@ public void testWeeklySessionSameDayOneDay() [Test] - public void testWeeklySessionMultiDay() + public void TestWeeklySessionMultiDay() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); //only on monday-thur (note end time) - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); //a monday Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 0, 0, 0, DateTimeKind.Utc))); @@ -193,17 +227,17 @@ public void testWeeklySessionMultiDay() } [Test] - public void testWeeklySessionMultiDayOverlap() + public void TestWeeklySessionMultiDayOverlap() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:00:00"); + settings.SetString(SessionSettings.END_TIME, "00:00:00"); //only on wed-sunday night - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Wednesday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Monday); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Wednesday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Monday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); //wed-monday Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 19, 9, 43, 0, DateTimeKind.Utc))); @@ -220,17 +254,17 @@ public void testWeeklySessionMultiDayOverlap() } [Test] - public void testWeeklySessionMultiDayHours() + public void TestWeeklySessionMultiDayHours() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "07:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "15:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "07:00:00"); + settings.SetString(SessionSettings.END_TIME, "15:00:00"); //only on monday-fri - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); //Monday Scenarios Assert.IsFalse(sched.IsSessionTime(new DateTime(2011, 10, 17, 6, 59, 0, DateTimeKind.Utc))); @@ -254,17 +288,17 @@ public void testWeeklySessionMultiDayHours() } [Test] - public void testWeeklySessionMultiDayHoursOverlap() + public void TestWeeklySessionMultiDayHoursOverlap() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "15:00:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "07:00:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "15:00:00"); + settings.SetString(SessionSettings.END_TIME, "07:00:00"); //only on monday-fri - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); //weekdays Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 15, 30, 0, DateTimeKind.Utc))); @@ -279,13 +313,13 @@ public void testWeeklySessionMultiDayHoursOverlap() [Test] - public void testDailyIsSessionTime() + public void TestDailyIsSessionTime() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "00:12:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "06:00:23"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "00:12:00"); + settings.SetString(SessionSettings.END_TIME, "06:00:23"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 0, 12, 0, DateTimeKind.Utc))); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 5, 43, 0, DateTimeKind.Utc))); @@ -296,13 +330,13 @@ public void testDailyIsSessionTime() } [Test] - public void testDailyIsSessionTimeWrapAround() + public void TestDailyIsSessionTimeWrapAround() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "06:00:23"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:12:00"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "06:00:23"); + settings.SetString(SessionSettings.END_TIME, "00:12:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 6, 0, 23, DateTimeKind.Utc))); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 8, 43, 0, DateTimeKind.Utc))); @@ -314,38 +348,38 @@ public void testDailyIsSessionTimeWrapAround() } [Test] - public void testInvalidTimeZone() + public void TestInvalidTimeZone() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "06:00:23"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:12:00"); - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, "Doh"); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "06:00:23"); + settings.SetString(SessionSettings.END_TIME, "00:12:00"); + settings.SetString(SessionSettings.TIME_ZONE, "Doh"); - Assert.Throws(typeof (TimeZoneNotFoundException), delegate { new QuickFix.SessionSchedule(settings); }); + Assert.Throws(typeof (TimeZoneNotFoundException), delegate { new SessionSchedule(settings); }); } [Test] - public void testLocalTimeTimeZoneConflict() + public void TestLocalTimeTimeZoneConflict() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "06:00:23"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "00:12:00"); - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, "Doh"); - settings.SetString(QuickFix.SessionSettings.USE_LOCAL_TIME, "Y"); - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); - - Assert.Throws(typeof (QuickFix.ConfigError), delegate { new QuickFix.SessionSchedule(settings); }); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "06:00:23"); + settings.SetString(SessionSettings.END_TIME, "00:12:00"); + settings.SetString(SessionSettings.TIME_ZONE, "Doh"); + settings.SetString(SessionSettings.USE_LOCAL_TIME, "Y"); + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); + + Assert.Throws(typeof (ConfigError), delegate { new SessionSchedule(settings); }); } [Test] - public void testTimeZone() + public void TestTimeZone() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SessionSchedule sched = new SessionSchedule(settings); Assert.IsFalse(sched.IsSessionTime(new DateTime(2011, 10, 17, 13, 29, 59, DateTimeKind.Utc))); Assert.IsTrue(sched.IsSessionTime(new DateTime(2011, 10, 17, 13, 30, 0, DateTimeKind.Utc))); @@ -354,12 +388,12 @@ public void testTimeZone() } [Test] - public void testNextEndTime_takesUtcOnly() + public void TestNextEndTime_takesUtcOnly() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + SessionSchedule sched = new SessionSchedule(settings); DateTime local = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Local); DateTime none = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Unspecified); @@ -369,114 +403,114 @@ public void testNextEndTime_takesUtcOnly() } [Test] - public void testNextEndTime_Daily() + public void TestNextEndTime_Daily() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + SessionSchedule sched = new SessionSchedule(settings); Assert.AreEqual("20121018-16:00:00", - sched.NextEndTime(new DateTime(2012, 10, 18, 15, 59, 59, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 10, 18, 15, 59, 59, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121018-16:00:00", - sched.NextEndTime(new DateTime(2012, 10, 18, 16, 00, 00, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 10, 18, 16, 00, 00, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121019-16:00:00", - sched.NextEndTime(new DateTime(2012, 10, 18, 16, 00, 01, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 10, 18, 16, 00, 01, DateTimeKind.Utc)).ToString(DtFmt)); // ========== // Settings file is specified in a zone (est, -5) - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5 - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-5 + sched = new SessionSchedule(settings); Assert.AreEqual("20121218-11:00:00", - sched.NextEndTime(new DateTime(2012, 12, 18, 15, 59, 59, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 12, 18, 15, 59, 59, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121218-11:00:00", - sched.NextEndTime(new DateTime(2012, 12, 18, 16, 00, 00, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 12, 18, 16, 00, 00, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121219-11:00:00", - sched.NextEndTime(new DateTime(2012, 12, 18, 16, 00, 01, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 12, 18, 16, 00, 01, DateTimeKind.Utc)).ToString(DtFmt)); // ========== // Time zone during Daylight Savings - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "05:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "12:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 for DST - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "05:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "12:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-4 for DST + sched = new SessionSchedule(settings); Assert.AreEqual("20120618-12:00:00", - sched.NextEndTime(new DateTime(2012, 06, 18, 15, 59, 59, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 06, 18, 15, 59, 59, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20120618-12:00:00", - sched.NextEndTime(new DateTime(2012, 06, 18, 16, 00, 00, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 06, 18, 16, 00, 00, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20120619-12:00:00", - sched.NextEndTime(new DateTime(2012, 06, 18, 16, 00, 01, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 06, 18, 16, 00, 01, DateTimeKind.Utc)).ToString(DtFmt)); } [Test] - public void testNextEndTime_Weekly() + public void TestNextEndTime_Weekly() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); + SessionSchedule sched = new SessionSchedule(settings); // Oct 15 and 22 are Mondays, 19 and 26 are Fridays Assert.AreEqual("20121019-16:00:00", - sched.NextEndTime(new DateTime(2012, 10, 19, 15, 59, 59, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 10, 19, 15, 59, 59, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121019-16:00:00", - sched.NextEndTime(new DateTime(2012, 10, 19, 16, 00, 00, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 10, 19, 16, 00, 00, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121026-16:00:00", - sched.NextEndTime(new DateTime(2012, 10, 19, 16, 00, 01, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 10, 19, 16, 00, 01, DateTimeKind.Utc)).ToString(DtFmt)); // ========== // Settings file is specified in a zone (est, -5) - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5 - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-5 + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); + sched = new SessionSchedule(settings); // Dec 14 and 21 are Fridays Assert.AreEqual("20121214-11:00:00", - sched.NextEndTime(new DateTime(2012, 12, 14, 15, 59, 59, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 12, 14, 15, 59, 59, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121214-11:00:00", - sched.NextEndTime(new DateTime(2012, 12, 14, 16, 00, 00, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 12, 14, 16, 00, 00, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20121221-11:00:00", - sched.NextEndTime(new DateTime(2012, 12, 14, 16, 00, 01, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 12, 14, 16, 00, 01, DateTimeKind.Utc)).ToString(DtFmt)); // ========== // Time zone during Daylight Savings - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "05:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "12:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 for DST - settings.SetDay(QuickFix.SessionSettings.START_DAY, System.DayOfWeek.Monday); - settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday); - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "05:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "12:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-4 for DST + settings.SetDay(SessionSettings.START_DAY, DayOfWeek.Monday); + settings.SetDay(SessionSettings.END_DAY, DayOfWeek.Friday); + sched = new SessionSchedule(settings); // June 15 and 22 are Fridays Assert.AreEqual("20120615-12:00:00", - sched.NextEndTime(new DateTime(2012, 06, 15, 15, 59, 59, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 06, 15, 15, 59, 59, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20120615-12:00:00", - sched.NextEndTime(new DateTime(2012, 06, 15, 16, 00, 00, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 06, 15, 16, 00, 00, DateTimeKind.Utc)).ToString(DtFmt)); Assert.AreEqual("20120622-12:00:00", - sched.NextEndTime(new DateTime(2012, 06, 15, 16, 00, 01, DateTimeKind.Utc)).ToString(FMT)); + sched.NextEndTime(new DateTime(2012, 06, 15, 16, 00, 01, DateTimeKind.Utc)).ToString(DtFmt)); } [Test] - public void testIsNewSession_takesUtcOnly() + public void TestIsNewSession_takesUtcOnly() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + SessionSchedule sched = new SessionSchedule(settings); DateTime local = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Local); DateTime utc = new DateTime(2001, 1, 1, 1, 1, 1, DateTimeKind.Utc); @@ -489,12 +523,12 @@ public void testIsNewSession_takesUtcOnly() } [Test] - public void testIsNewSession_Daily() + public void TestIsNewSession_Daily() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + SessionSchedule sched = new SessionSchedule(settings); Assert.False(sched.IsNewSession( new DateTime(2012, 10, 18, 15, 59, 58, DateTimeKind.Utc), @@ -511,11 +545,11 @@ public void testIsNewSession_Daily() // ========== // Settings file is specified in a zone (est, -5) - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5 - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-5 + sched = new SessionSchedule(settings); Assert.False(sched.IsNewSession( new DateTime(2012, 12, 18, 15, 59, 58, DateTimeKind.Utc), @@ -532,11 +566,11 @@ public void testIsNewSession_Daily() // ========== // Time zone during Daylight savings - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "05:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "12:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 during dst - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "05:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "12:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-4 during dst + sched = new SessionSchedule(settings); Assert.False(sched.IsNewSession( new DateTime(2012, 06, 18, 15, 59, 58, DateTimeKind.Utc), @@ -553,12 +587,12 @@ public void testIsNewSession_Daily() } [Test] - public void testAdjustDateTime() + public void TestAdjustDateTime() { - QuickFix.SettingsDictionary settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "09:30:00"); - settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00"); - QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings); + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "09:30:00"); + settings.SetString(SessionSettings.END_TIME, "16:00:00"); + SessionSchedule sched = new SessionSchedule(settings); // 1) reject if param is not utc Assert.Throws( @@ -571,11 +605,11 @@ public void testAdjustDateTime() Assert.AreEqual(d2, sched.AdjustUtcDateTime(d2)); // 3) if settings has a TimeZone, convert to TimeZone - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5 - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-5 + sched = new SessionSchedule(settings); DateTime d3 = new DateTime(2013, 01, 15, 03, 00, 00, DateTimeKind.Utc); DateTime d3expected = new DateTime(2013, 01, 14, 22, 00, 00, DateTimeKind.Unspecified); @@ -583,11 +617,11 @@ public void testAdjustDateTime() Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d3expected, d3actual); // now with Pacific Standard Time - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, PACIFIC_STANDARD_TIME_ZONE_ID); //-5 - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, PacificStandardTimeZoneId); //-5 + sched = new SessionSchedule(settings); d3 = new DateTime(2013, 01, 15, 03, 00, 00, DateTimeKind.Utc); d3expected = new DateTime(2013, 01, 14, 19, 00, 00, DateTimeKind.Unspecified); @@ -595,11 +629,11 @@ public void testAdjustDateTime() Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d3expected, d3actual); // 4) TimeZone with daylight savings - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 in June - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.TIME_ZONE, EasternStandardTimeZoneId); //-4 in June + sched = new SessionSchedule(settings); DateTime d4 = new DateTime(2013, 06, 15, 03, 00, 00, DateTimeKind.Utc); DateTime d4expected = new DateTime(2013, 06, 14, 23, 00, 00, DateTimeKind.Unspecified); @@ -607,11 +641,11 @@ public void testAdjustDateTime() Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d4expected, d4actual); // 5) if settings has UseLocalTime, convert to local time - settings = new QuickFix.SettingsDictionary(); - settings.SetString(QuickFix.SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc - settings.SetString(QuickFix.SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc - settings.SetString(QuickFix.SessionSettings.USE_LOCAL_TIME, "Y"); - sched = new QuickFix.SessionSchedule(settings); + settings = new SettingsDictionary(); + settings.SetString(SessionSettings.START_TIME, "04:30:00"); // 09:30:00 utc + settings.SetString(SessionSettings.END_TIME, "11:00:00"); // 16:00:00 utc + settings.SetString(SessionSettings.USE_LOCAL_TIME, "Y"); + sched = new SessionSchedule(settings); DateTime d5 = new DateTime(2013, 01, 15, 16, 00, 00, DateTimeKind.Utc); DateTime d5expected = d5.ToLocalTime(); @@ -619,5 +653,59 @@ public void testAdjustDateTime() Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d5expected, d5actual); Assert.AreEqual(DateTimeKind.Local, d5actual.Kind); } + + [Test] + public void TestWeekdaysSession() + { + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.WEEKDAYS, "Tue,Th"); + settings.SetString(SessionSettings.START_TIME, "08:00:00"); + settings.SetString(SessionSettings.END_TIME, "17:00:00"); + + SessionSchedule sched = new SessionSchedule(settings); + + // bounds of Tuesday + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 21, 07, 59, 59, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 21, 08, 00, 00, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 21, 08, 00, 10, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 21, 16, 59, 59, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 21, 17, 00, 00, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 21, 17, 00, 10, DateTimeKind.Utc))); + + // bounds of Thursday + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 23, 07, 59, 59, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 23, 08, 00, 00, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 23, 08, 00, 10, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 23, 16, 59, 59, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 23, 17, 00, 00, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 23, 17, 00, 10, DateTimeKind.Utc))); + } + + [Test] + public void TestWeekdaysSession_ThatCrossesMidnight() + { + SettingsDictionary settings = new SettingsDictionary(); + settings.SetString(SessionSettings.WEEKDAYS, "Tue,Th"); + settings.SetString(SessionSettings.START_TIME, "17:00:00"); + settings.SetString(SessionSettings.END_TIME, "11:00:00"); + + SessionSchedule sched = new SessionSchedule(settings); + + // bounds of Tuesday-Wednesday + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 21, 16, 59, 59, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 21, 17, 00, 00, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 21, 17, 00, 10, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 22, 10, 59, 59, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 22, 11, 00, 00, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 22, 11, 00, 10, DateTimeKind.Utc))); + + // bounds of Thursday-Friday + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 23, 16, 59, 59, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 23, 17, 00, 00, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 23, 17, 00, 10, DateTimeKind.Utc))); + Assert.IsTrue(sched.IsSessionTime(new DateTime(2024, 05, 24, 10, 59, 59, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 24, 11, 00, 00, DateTimeKind.Utc))); + Assert.IsFalse(sched.IsSessionTime(new DateTime(2024, 05, 24, 11, 00, 10, DateTimeKind.Utc))); + } } } diff --git a/UnitTests/SettingsDictionaryTests.cs b/UnitTests/SettingsDictionaryTests.cs index de8d42fc7..776e9a57e 100755 --- a/UnitTests/SettingsDictionaryTests.cs +++ b/UnitTests/SettingsDictionaryTests.cs @@ -1,4 +1,5 @@ #nullable enable +using System; using NUnit.Framework; using QuickFix; @@ -14,7 +15,7 @@ public void Teardown() } [Test] - public void SetGetString() + public void TestSetGetString() { SettingsDictionary d = new(); d.SetString("STRINGKEY1", "STRINGVALUE1"); @@ -26,7 +27,7 @@ public void SetGetString() } [Test] - public void SetGetLong() + public void TestSetGetLong() { SettingsDictionary d = new(); d.SetLong("LONGKEY1", 12); @@ -39,7 +40,7 @@ public void SetGetLong() } [Test] - public void SetDouble() + public void TestSetDouble() { // make sure that QF/n uses the invariant culture, no matter what the current culture is System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR"); @@ -53,7 +54,7 @@ public void SetDouble() } [Test] - public void GetDouble() + public void TestGetDouble() { // make sure that QF/n uses the invariant culture, no matter what the current culture is System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-FR"); @@ -72,7 +73,7 @@ public void GetDouble() } [Test] - public void SetGetBool() + public void TestSetGetBool() { SettingsDictionary d = new(); d.SetBool("BOOLKEY1", true); @@ -85,7 +86,7 @@ public void SetGetBool() } [Test] - public void IsBoolPresentAndTrue() { + public void TestIsBoolPresentAndTrue() { SettingsDictionary d = new(); d.SetBool("BOOLKEY-T", true); d.SetBool("BOOLKEY-F", false); @@ -95,7 +96,7 @@ public void IsBoolPresentAndTrue() { } [Test] - public void SetGetDay() + public void TestGetDay() { SettingsDictionary d = new(); @@ -106,32 +107,34 @@ public void SetGetDay() d.SetString("DAY5", "TH"); d.SetString("DAY6", "FR"); d.SetString("DAY7", "SA"); - Assert.That(d.GetDay("DAY1"), Is.EqualTo(System.DayOfWeek.Sunday)); - Assert.That(d.GetDay("DAY2"), Is.EqualTo(System.DayOfWeek.Monday)); - Assert.That(d.GetDay("DAY3"), Is.EqualTo(System.DayOfWeek.Tuesday)); - Assert.That(d.GetDay("DAY4"), Is.EqualTo(System.DayOfWeek.Wednesday)); - Assert.That(d.GetDay("DAY5"), Is.EqualTo(System.DayOfWeek.Thursday)); - Assert.That(d.GetDay("DAY6"), Is.EqualTo(System.DayOfWeek.Friday)); - Assert.That(d.GetDay("DAY7"), Is.EqualTo(System.DayOfWeek.Saturday)); - - d.SetDay("NEXTDAY1", System.DayOfWeek.Sunday); - d.SetDay("NEXTDAY2", System.DayOfWeek.Monday); - d.SetDay("NEXTDAY3", System.DayOfWeek.Tuesday); - d.SetDay("NEXTDAY4", System.DayOfWeek.Wednesday); - d.SetDay("NEXTDAY5", System.DayOfWeek.Thursday); - d.SetDay("NEXTDAY6", System.DayOfWeek.Friday); - d.SetDay("NEXTDAY7", System.DayOfWeek.Saturday); - Assert.That(d.GetDay("NEXTDAY1"), Is.EqualTo(System.DayOfWeek.Sunday)); - Assert.That(d.GetDay("NEXTDAY2"), Is.EqualTo(System.DayOfWeek.Monday)); - Assert.That(d.GetDay("NEXTDAY3"), Is.EqualTo(System.DayOfWeek.Tuesday)); - Assert.That(d.GetDay("NEXTDAY4"), Is.EqualTo(System.DayOfWeek.Wednesday)); - Assert.That(d.GetDay("NEXTDAY5"), Is.EqualTo(System.DayOfWeek.Thursday)); - Assert.That(d.GetDay("NEXTDAY6"), Is.EqualTo(System.DayOfWeek.Friday)); - Assert.That(d.GetDay("NEXTDAY7"), Is.EqualTo(System.DayOfWeek.Saturday)); + Assert.That(d.GetDay("DAY1"), Is.EqualTo(DayOfWeek.Sunday)); + Assert.That(d.GetDay("DAY2"), Is.EqualTo(DayOfWeek.Monday)); + Assert.That(d.GetDay("DAY3"), Is.EqualTo(DayOfWeek.Tuesday)); + Assert.That(d.GetDay("DAY4"), Is.EqualTo(DayOfWeek.Wednesday)); + Assert.That(d.GetDay("DAY5"), Is.EqualTo(DayOfWeek.Thursday)); + Assert.That(d.GetDay("DAY6"), Is.EqualTo(DayOfWeek.Friday)); + Assert.That(d.GetDay("DAY7"), Is.EqualTo(DayOfWeek.Saturday)); + + 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); } [Test] - public void Merge() + public void TestSetDay() { + SettingsDictionary d = new(); + d.SetDay("DAY1", DayOfWeek.Monday); + d.SetDay("DAY4", DayOfWeek.Thursday); + + Assert.That(d.GetString("DAY1"), Is.EqualTo("Monday")); + 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); + } + + [Test] + public void TestMerge() { SettingsDictionary first = new(); first.SetString("FIRSTKEY", "FIRSTVALUE"); @@ -148,7 +151,7 @@ public void Merge() } [Test] - public void ValueEquality() + public void TestValueEquality() { SettingsDictionary first = new("MyName"); SettingsDictionary second = new("MyName"); @@ -175,7 +178,7 @@ public void ValueEquality() } [Test] - public void CopyCtor() { + public void TestCopyCtor() { SettingsDictionary orig = new("orig"); orig.SetString("uno", "One"); orig.SetLong("dos", 2);