Skip to content
Browse files

corrections to SessionSchedule.LastEndTime and tests

  • Loading branch information...
1 parent f984638 commit 1b9ecbafdd1991bf22970e6cb75bfa4fb3dc9414 @gbirchmeier gbirchmeier committed Feb 5, 2013
Showing with 69 additions and 46 deletions.
  1. +1 −0 .gitignore
  2. +11 −13 QuickFIXn/SessionSchedule.cs
  3. +57 −33 UnitTests/SessionScheduleTests.cs
View
1 .gitignore
@@ -11,6 +11,7 @@ QuickFIXn.sln.cache
ChangeLog
*.swp
AcceptanceTest/AcceptanceTests*.html
+AcceptanceTest/AcceptanceTests*.xml
AcceptanceTest/TestResult.xml
AcceptanceTest/bin/Debug/*
AcceptanceTest/bin/Release/*
View
24 QuickFIXn/SessionSchedule.cs
@@ -73,8 +73,7 @@ public bool IsSessionTime(System.DateTime utc)
}
/// <summary>
- /// Get the next endtime that is equal to or after the input.
- /// The return value will be represented in the timezone specified in the config file.
+ /// Get the next endtime (in config file's timezone) that is equal to or after the input.
/// </summary>
/// <param name="utc">a utc time (raises an ArgumentException if not utc)</param>
/// <returns></returns>
@@ -104,6 +103,7 @@ public DateTime NextEndTime(DateTime utc)
return end;
}
+ // TODO: consider removing this function in v2.0, as it's not used.
/// <summary>
/// Return the latest EndTime (in UTC) before time.
/// </summary>
@@ -114,19 +114,17 @@ public DateTime LastEndTime(DateTime utc)
if (utc.Kind != DateTimeKind.Utc)
throw new ArgumentException("Only UTC time is supported", "time");
- DateTime adjusted = AdjustUtcDateTime(utc);
-
- int daysBack = 0;
+ DateTime n = NextEndTime(utc);
if (WeeklySession)
- {
- daysBack = (7 - (int)EndDay + (int)adjusted.DayOfWeek) % 7;
- if (daysBack == 0 && adjusted.TimeOfDay < EndTime)
- daysBack = 7;
- }
- else if (adjusted.TimeOfDay < EndTime)
- daysBack = 1;
+ n = n.AddDays(-7);
+ else
+ n = n.AddDays(-1);
- return (adjusted.Date + new TimeSpan(-daysBack, 0, 0, 0) + EndTime).ToUniversalTime();
+ if (UseLocalTime)
+ return n.ToUniversalTime();
+ if (TimeZone != null)
+ return TimeZoneInfo.ConvertTimeBySystemTimeZoneId(n, this.TimeZone.Id, "UTC");
+ return n;
}
/// <summary>
View
90 UnitTests/SessionScheduleTests.cs
@@ -11,20 +11,32 @@ class SessionScheduleTests
{
#region Properties
/// <summary>
- /// Deal with the fact that time zone IDs are not cross-platform.
+ /// Windows/Mono-agnostic time zone ID
+ /// (because it would be too easy if they could settle on a standard list of ids, right?)
/// </summary>
public string EASTERN_STANDARD_TIME_ZONE_ID
{
get
{
if(null != System.Type.GetType("Mono.Runtime"))
- {
return "US/Eastern";
- }
else
- {
return "Eastern Standard Time";
- }
+ }
+ }
+
+ /// <summary>
+ /// Windows/Mono-agnostic time zone ID
+ /// (because it would be too easy if they could settle on a standard list of ids, right?)
+ /// </summary>
+ public string PACIFIC_STANDARD_TIME_ZONE_ID
+ {
+ get
+ {
+ if (null != System.Type.GetType("Mono.Runtime"))
+ return "US/Pacific";
+ else
+ return "Pacific Standard Time";
}
}
#endregion
@@ -364,17 +376,17 @@ public void testLastEndTime_DailySessions()
settings.SetString(QuickFix.SessionSettings.END_TIME, "16:00:00");
QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings);
- DateTime thisDayEnd = new DateTime(2012, 10, 18, 16, 00, 00, DateTimeKind.Utc);
- DateTime prevDayEnd = new DateTime(2012, 10, 17, 16, 00, 00, DateTimeKind.Utc);
+ DateTime thisDayEnd = new DateTime(2013, 02, 05, 16, 00, 00, DateTimeKind.Utc);
+ DateTime prevDayEnd = new DateTime(2013, 02, 04, 16, 00, 00, DateTimeKind.Utc);
// before starttime
- Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2012, 10, 18, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 08, 00, 00, DateTimeKind.Utc)));
// during session
- Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2012, 10, 18, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 10, 00, 00, DateTimeKind.Utc)));
// equals endtime
- Assert.AreEqual(thisDayEnd, sched.LastEndTime(thisDayEnd));
+ Assert.AreEqual(prevDayEnd, sched.LastEndTime(thisDayEnd));
// after endtime
- Assert.AreEqual(thisDayEnd, sched.LastEndTime(new DateTime(2012, 10, 18, 17, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(thisDayEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 17, 00, 00, DateTimeKind.Utc)));
// ==========
// Settings file is specified in a zone (est, -5)
@@ -385,13 +397,13 @@ public void testLastEndTime_DailySessions()
sched = new QuickFix.SessionSchedule(settings);
// before starttime
- Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2012, 10, 18, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 08, 00, 00, DateTimeKind.Utc)));
// during session
- Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2012, 10, 18, 10, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevDayEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 10, 00, 00, DateTimeKind.Utc)));
// equals endtime
- Assert.AreEqual(thisDayEnd, sched.LastEndTime(thisDayEnd));
+ Assert.AreEqual(prevDayEnd, sched.LastEndTime(thisDayEnd));
// after endtime
- Assert.AreEqual(thisDayEnd, sched.LastEndTime(new DateTime(2012, 10, 18, 17, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(thisDayEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 17, 00, 00, DateTimeKind.Utc)));
}
[Test]
@@ -404,17 +416,17 @@ public void testLastEndTime_WeeklySessions()
settings.SetDay(QuickFix.SessionSettings.END_DAY, System.DayOfWeek.Friday);
QuickFix.SessionSchedule sched = new QuickFix.SessionSchedule(settings);
- DateTime thisWeekEnd = new DateTime(2012, 10, 19, 16, 00, 00, DateTimeKind.Utc);
- DateTime prevWeekEnd = new DateTime(2012, 10, 12, 16, 00, 00, DateTimeKind.Utc);
+ DateTime thisWeekEnd = new DateTime(2013, 02, 08, 16, 00, 00, DateTimeKind.Utc);
+ DateTime prevWeekEnd = new DateTime(2013, 02, 01, 16, 00, 00, DateTimeKind.Utc);
// before starttime
- Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2012, 10, 15, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2013, 02, 04, 08, 00, 00, DateTimeKind.Utc)));
// during session
- Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2012, 10, 17, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 08, 00, 00, DateTimeKind.Utc)));
// equals endtime
- Assert.AreEqual(thisWeekEnd, sched.LastEndTime(thisWeekEnd));
+ Assert.AreEqual(prevWeekEnd, sched.LastEndTime(thisWeekEnd));
// after endtime
- Assert.AreEqual(thisWeekEnd, sched.LastEndTime(new DateTime(2012, 10, 19, 17, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(thisWeekEnd, sched.LastEndTime(new DateTime(2013, 02, 08, 17, 00, 00, DateTimeKind.Utc)));
// ==========
// Settings file is specified in a zone (est, -5)
@@ -427,13 +439,13 @@ public void testLastEndTime_WeeklySessions()
sched = new QuickFix.SessionSchedule(settings);
// before starttime
- Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2012, 10, 15, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2013, 02, 04, 08, 00, 00, DateTimeKind.Utc)));
// during session
- Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2012, 10, 17, 08, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(prevWeekEnd, sched.LastEndTime(new DateTime(2013, 02, 05, 08, 00, 00, DateTimeKind.Utc)));
// equals endtime
- Assert.AreEqual(thisWeekEnd, sched.LastEndTime(thisWeekEnd));
+ Assert.AreEqual(prevWeekEnd, sched.LastEndTime(thisWeekEnd));
// after endtime
- Assert.AreEqual(thisWeekEnd, sched.LastEndTime(new DateTime(2012, 10, 19, 17, 00, 00, DateTimeKind.Utc)));
+ Assert.AreEqual(thisWeekEnd, sched.LastEndTime(new DateTime(2013, 02, 08, 17, 00, 00, DateTimeKind.Utc)));
}
[Test]
@@ -471,7 +483,7 @@ public void testNextEndTime_Daily()
settings = new QuickFix.Dictionary();
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"); //-5
+ settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5
sched = new QuickFix.SessionSchedule(settings);
Assert.AreEqual("20121218-11:00:00",
@@ -486,7 +498,7 @@ public void testNextEndTime_Daily()
settings = new QuickFix.Dictionary();
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"); //-4 for DST
+ settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 for DST
sched = new QuickFix.SessionSchedule(settings);
Assert.AreEqual("20120618-12:00:00",
@@ -520,7 +532,7 @@ public void testNextEndTime_Weekly()
settings = new QuickFix.Dictionary();
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"); //-5
+ 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);
@@ -538,7 +550,7 @@ public void testNextEndTime_Weekly()
settings = new QuickFix.Dictionary();
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"); //-4 for DST
+ 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);
@@ -597,7 +609,7 @@ public void testIsNewSession_Daily()
settings = new QuickFix.Dictionary();
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"); //-5
+ settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5
sched = new QuickFix.SessionSchedule(settings);
Assert.False(sched.IsNewSession(
@@ -618,7 +630,7 @@ public void testIsNewSession_Daily()
settings = new QuickFix.Dictionary();
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"); //-4 during dst
+ settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 during dst
sched = new QuickFix.SessionSchedule(settings);
Assert.False(sched.IsNewSession(
@@ -657,19 +669,31 @@ public void testAdjustDateTime()
settings = new QuickFix.Dictionary();
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"); //-5
+ settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-5
sched = new QuickFix.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);
DateTime d3actual = sched.AdjustUtcDateTime(d3);
Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d3expected, d3actual);
+ // now with Pacific Standard Time
+ settings = new QuickFix.Dictionary();
+ 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);
+
+ d3 = new DateTime(2013, 01, 15, 03, 00, 00, DateTimeKind.Utc);
+ d3expected = new DateTime(2013, 01, 14, 19, 00, 00, DateTimeKind.Unspecified);
+ d3actual = sched.AdjustUtcDateTime(d3);
+ Util.UtcDateTimeSerializerTests.AssertHackyDateTimeEquality(d3expected, d3actual);
+
// 4) TimeZone with daylight savings
settings = new QuickFix.Dictionary();
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"); //-4 in June
+ settings.SetString(QuickFix.SessionSettings.TIME_ZONE, EASTERN_STANDARD_TIME_ZONE_ID); //-4 in June
sched = new QuickFix.SessionSchedule(settings);
DateTime d4 = new DateTime(2013, 06, 15, 03, 00, 00, DateTimeKind.Utc);

0 comments on commit 1b9ecba

Please sign in to comment.
Something went wrong with that request. Please try again.