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 if( startDay > 0
00040 && endDay > 0
00041 && startDay == endDay
00042 && endTime > startTime )
00043 { m_endTime = m_startTime; }
00044 }
00045
00046 bool SessionTime::isSessionTime( const UtcTimeOnly& start,
00047 const UtcTimeOnly& end,
00048 const UtcTimeStamp& time )
00049 { QF_STACK_PUSH(SessionTime::isSessionTime)
00050
00051 UtcTimeOnly timeOnly (time);
00052
00053 if( start < end )
00054 return( timeOnly >= start && timeOnly <= end );
00055 else
00056 return( timeOnly >= start || timeOnly <= end );
00057
00058 QF_STACK_POP
00059 }
00060
00061 bool SessionTime::isSessionTime( const UtcTimeOnly& startTime,
00062 const UtcTimeOnly& endTime,
00063 int startDay,
00064 int endDay,
00065 const UtcTimeStamp& time )
00066 { QF_STACK_PUSH(SessionTime::isSessionTime)
00067
00068 int currentDay = time.getWeekDay();
00069 UtcTimeOnly timeOnly (time);
00070
00071 if( startDay == endDay )
00072 {
00073 if( timeOnly < startTime && timeOnly > endTime )
00074 return false;
00075 }
00076 else if( startDay < endDay )
00077 {
00078 if( currentDay < startDay || currentDay > endDay )
00079 return false;
00080 else if( currentDay == startDay && timeOnly < startTime )
00081 return false;
00082 else if( currentDay == endDay && timeOnly > endTime )
00083 return false;
00084 }
00085 else if( startDay > endDay )
00086 {
00087 if( currentDay < startDay && currentDay > endDay )
00088 return false;
00089 else if( currentDay == startDay && timeOnly < startTime )
00090 return false;
00091 else if( currentDay == endDay && timeOnly > endTime )
00092 return false;
00093 }
00094 return true;
00095 QF_STACK_POP
00096 }
00097
00098 bool SessionTime::isSameSession( const UtcTimeOnly& start,
00099 const UtcTimeOnly& end,
00100 const UtcTimeStamp& time1,
00101 const UtcTimeStamp& time2 )
00102 { QF_STACK_PUSH(SessionTime::isSameSession)
00103
00104 if( !isSessionTime( start, end, time1 ) ) return false;
00105 if( !isSessionTime( start, end, time2 ) ) return false;
00106
00107 if( time1 == time2 ) return true;
00108
00109 if( start < end || start == end )
00110 {
00111 UtcDate time1Date( time1 );
00112 UtcDate time2Date( time2 );
00113
00114 return time1Date == time2Date;
00115 }
00116 else
00117 {
00118 int sessionLength = DateTime::SECONDS_PER_DAY - (start - end);
00119
00120 if( time1 > time2 )
00121 {
00122 UtcTimeOnly time2TimeOnly = UtcTimeOnly(time2);
00123
00124 long delta = time2TimeOnly - start;
00125 if( delta < 0 )
00126 delta = DateTime::SECONDS_PER_DAY - labs(delta);
00127
00128 return (time1 - time2) < (sessionLength - delta);
00129 }
00130 else
00131 {
00132 return (time2 - time1) < sessionLength;
00133 }
00134 }
00135
00136 QF_STACK_POP
00137 }
00138
00139 bool SessionTime::isSameSession( const UtcTimeOnly& startTime,
00140 const UtcTimeOnly& endTime,
00141 int startDay,
00142 int endDay,
00143 const UtcTimeStamp& time1,
00144 const UtcTimeStamp& time2 )
00145 { QF_STACK_PUSH(SessionTime::isSameSession)
00146
00147 if( !isSessionTime( startTime, endTime, startDay, endDay, time1 ) )
00148 return false;
00149
00150 if( !isSessionTime( startTime, endTime, startDay, endDay, time2 ) )
00151 return false;
00152
00153 int absoluteDay1 = time1.getJulianDate() - time1.getWeekDay();
00154 int absoluteDay2 = time2.getJulianDate() - time2.getWeekDay();
00155 return absoluteDay1 == absoluteDay2;
00156
00157 QF_STACK_POP
00158 }
00159 }