Re: [Quickfix-developers] RE: Session *NOT* Resetting
Brought to you by:
orenmnero
|
From: Oren M. <or...@qu...> - 2006-03-15 07:27:26
|
Thank you very much for providing unit tests. This patch has been added to CVS. --oren Yihu Fang wrote: > Jonathan, > > From the example you provided, I did a unit test and indeed it looks > like that the isSameSession() does not pass the test. > >>> My session start time is 10:00 (5 am est) > >>> My session end time is 02:00:00 (9 pm est) > >>> Day one, my session starts at 5:00:14. Next day, the session starts > up at 5:00:11.. > > // start time is greater than end time > > start = UtcTimeOnly( 10, 0, 0 ); > > end = UtcTimeOnly( 2, 0, 0 ); > > // same session time 1 is in next day > > time1 = UtcTimeStamp( 10, 0, 11, 9, 3, 2006 ); > > time2 = UtcTimeStamp( 10, 0, 14, 8, 3, 2006 ); > > assert( !SessionTime::isSameSession( start, end, time1, time2 ) ); > > As you noticed that when the startTime is ahead of endTime (next day), > the following simple check in method isSameSession() is not valid > > return labs( time1 - time2 ) < DateTime::SECONDS_PER_DAY; > > Because the current time2 (creation time) could be at any where within > the session window between start and end. A simple compare of current > time (time1) and creation time (time2) is not enough. A bit more check > to ensure that the (time1 – time2) is within the session window is needed. > > Attached please find the patch of SessionTime.cpp. I also provide some > more unit test cases in SessionTimeTestCase.cpp. The patch seems to > solve the problem and it also passes all the unit tests. > > Thanks, > > -Yihu > > > > To find out more about Reuters visit www.about.reuters.com > > Any views expressed in this message are those of the individual > sender, except where the sender specifically states them to be the > views of Reuters Ltd. > >------------------------------------------------------------------------ > >--- SessionTime.cpp 2006-03-09 22:08:49.060525200 -0500 >+++ SessionTime.cpp.new 2006-03-09 21:58:45.598807200 -0500 >@@ -112,7 +112,21 @@ > if( start < end || start == end ) > return time1Date == time2Date; > else if( start > end ) >- return labs( time1 - time2 ) < DateTime::SECONDS_PER_DAY; >+ { >+ UtcTimeOnly time2TimeOnly = UtcTimeOnly(time2); >+ long delta = time2TimeOnly - start; >+ if (delta < 0) >+ delta = DateTime::SECONDS_PER_DAY + delta; >+ >+ int sessionLength = DateTime::SECONDS_PER_DAY - (start - end); >+ bool result; >+ if (time1 > time2) >+ result = (time1 - time2) < (sessionLength - delta); >+ else >+ result = (time2 - time1) < sessionLength; >+ return result; >+ // return labs( time1 - time2 ) < DateTime::SECONDS_PER_DAY; >+ } > return false; > > QF_STACK_POP > > >------------------------------------------------------------------------ > >--- SessionTimeTestCase.cpp 2006-03-09 22:15:01.300718300 -0500 >+++ SessionTimeTestCase.cpp.new 2006-03-09 21:58:11.680373100 -0500 >@@ -190,6 +190,31 @@ > time2 = UtcTimeStamp( 19, 06, 0, 1, 14, 2004 ); > assert( !SessionTime::isSameSession( start, end, time1, time2 ) ); > assert( !SessionTime::isSameSession( start, end, time2, time1 ) ); >+ >+ // start time is greater than end time >+ start = UtcTimeOnly( 10, 0, 0 ); >+ end = UtcTimeOnly( 2, 0, 0 ); >+ >+ // same session time 1 is in next day >+ time1 = UtcTimeStamp( 10, 0, 11, 9, 3, 2006 ); >+ time2 = UtcTimeStamp( 10, 0, 14, 8, 3, 2006 ); >+ assert( !SessionTime::isSameSession( start, end, time1, time2 ) ); >+ >+ // same session time 1 is in next day >+ start = UtcTimeOnly( 16, 0, 0 ); >+ end = UtcTimeOnly( 15, 0, 0 ); >+ >+ time1 = UtcTimeStamp( 14, 0, 0, 9, 3, 2006 ); >+ time2 = UtcTimeStamp( 1, 0, 0, 9, 3, 2006 ); >+ assert (SessionTime::isSameSession( start, end, time1, time2 ) ); // yes >+ time2 = UtcTimeStamp( 23, 0, 0, 8, 3, 2006 ); >+ assert( SessionTime::isSameSession( start, end, time1, time2 ) ); // yes >+ >+ time1 = UtcTimeStamp( 17, 0, 0, 9, 3, 2006 ); >+ time2 = UtcTimeStamp( 1, 0, 0, 9, 3, 2006 ); >+ assert( !SessionTime::isSameSession( start, end, time1, time2 ) ); // no >+ time2 = UtcTimeStamp( 23, 0, 0, 8, 3, 2006 ); >+ assert( !SessionTime::isSameSession( start, end, time1, time2 ) ); // no > } > > void SessionTimeTestCase::isSameSessionWithDay::onRun( SessionTime& object ) > > |