SessionTime.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifdef _MSC_VER
00021 #include "stdafx.h"
00022 #else
00023 #include "config.h"
00024 #endif
00025 #include "CallStack.h"
00026
00027 #include "SessionTime.h"
00028 #include "Utility.h"
00029
00030 namespace FIX
00031 {
00032 SessionTime::SessionTime( const UtcTimeOnly& startTime,
00033 const UtcTimeOnly& endTime,
00034 int startDay,
00035 int endDay )
00036 : m_startTime( startTime ), m_endTime( endTime ),
00037 m_startDay( startDay ), m_endDay( endDay )
00038 {
00039 }
00040
00041 bool SessionTime::isSessionTime( const UtcTimeOnly& start,
00042 const UtcTimeOnly& end,
00043 const UtcTimeStamp& time )
00044 { QF_STACK_PUSH(SessionTime::isSessionTime)
00045
00046 UtcTimeOnly timeOnly (time);
00047
00048 if( start < end )
00049 return( timeOnly >= start && timeOnly <= end );
00050 else
00051 return( timeOnly >= start || timeOnly <= end );
00052
00053 QF_STACK_POP
00054 }
00055
00056 bool SessionTime::isSessionTime( const UtcTimeOnly& startTime,
00057 const UtcTimeOnly& endTime,
00058 int startDay,
00059 int endDay,
00060 const UtcTimeStamp& time )
00061 { QF_STACK_PUSH(SessionTime::isSessionTime)
00062
00063 int currentDay = time.getWeekDay();
00064 UtcTimeOnly timeOnly (time);
00065
00066 if (startDay == endDay)
00067 {
00068 if (currentDay == startDay)
00069 {
00070 return isSessionTime(startTime, endTime, time);
00071 }
00072 if (startTime < endTime)
00073 {
00074 return false;
00075 }
00076 return true;
00077 }
00078
00079 if (startDay < endDay)
00080 {
00081 if (currentDay < startDay || endDay < currentDay ||
00082 (currentDay == startDay && timeOnly < startTime) ||
00083 (currentDay == endDay && endTime < timeOnly))
00084 {
00085 return false;
00086 }
00087 return true;
00088 }
00089
00090 if ((endDay < currentDay && currentDay < startDay) ||
00091 (currentDay == startDay && timeOnly < startTime) ||
00092 (currentDay == endDay && endTime < timeOnly))
00093 {
00094 return false;
00095 }
00096 return true;
00097
00098 QF_STACK_POP
00099 }
00100
00101 bool SessionTime::isSameSession( const UtcTimeOnly& start,
00102 const UtcTimeOnly& end,
00103 const UtcTimeStamp& time1,
00104 const UtcTimeStamp& time2 )
00105 { QF_STACK_PUSH(SessionTime::isSameSession)
00106
00107 if( !isSessionTime( start, end, time1 ) ) return false;
00108 if( !isSessionTime( start, end, time2 ) ) return false;
00109
00110 if( time1 == time2 ) return true;
00111
00112 if( start < end || start == end )
00113 {
00114 UtcDate time1Date( time1 );
00115 UtcDate time2Date( time2 );
00116
00117 return time1Date == time2Date;
00118 }
00119 else
00120 {
00121 int sessionLength = DateTime::SECONDS_PER_DAY - (start - end);
00122
00123 if( time1 > time2 )
00124 {
00125 UtcTimeOnly time2TimeOnly = UtcTimeOnly(time2);
00126
00127 long delta = time2TimeOnly - start;
00128 if( delta < 0 )
00129 delta = DateTime::SECONDS_PER_DAY - labs(delta);
00130
00131 return (time1 - time2) < (sessionLength - delta);
00132 }
00133 else
00134 {
00135 return (time2 - time1) < sessionLength;
00136 }
00137 }
00138
00139 QF_STACK_POP
00140 }
00141
00142 bool SessionTime::isSameSession( const UtcTimeOnly& startTime,
00143 const UtcTimeOnly& endTime,
00144 int startDay,
00145 int endDay,
00146 const UtcTimeStamp& time1,
00147 const UtcTimeStamp& time2 )
00148 { QF_STACK_PUSH(SessionTime::isSameSession)
00149
00150 if( !isSessionTime( startTime, endTime, startDay, endDay, time1 ) )
00151 return false;
00152
00153 if( !isSessionTime( startTime, endTime, startDay, endDay, time2 ) )
00154 return false;
00155
00156 int absoluteDay1 = time1.getJulianDate() - time1.getWeekDay();
00157 int absoluteDay2 = time2.getJulianDate() - time2.getWeekDay();
00158 return absoluteDay1 == absoluteDay2;
00159
00160 QF_STACK_POP
00161 }
00162 }
00163
00164