quickfix_ruby 1.14.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. checksums.yaml +7 -0
  2. data/ext/quickfix/Acceptor.cpp +248 -0
  3. data/ext/quickfix/Acceptor.h +127 -0
  4. data/ext/quickfix/Allocator.h +9 -0
  5. data/ext/quickfix/Application.h +127 -0
  6. data/ext/quickfix/AtomicCount.h +109 -0
  7. data/ext/quickfix/DOMDocument.h +74 -0
  8. data/ext/quickfix/DataDictionary.cpp +618 -0
  9. data/ext/quickfix/DataDictionary.h +539 -0
  10. data/ext/quickfix/DataDictionaryProvider.cpp +71 -0
  11. data/ext/quickfix/DataDictionaryProvider.h +70 -0
  12. data/ext/quickfix/DatabaseConnectionID.h +105 -0
  13. data/ext/quickfix/DatabaseConnectionPool.h +91 -0
  14. data/ext/quickfix/Dictionary.cpp +162 -0
  15. data/ext/quickfix/Dictionary.h +94 -0
  16. data/ext/quickfix/Event.h +95 -0
  17. data/ext/quickfix/Exceptions.h +299 -0
  18. data/ext/quickfix/Field.h +672 -0
  19. data/ext/quickfix/FieldConvertors.h +863 -0
  20. data/ext/quickfix/FieldMap.cpp +238 -0
  21. data/ext/quickfix/FieldMap.h +244 -0
  22. data/ext/quickfix/FieldNumbers.h +46 -0
  23. data/ext/quickfix/FieldTypes.cpp +64 -0
  24. data/ext/quickfix/FieldTypes.h +698 -0
  25. data/ext/quickfix/Fields.h +31 -0
  26. data/ext/quickfix/FileLog.cpp +200 -0
  27. data/ext/quickfix/FileLog.h +112 -0
  28. data/ext/quickfix/FileStore.cpp +332 -0
  29. data/ext/quickfix/FileStore.h +129 -0
  30. data/ext/quickfix/FixFieldNumbers.h +1537 -0
  31. data/ext/quickfix/FixFields.h +1538 -0
  32. data/ext/quickfix/FixValues.h +3281 -0
  33. data/ext/quickfix/FlexLexer.h +188 -0
  34. data/ext/quickfix/Group.cpp +64 -0
  35. data/ext/quickfix/Group.h +73 -0
  36. data/ext/quickfix/HtmlBuilder.h +186 -0
  37. data/ext/quickfix/HttpConnection.cpp +739 -0
  38. data/ext/quickfix/HttpConnection.h +78 -0
  39. data/ext/quickfix/HttpMessage.cpp +149 -0
  40. data/ext/quickfix/HttpMessage.h +133 -0
  41. data/ext/quickfix/HttpParser.cpp +49 -0
  42. data/ext/quickfix/HttpParser.h +54 -0
  43. data/ext/quickfix/HttpServer.cpp +169 -0
  44. data/ext/quickfix/HttpServer.h +78 -0
  45. data/ext/quickfix/Initiator.cpp +289 -0
  46. data/ext/quickfix/Initiator.h +149 -0
  47. data/ext/quickfix/Log.cpp +77 -0
  48. data/ext/quickfix/Log.h +179 -0
  49. data/ext/quickfix/Message.cpp +580 -0
  50. data/ext/quickfix/Message.h +370 -0
  51. data/ext/quickfix/MessageCracker.h +188 -0
  52. data/ext/quickfix/MessageSorters.cpp +105 -0
  53. data/ext/quickfix/MessageSorters.h +156 -0
  54. data/ext/quickfix/MessageStore.cpp +146 -0
  55. data/ext/quickfix/MessageStore.h +174 -0
  56. data/ext/quickfix/Mutex.h +131 -0
  57. data/ext/quickfix/MySQLConnection.h +194 -0
  58. data/ext/quickfix/MySQLLog.cpp +275 -0
  59. data/ext/quickfix/MySQLLog.h +145 -0
  60. data/ext/quickfix/MySQLStore.cpp +331 -0
  61. data/ext/quickfix/MySQLStore.h +142 -0
  62. data/ext/quickfix/NullStore.cpp +54 -0
  63. data/ext/quickfix/NullStore.h +99 -0
  64. data/ext/quickfix/OdbcConnection.h +266 -0
  65. data/ext/quickfix/OdbcLog.cpp +252 -0
  66. data/ext/quickfix/OdbcLog.h +117 -0
  67. data/ext/quickfix/OdbcStore.cpp +338 -0
  68. data/ext/quickfix/OdbcStore.h +113 -0
  69. data/ext/quickfix/PUGIXML_DOMDocument.cpp +112 -0
  70. data/ext/quickfix/PUGIXML_DOMDocument.h +81 -0
  71. data/ext/quickfix/Parser.cpp +103 -0
  72. data/ext/quickfix/Parser.h +57 -0
  73. data/ext/quickfix/PostgreSQLConnection.h +176 -0
  74. data/ext/quickfix/PostgreSQLLog.cpp +276 -0
  75. data/ext/quickfix/PostgreSQLLog.h +144 -0
  76. data/ext/quickfix/PostgreSQLStore.cpp +334 -0
  77. data/ext/quickfix/PostgreSQLStore.h +141 -0
  78. data/ext/quickfix/Queue.h +75 -0
  79. data/ext/quickfix/QuickfixRuby.cpp +252066 -0
  80. data/ext/quickfix/QuickfixRuby.h +34 -0
  81. data/ext/quickfix/Responder.h +43 -0
  82. data/ext/quickfix/Session.cpp +1487 -0
  83. data/ext/quickfix/Session.h +335 -0
  84. data/ext/quickfix/SessionFactory.cpp +274 -0
  85. data/ext/quickfix/SessionFactory.h +86 -0
  86. data/ext/quickfix/SessionID.h +170 -0
  87. data/ext/quickfix/SessionSettings.cpp +189 -0
  88. data/ext/quickfix/SessionSettings.h +171 -0
  89. data/ext/quickfix/SessionState.h +231 -0
  90. data/ext/quickfix/Settings.cpp +100 -0
  91. data/ext/quickfix/Settings.h +53 -0
  92. data/ext/quickfix/SharedArray.h +150 -0
  93. data/ext/quickfix/SocketAcceptor.cpp +222 -0
  94. data/ext/quickfix/SocketAcceptor.h +75 -0
  95. data/ext/quickfix/SocketConnection.cpp +238 -0
  96. data/ext/quickfix/SocketConnection.h +103 -0
  97. data/ext/quickfix/SocketConnector.cpp +116 -0
  98. data/ext/quickfix/SocketConnector.h +67 -0
  99. data/ext/quickfix/SocketInitiator.cpp +260 -0
  100. data/ext/quickfix/SocketInitiator.h +81 -0
  101. data/ext/quickfix/SocketMonitor.cpp +335 -0
  102. data/ext/quickfix/SocketMonitor.h +111 -0
  103. data/ext/quickfix/SocketServer.cpp +177 -0
  104. data/ext/quickfix/SocketServer.h +100 -0
  105. data/ext/quickfix/ThreadedSocketAcceptor.cpp +258 -0
  106. data/ext/quickfix/ThreadedSocketAcceptor.h +98 -0
  107. data/ext/quickfix/ThreadedSocketConnection.cpp +209 -0
  108. data/ext/quickfix/ThreadedSocketConnection.h +82 -0
  109. data/ext/quickfix/ThreadedSocketInitiator.cpp +268 -0
  110. data/ext/quickfix/ThreadedSocketInitiator.h +84 -0
  111. data/ext/quickfix/TimeRange.cpp +173 -0
  112. data/ext/quickfix/TimeRange.h +258 -0
  113. data/ext/quickfix/Utility.cpp +537 -0
  114. data/ext/quickfix/Utility.h +219 -0
  115. data/ext/quickfix/Values.h +62 -0
  116. data/ext/quickfix/config.h +0 -0
  117. data/ext/quickfix/config_windows.h +0 -0
  118. data/ext/quickfix/extconf.rb +12 -0
  119. data/ext/quickfix/index.h +37 -0
  120. data/ext/quickfix/pugiconfig.hpp +72 -0
  121. data/ext/quickfix/pugixml.cpp +10765 -0
  122. data/ext/quickfix/pugixml.hpp +1341 -0
  123. data/ext/quickfix/strptime.h +7 -0
  124. data/lib/quickfix40.rb +274 -0
  125. data/lib/quickfix41.rb +351 -0
  126. data/lib/quickfix42.rb +1184 -0
  127. data/lib/quickfix43.rb +3504 -0
  128. data/lib/quickfix44.rb +10721 -0
  129. data/lib/quickfix50.rb +13426 -0
  130. data/lib/quickfix50sp1.rb +15629 -0
  131. data/lib/quickfix50sp2.rb +17068 -0
  132. data/lib/quickfix_fields.rb +19853 -0
  133. data/lib/quickfix_ruby.rb +82 -0
  134. data/lib/quickfixt11.rb +70 -0
  135. data/spec/FIX40.xml +862 -0
  136. data/spec/FIX41.xml +1285 -0
  137. data/spec/FIX42.xml +2746 -0
  138. data/spec/FIX43.xml +4229 -0
  139. data/spec/FIX44.xml +6596 -0
  140. data/spec/FIX50.xml +8137 -0
  141. data/spec/FIX50SP1.xml +9496 -0
  142. data/spec/FIX50SP2.xml +10011 -0
  143. data/spec/FIXT11.xml +313 -0
  144. data/test/test_DataDictionaryTestCase.rb +268 -0
  145. data/test/test_DictionaryTestCase.rb +112 -0
  146. data/test/test_FieldBaseTestCase.rb +24 -0
  147. data/test/test_MessageTestCase.rb +368 -0
  148. data/test/test_SessionSettingsTestCase.rb +41 -0
  149. metadata +193 -0
@@ -0,0 +1,268 @@
1
+ /****************************************************************************
2
+ ** Copyright (c) 2001-2014
3
+ **
4
+ ** This file is part of the QuickFIX FIX Engine
5
+ **
6
+ ** This file may be distributed under the terms of the quickfixengine.org
7
+ ** license as defined by quickfixengine.org and appearing in the file
8
+ ** LICENSE included in the packaging of this file.
9
+ **
10
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12
+ **
13
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
14
+ **
15
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
16
+ ** not clear to you.
17
+ **
18
+ ****************************************************************************/
19
+
20
+ #ifdef _MSC_VER
21
+ #include "stdafx.h"
22
+ #else
23
+ #include "config.h"
24
+ #endif
25
+
26
+ #include "ThreadedSocketInitiator.h"
27
+ #include "Session.h"
28
+ #include "Settings.h"
29
+
30
+ namespace FIX
31
+ {
32
+ ThreadedSocketInitiator::ThreadedSocketInitiator(
33
+ Application& application,
34
+ MessageStoreFactory& factory,
35
+ const SessionSettings& settings ) throw( ConfigError )
36
+ : Initiator( application, factory, settings ),
37
+ m_lastConnect( 0 ), m_reconnectInterval( 30 ), m_noDelay( false ),
38
+ m_sendBufSize( 0 ), m_rcvBufSize( 0 )
39
+ {
40
+ socket_init();
41
+ }
42
+
43
+ ThreadedSocketInitiator::ThreadedSocketInitiator(
44
+ Application& application,
45
+ MessageStoreFactory& factory,
46
+ const SessionSettings& settings,
47
+ LogFactory& logFactory ) throw( ConfigError )
48
+ : Initiator( application, factory, settings, logFactory ),
49
+ m_lastConnect( 0 ), m_reconnectInterval( 30 ), m_noDelay( false ),
50
+ m_sendBufSize( 0 ), m_rcvBufSize( 0 )
51
+ {
52
+ socket_init();
53
+ }
54
+
55
+ ThreadedSocketInitiator::~ThreadedSocketInitiator()
56
+ {
57
+ socket_term();
58
+ }
59
+
60
+ void ThreadedSocketInitiator::onConfigure( const SessionSettings& s )
61
+ throw ( ConfigError )
62
+ {
63
+ const Dictionary& dict = s.get();
64
+
65
+ if( dict.has( RECONNECT_INTERVAL ) )
66
+ m_reconnectInterval = dict.getInt( RECONNECT_INTERVAL );
67
+ if( dict.has( SOCKET_NODELAY ) )
68
+ m_noDelay = dict.getBool( SOCKET_NODELAY );
69
+ if( dict.has( SOCKET_SEND_BUFFER_SIZE ) )
70
+ m_sendBufSize = dict.getInt( SOCKET_SEND_BUFFER_SIZE );
71
+ if( dict.has( SOCKET_RECEIVE_BUFFER_SIZE ) )
72
+ m_rcvBufSize = dict.getInt( SOCKET_RECEIVE_BUFFER_SIZE );
73
+ }
74
+
75
+ void ThreadedSocketInitiator::onInitialize( const SessionSettings& s )
76
+ throw ( RuntimeError )
77
+ {
78
+ }
79
+
80
+ void ThreadedSocketInitiator::onStart()
81
+ {
82
+ while ( !isStopped() )
83
+ {
84
+ time_t now;
85
+ ::time( &now );
86
+
87
+ if ( (now - m_lastConnect) >= m_reconnectInterval )
88
+ {
89
+ Locker l( m_mutex );
90
+ connect();
91
+ m_lastConnect = now;
92
+ }
93
+
94
+ process_sleep( 1 );
95
+ }
96
+ }
97
+
98
+ bool ThreadedSocketInitiator::onPoll( double timeout )
99
+ {
100
+ return false;
101
+ }
102
+
103
+ void ThreadedSocketInitiator::onStop()
104
+ {
105
+ SocketToThread threads;
106
+ SocketToThread::iterator i;
107
+
108
+ {
109
+ Locker l(m_mutex);
110
+
111
+ time_t start = 0;
112
+ time_t now = 0;
113
+
114
+ ::time( &start );
115
+ while ( isLoggedOn() )
116
+ {
117
+ if( ::time(&now) -5 >= start )
118
+ break;
119
+ }
120
+
121
+ threads = m_threads;
122
+ m_threads.clear();
123
+ }
124
+
125
+ for ( i = threads.begin(); i != threads.end(); ++i )
126
+ socket_close( i->first );
127
+
128
+ for ( i = threads.begin(); i != threads.end(); ++i )
129
+ thread_join( i->second );
130
+ threads.clear();
131
+ }
132
+
133
+ void ThreadedSocketInitiator::doConnect( const SessionID& s, const Dictionary& d )
134
+ {
135
+ try
136
+ {
137
+ Session* session = Session::lookupSession( s );
138
+ if( !session->isSessionTime(UtcTimeStamp()) ) return;
139
+
140
+ Log* log = session->getLog();
141
+
142
+ std::string address;
143
+ short port = 0;
144
+ getHost( s, d, address, port );
145
+
146
+ int socket = socket_createConnector();
147
+ if( m_noDelay )
148
+ socket_setsockopt( socket, TCP_NODELAY );
149
+ if( m_sendBufSize )
150
+ socket_setsockopt( socket, SO_SNDBUF, m_sendBufSize );
151
+ if( m_rcvBufSize )
152
+ socket_setsockopt( socket, SO_RCVBUF, m_rcvBufSize );
153
+
154
+ setPending( s );
155
+ log->onEvent( "Connecting to " + address + " on port " + IntConvertor::convert((unsigned short)port) );
156
+
157
+ ThreadedSocketConnection* pConnection =
158
+ new ThreadedSocketConnection( s, socket, address, port, getLog() );
159
+
160
+ ThreadPair* pair = new ThreadPair( this, pConnection );
161
+
162
+ {
163
+ Locker l( m_mutex );
164
+ thread_id thread;
165
+ if ( thread_spawn( &socketThread, pair, thread ) )
166
+ {
167
+ addThread( socket, thread );
168
+ }
169
+ else
170
+ {
171
+ delete pair;
172
+ pConnection->disconnect();
173
+ delete pConnection;
174
+ setDisconnected( s );
175
+ }
176
+ }
177
+ }
178
+ catch ( std::exception& ) {}
179
+ }
180
+
181
+ void ThreadedSocketInitiator::addThread( int s, thread_id t )
182
+ {
183
+ Locker l(m_mutex);
184
+
185
+ m_threads[ s ] = t;
186
+ }
187
+
188
+ void ThreadedSocketInitiator::removeThread( int s )
189
+ {
190
+ Locker l(m_mutex);
191
+ SocketToThread::iterator i = m_threads.find( s );
192
+
193
+ if ( i != m_threads.end() )
194
+ {
195
+ thread_detach( i->second );
196
+ m_threads.erase( i );
197
+ }
198
+ }
199
+
200
+ THREAD_PROC ThreadedSocketInitiator::socketThread( void* p )
201
+ {
202
+ ThreadPair * pair = reinterpret_cast < ThreadPair* > ( p );
203
+
204
+ ThreadedSocketInitiator* pInitiator = pair->first;
205
+ ThreadedSocketConnection* pConnection = pair->second;
206
+ FIX::SessionID sessionID = pConnection->getSession()->getSessionID();
207
+ FIX::Session* pSession = FIX::Session::lookupSession( sessionID );
208
+ int socket = pConnection->getSocket();
209
+ delete pair;
210
+
211
+ pInitiator->lock();
212
+
213
+ if( !pConnection->connect() )
214
+ {
215
+ pInitiator->getLog()->onEvent( "Connection failed" );
216
+ pConnection->disconnect();
217
+ delete pConnection;
218
+ pInitiator->removeThread( socket );
219
+ pInitiator->setDisconnected( sessionID );
220
+ return 0;
221
+ }
222
+
223
+ pInitiator->setConnected( sessionID );
224
+ pInitiator->getLog()->onEvent( "Connection succeeded" );
225
+
226
+ pSession->next();
227
+
228
+ while ( pConnection->read() ) {}
229
+
230
+ delete pConnection;
231
+ if( !pInitiator->isStopped() )
232
+ pInitiator->removeThread( socket );
233
+
234
+ pInitiator->setDisconnected( sessionID );
235
+ return 0;
236
+ }
237
+
238
+ void ThreadedSocketInitiator::getHost( const SessionID& s, const Dictionary& d,
239
+ std::string& address, short& port )
240
+ {
241
+ int num = 0;
242
+ SessionToHostNum::iterator i = m_sessionToHostNum.find( s );
243
+ if ( i != m_sessionToHostNum.end() ) num = i->second;
244
+
245
+ std::stringstream hostStream;
246
+ hostStream << SOCKET_CONNECT_HOST << num;
247
+ std::string hostString = hostStream.str();
248
+
249
+ std::stringstream portStream;
250
+ portStream << SOCKET_CONNECT_PORT << num;
251
+ std::string portString = portStream.str();
252
+
253
+ if( d.has(hostString) && d.has(portString) )
254
+ {
255
+ address = d.getString( hostString );
256
+ port = ( short ) d.getInt( portString );
257
+ }
258
+ else
259
+ {
260
+ num = 0;
261
+ address = d.getString( SOCKET_CONNECT_HOST );
262
+ port = ( short ) d.getInt( SOCKET_CONNECT_PORT );
263
+ }
264
+
265
+ m_sessionToHostNum[ s ] = ++num;
266
+ }
267
+
268
+ }
@@ -0,0 +1,84 @@
1
+ /* -*- C++ -*- */
2
+
3
+ /****************************************************************************
4
+ ** Copyright (c) 2001-2014
5
+ **
6
+ ** This file is part of the QuickFIX FIX Engine
7
+ **
8
+ ** This file may be distributed under the terms of the quickfixengine.org
9
+ ** license as defined by quickfixengine.org and appearing in the file
10
+ ** LICENSE included in the packaging of this file.
11
+ **
12
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
13
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
14
+ **
15
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
16
+ **
17
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
18
+ ** not clear to you.
19
+ **
20
+ ****************************************************************************/
21
+
22
+ #ifndef FIX_THREADEDSOCKETINITIATOR_H
23
+ #define FIX_THREADEDSOCKETINITIATOR_H
24
+
25
+ #ifdef _MSC_VER
26
+ #pragma warning( disable : 4503 4355 4786 4290 )
27
+ #endif
28
+
29
+ #include "Initiator.h"
30
+ #include "ThreadedSocketConnection.h"
31
+ #include <map>
32
+
33
+ namespace FIX
34
+ {
35
+ /*! \addtogroup user
36
+ * @{
37
+ */
38
+ /// Threaded Socket implementation of Initiator.
39
+ class ThreadedSocketInitiator : public Initiator
40
+ {
41
+ public:
42
+ ThreadedSocketInitiator( Application&, MessageStoreFactory&,
43
+ const SessionSettings& ) throw( ConfigError );
44
+ ThreadedSocketInitiator( Application&, MessageStoreFactory&,
45
+ const SessionSettings&,
46
+ LogFactory& ) throw( ConfigError );
47
+
48
+ virtual ~ThreadedSocketInitiator();
49
+
50
+ private:
51
+ typedef std::map < int, thread_id > SocketToThread;
52
+ typedef std::map < SessionID, int > SessionToHostNum;
53
+ typedef std::pair < ThreadedSocketInitiator*, ThreadedSocketConnection* > ThreadPair;
54
+
55
+ void onConfigure( const SessionSettings& ) throw ( ConfigError );
56
+ void onInitialize( const SessionSettings& ) throw ( RuntimeError );
57
+
58
+ void onStart();
59
+ bool onPoll( double timeout );
60
+ void onStop();
61
+
62
+ void doConnect( const SessionID& s, const Dictionary& d );
63
+
64
+ void addThread( int s, thread_id t );
65
+ void removeThread( int s );
66
+ void lock() { Locker l(m_mutex); }
67
+ static THREAD_PROC socketThread( void* p );
68
+
69
+ void getHost( const SessionID&, const Dictionary&, std::string&, short& );
70
+
71
+ SessionSettings m_settings;
72
+ SessionToHostNum m_sessionToHostNum;
73
+ time_t m_lastConnect;
74
+ int m_reconnectInterval;
75
+ bool m_noDelay;
76
+ int m_sendBufSize;
77
+ int m_rcvBufSize;
78
+ SocketToThread m_threads;
79
+ Mutex m_mutex;
80
+ };
81
+ /*! @} */
82
+ }
83
+
84
+ #endif //FIX_THREADEDSOCKETINITIATOR_H
@@ -0,0 +1,173 @@
1
+ /****************************************************************************
2
+ ** Copyright (c) 2001-2014
3
+ **
4
+ ** This file is part of the QuickFIX FIX Engine
5
+ **
6
+ ** This file may be distributed under the terms of the quickfixengine.org
7
+ ** license as defined by quickfixengine.org and appearing in the file
8
+ ** LICENSE included in the packaging of this file.
9
+ **
10
+ ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11
+ ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12
+ **
13
+ ** See http://www.quickfixengine.org/LICENSE for licensing information.
14
+ **
15
+ ** Contact ask@quickfixengine.org if any conditions of this licensing are
16
+ ** not clear to you.
17
+ **
18
+ ****************************************************************************/
19
+
20
+ #ifdef _MSC_VER
21
+ #include "stdafx.h"
22
+ #else
23
+ #include "config.h"
24
+ #endif
25
+
26
+ #include "TimeRange.h"
27
+ #include "Utility.h"
28
+
29
+ namespace FIX
30
+ {
31
+ TimeRange::TimeRange( const UtcTimeOnly& startTime,
32
+ const UtcTimeOnly& endTime,
33
+ int startDay,
34
+ int endDay )
35
+ : m_startTime( startTime ), m_endTime( endTime ),
36
+ m_startDay( startDay ), m_endDay( endDay ),
37
+ m_useLocalTime( false )
38
+ {
39
+ if( startDay > 0
40
+ && endDay > 0
41
+ && startDay == endDay
42
+ && endTime > startTime )
43
+ { m_endTime = m_startTime; }
44
+ }
45
+
46
+ TimeRange::TimeRange( const LocalTimeOnly& startTime,
47
+ const LocalTimeOnly& endTime,
48
+ int startDay,
49
+ int endDay )
50
+ : m_startTime( startTime ), m_endTime( endTime ),
51
+ m_startDay( startDay ), m_endDay( endDay ),
52
+ m_useLocalTime( true )
53
+ {
54
+ if( startDay > 0
55
+ && endDay > 0
56
+ && startDay == endDay
57
+ && endTime > startTime )
58
+ { m_endTime = m_startTime; }
59
+ }
60
+
61
+ bool TimeRange::isInRange( const DateTime& start,
62
+ const DateTime& end,
63
+ const DateTime& time )
64
+ {
65
+ UtcTimeOnly timeOnly (time);
66
+
67
+ if( start < end )
68
+ return( timeOnly >= start && timeOnly <= end );
69
+ else
70
+ return( timeOnly >= start || timeOnly <= end );
71
+ }
72
+
73
+ bool TimeRange::isInRange( const DateTime& startTime,
74
+ const DateTime& endTime,
75
+ int startDay,
76
+ int endDay,
77
+ const DateTime& time,
78
+ int day )
79
+ {
80
+ UtcTimeOnly timeOnly (time);
81
+
82
+ if( startDay == endDay )
83
+ {
84
+ if( day != startDay )
85
+ return true;
86
+ return isInRange( startTime, endTime, time );
87
+ }
88
+ else if( startDay < endDay )
89
+ {
90
+ if( day < startDay || day > endDay )
91
+ return false;
92
+ else if( day == startDay && timeOnly < startTime )
93
+ return false;
94
+ else if( day == endDay && timeOnly > endTime )
95
+ return false;
96
+ }
97
+ else if( startDay > endDay )
98
+ {
99
+ if( day < startDay && day > endDay )
100
+ return false;
101
+ else if( day == startDay && timeOnly < startTime )
102
+ return false;
103
+ else if( day == endDay && timeOnly > endTime )
104
+ return false;
105
+ }
106
+ return true;
107
+ }
108
+
109
+ bool TimeRange::isInRange( const DateTime& startTime,
110
+ const DateTime& endTime,
111
+ int startDay,
112
+ int endDay,
113
+ const DateTime& time )
114
+ {
115
+ return isInRange( startTime, endTime, startDay, endDay, time, time.getWeekDay() );
116
+ }
117
+
118
+ bool TimeRange::isInSameRange( const DateTime& start,
119
+ const DateTime& end,
120
+ const DateTime& time1,
121
+ const DateTime& time2 )
122
+ {
123
+ if( !isInRange( start, end, time1 ) ) return false;
124
+ if( !isInRange( start, end, time2 ) ) return false;
125
+
126
+ if( time1 == time2 ) return true;
127
+
128
+ if( start < end || start == end )
129
+ {
130
+ UtcDate time1Date( time1 );
131
+ UtcDate time2Date( time2 );
132
+
133
+ return time1Date == time2Date;
134
+ }
135
+ else
136
+ {
137
+ int sessionLength = DateTime::SECONDS_PER_DAY - (start - end);
138
+
139
+ if( time1 > time2 )
140
+ {
141
+ UtcTimeOnly time2TimeOnly = UtcTimeOnly(time2);
142
+
143
+ long delta = time2TimeOnly - start;
144
+ if( delta < 0 )
145
+ delta = DateTime::SECONDS_PER_DAY - labs(delta);
146
+
147
+ return (time1 - time2) < (sessionLength - delta);
148
+ }
149
+ else
150
+ {
151
+ return (time2 - time1) < sessionLength;
152
+ }
153
+ }
154
+ }
155
+
156
+ bool TimeRange::isInSameRange( const DateTime& startTime,
157
+ const DateTime& endTime,
158
+ int startDay,
159
+ int endDay,
160
+ const DateTime& time1,
161
+ const DateTime& time2 )
162
+ {
163
+ if( !isInRange( startTime, endTime, startDay, endDay, time1, time1.getWeekDay() ) )
164
+ return false;
165
+
166
+ if( !isInRange( startTime, endTime, startDay, endDay, time2, time2.getWeekDay() ) )
167
+ return false;
168
+
169
+ int absoluteDay1 = time1.getJulianDate() - time1.getWeekDay();
170
+ int absoluteDay2 = time2.getJulianDate() - time2.getWeekDay();
171
+ return absoluteDay1 == absoluteDay2;
172
+ }
173
+ }