TimeRange.h
Go to the documentation of this file.
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_TIMERANGE_H
23 #define FIX_TIMERANGE_H
24 
25 #ifdef _MSC_VER
26 #pragma warning( disable : 4503 4355 4786 4290 )
27 #endif
28 
29 #include "FieldTypes.h"
30 
31 namespace FIX
32 {
34 class TimeRange
35 {
36 public:
37  TimeRange( const UtcTimeOnly& startTime, const UtcTimeOnly& endTime,
38  int startDay = -1, int endDay = -1 );
39 
40  TimeRange( const LocalTimeOnly& startTime, const LocalTimeOnly& endTime,
41  int startDay = -1, int endDay = -1 );
42 
43  static bool isInRange( const UtcTimeOnly& start,
44  const UtcTimeOnly& end,
45  const DateTime& time )
46  {
47  return isInRange
48  ( (DateTime)start, (DateTime)end, (DateTime)time );
49  }
50 
51  static bool isInRange( const UtcTimeOnly& startTime,
52  const UtcTimeOnly& endTime,
53  int startDay,
54  int endDay,
55  const DateTime& time,
56  int day )
57  {
58  return isInRange
59  ( (DateTime)startTime, (DateTime)endTime,
60  startDay, endDay,
61  (DateTime)time, day );
62  }
63 
64  static bool isInRange( const UtcTimeOnly& startTime,
65  const UtcTimeOnly& endTime,
66  int startDay,
67  int endDay,
68  const DateTime& time )
69  {
70  return isInRange
71  ( (DateTime)startTime, (DateTime)endTime,
72  startDay, endDay,
73  (DateTime)time );
74  }
75 
76  static bool isInSameRange( const UtcTimeOnly& start,
77  const UtcTimeOnly& end,
78  const DateTime& time1,
79  const DateTime& time2 )
80  {
81  return isInSameRange
82  ( (DateTime)start, (DateTime)end,
83  (DateTime)time1, (DateTime)time2 );
84  }
85 
86  static bool isInSameRange( const UtcTimeOnly& startTime,
87  const UtcTimeOnly& endTime,
88  int startDay,
89  int endDay,
90  const DateTime& time1,
91  const DateTime& time2 )
92  {
93  return isInSameRange
94  ( (DateTime)startTime, (DateTime)endTime,
95  startDay, endDay,
96  (DateTime)time1, (DateTime)time2 );
97  }
98 
99  static bool isInRange( const LocalTimeOnly& start,
100  const LocalTimeOnly& end,
101  const DateTime& time )
102  {
103  return isInRange
104  ( (DateTime)start, (DateTime)end, (DateTime)time );
105  }
106 
107  static bool isInRange( const LocalTimeOnly& startTime,
108  const LocalTimeOnly& endTime,
109  int startDay,
110  int endDay,
111  const DateTime& time,
112  int day )
113  {
114  return isInRange
115  ( (DateTime)startTime, (DateTime)endTime,
116  startDay, endDay,
117  (DateTime)time, day );
118  }
119 
120  static bool isInRange( const LocalTimeOnly& startTime,
121  const LocalTimeOnly& endTime,
122  int startDay,
123  int endDay,
124  const DateTime& time )
125  {
126  return isInRange
127  ( (DateTime)startTime, (DateTime)endTime,
128  startDay, endDay,
129  (DateTime)time );
130  }
131 
132  static bool isInSameRange( const LocalTimeOnly& start,
133  const LocalTimeOnly& end,
134  const DateTime& time1,
135  const DateTime& time2 )
136  {
137  return isInSameRange
138  ( (DateTime)start, (DateTime)end,
139  (DateTime)time1, (DateTime)time2 );
140  }
141 
142  static bool isInSameRange( const LocalTimeOnly& startTime,
143  const LocalTimeOnly& endTime,
144  int startDay,
145  int endDay,
146  const DateTime& time1,
147  const DateTime& time2 )
148  {
149  return isInSameRange
150  ( (DateTime)startTime, (DateTime)endTime,
151  startDay, endDay,
152  (DateTime)time1, (DateTime)time2 );
153  }
154 
155 private:
156  static bool isInRange( const DateTime& start,
157  const DateTime& end,
158  const DateTime& time );
159 
160  static bool isInRange( const DateTime& startTime,
161  const DateTime& endTime,
162  int startDay,
163  int endDay,
164  const DateTime& time,
165  int day );
166 
167  static bool isInRange( const DateTime& startTime,
168  const DateTime& endTime,
169  int startDay,
170  int endDay,
171  const DateTime& time );
172 
173  static bool isInSameRange( const DateTime& start,
174  const DateTime& end,
175  const DateTime& time1,
176  const DateTime& time2 );
177 
178  static bool isInSameRange( const DateTime& startTime,
179  const DateTime& endTime,
180  int startDay,
181  int endDay,
182  const DateTime& time1,
183  const DateTime& time2 );
184 public:
185  bool isInRange( const DateTime& dateTime, int day )
186  {
187  if( m_startDay < 0 && m_endDay < 0 )
188  return isInRange( m_startTime, m_endTime, dateTime );
189  else
190  return isInRange
191  ( m_startTime, m_endTime, m_startDay, m_endDay, dateTime, day );
192  }
193 
194  bool isInRange( const UtcTimeStamp& dateTime )
195  {
196  if( m_useLocalTime )
197  {
198  LocalTimeStamp localDateTime( dateTime.getTimeT() );
199  return isInRange( localDateTime, localDateTime.getWeekDay() );
200  }
201 
202  return isInRange( dateTime, dateTime.getWeekDay() );
203  }
204 
205  bool isInRange( const LocalTimeStamp& dateTime )
206  {
207  if( !m_useLocalTime )
208  {
209  LocalTimeStamp utcDateTime( dateTime.getTimeT() );
210  return isInRange( utcDateTime, utcDateTime.getWeekDay() );
211  }
212 
213  return isInRange( dateTime, dateTime.getWeekDay() );
214  }
215 
216  bool isInSameRange( const UtcTimeStamp& time1, const UtcTimeStamp& time2 )
217  {
218  if( m_useLocalTime )
219  {
220  LocalTimeStamp localTime1( time1.getTimeT() );
221  LocalTimeStamp localTime2( time2.getTimeT() );
222  return isInSameRange( (DateTime)localTime1, (DateTime)localTime2 );
223  }
224 
225  return isInSameRange( (DateTime)time1, (DateTime)time2 );
226  }
227 
228  bool isInSameRange( const LocalTimeStamp& time1, const LocalTimeStamp& time2 )
229  {
230  if( !m_useLocalTime )
231  {
232  UtcTimeStamp utcTime1( time1.getTimeT() );
233  UtcTimeStamp utcTime2( time2.getTimeT() );
234  return isInSameRange( (DateTime)utcTime1, (DateTime)utcTime2 );
235  }
236 
237  return isInSameRange( (DateTime)time1, (DateTime)time2 );
238  }
239 
240 private:
241  bool isInSameRange( const DateTime& time1, const DateTime& time2 )
242  {
243  if( m_startDay < 0 && m_endDay < 0 )
244  return isInSameRange( m_startTime, m_endTime, time1, time2 );
245  else
246  return isInSameRange
247  ( m_startTime, m_endTime, m_startDay, m_endDay, time1, time2 );
248  }
249 
252  int m_startDay;
253  int m_endDay;
254  bool m_useLocalTime;
255 };
256 }
257 
258 #endif
FIX::DateTime
Definition: FieldTypes.h:77
FIX::TimeRange::m_startTime
UtcTimeOnly m_startTime
Definition: TimeRange.h:284
FIX::TimeRange::m_startDay
int m_startDay
Definition: TimeRange.h:286
FIX::UtcTimeStamp
Date and Time represented in UTC.
Definition: FieldTypes.h:599
FIX::TimeRange::TimeRange
TimeRange(const UtcTimeOnly &startTime, const UtcTimeOnly &endTime, int startDay=-1, int endDay=-1)
Definition: TimeRange.cpp:48
FIX::DateTime::getTimeT
time_t getTimeT() const
Convert the DateTime to a time_t.
Definition: FieldTypes.h:271
FIX::LocalTimeStamp
Date and Time represented in local time.
Definition: FieldTypes.h:650
FIX::TYPE::UtcTimeStamp
@ UtcTimeStamp
Definition: FieldTypes.h:940
FIX::TimeRange::m_endDay
int m_endDay
Definition: TimeRange.h:287
FIX::TYPE::UtcTimeOnly
@ UtcTimeOnly
Definition: FieldTypes.h:950
FIX::TimeRange::m_endTime
UtcTimeOnly m_endTime
Definition: TimeRange.h:285
FIX::LocalTimeOnly
Time only represented in local time.
Definition: FieldTypes.h:759
FIX::TimeRange::isInSameRange
static bool isInSameRange(const UtcTimeOnly &start, const UtcTimeOnly &end, const DateTime &time1, const DateTime &time2)
Definition: TimeRange.h:110
FIX::TimeRange::m_useLocalTime
bool m_useLocalTime
Definition: TimeRange.h:288
FIX
Definition: Acceptor.cpp:34
FIX::TimeRange::isInRange
static bool isInRange(const UtcTimeOnly &start, const UtcTimeOnly &end, const DateTime &time)
Definition: TimeRange.h:77
FIX::DateTime::getWeekDay
int getWeekDay() const
Calculate the weekday of the date (Sunday is 1, Saturday is 7)
Definition: FieldTypes.h:256
FieldTypes.h
FIX::UtcTimeOnly
Time only represented in UTC.
Definition: FieldTypes.h:701

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001