OpenMAMA C++ API
MamaDateTime.h
Go to the documentation of this file.
1 /* $Id$
2  *
3  * OpenMAMA: The open middleware agnostic messaging API
4  * Copyright (C) 2011 NYSE Technologies, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301 USA
20  */
21 
22 #ifndef MamaDateTimeHpp__
23 #define MamaDateTimeHpp__
24 
25 #include <mama/datetime.h>
26 #include <mama/MamaTimeZone.h>
27 
28 
29 
30 namespace Wombat
31 {
32 
67 class MAMACPPExpDLL MamaDateTime
68 {
69 public:
70  MamaDateTime ();
71  MamaDateTime (const MamaDateTime& copy);
72 
77  explicit MamaDateTime (const char* str,
78  const MamaTimeZone* tz = NULL);
79 
80  ~MamaDateTime ();
81 
82  MamaDateTime& operator= (const MamaDateTime& rhs);
83  bool operator== (const MamaDateTime& rhs) const;
84  bool operator!= (const MamaDateTime& rhs) const
85  { return ! operator== (rhs); }
86  bool operator< (const MamaDateTime& rhs) const;
87  bool operator> (const MamaDateTime& rhs) const;
88  int compare (const MamaDateTime& rhs) const;
89  bool empty () const;
90 
91  void setEpochTime (mama_u32_t secondsSinceEpoch,
92  mama_u32_t microseconds,
93  mamaDateTimePrecision precision =
94  MAMA_DATE_TIME_PREC_UNKNOWN);
95  void setEpochTimeF64 (double secondsSinceEpoch);
96  void setEpochTimeMilliseconds (
97  mama_u64_t millisecondsSinceEpoch);
98  void setEpochTimeMicroseconds (
99  mama_u64_t microsecondsSinceEpoch);
100  void setWithHints (mama_u32_t secondsSinceEpoch,
101  mama_u32_t microseconds,
102  mamaDateTimePrecision precision =
103  MAMA_DATE_TIME_PREC_UNKNOWN,
104  mamaDateTimeHints hints = 0);
105  mamaDateTimePrecision
106  getPrecision ();
107  void setPrecision (mamaDateTimePrecision precision);
108  mamaDateTimeHints
109  getHints ();
110  void setHints (mamaDateTimeHints hints);
111  void setFromString (const char* str,
112  const MamaTimeZone* tz = NULL);
113  void setFromString (const char* str,
114  mama_size_t strLen,
115  const MamaTimeZone* tz = NULL);
116  void setToNow ();
117  void setToMidnightToday (const MamaTimeZone* tz = NULL);
118 
123  void setFromStructTimeSpec (struct timespec& inputTimeSpec);
124 
129  void set (struct timeval inputTimeVal);
130 
146  void set (
147  mama_u32_t year,
148  mama_u32_t month,
149  mama_u32_t day,
150  mama_u32_t hour,
151  mama_u32_t minute,
152  mama_u32_t second,
153  mama_u32_t microsecond,
154  mamaDateTimePrecision precision = MAMA_DATE_TIME_PREC_UNKNOWN,
155  const MamaTimeZone* tz = NULL);
156 
168  void setTime (
169  mama_u32_t hour,
170  mama_u32_t minute,
171  mama_u32_t second,
172  mama_u32_t microsecond,
173  mamaDateTimePrecision precision = MAMA_DATE_TIME_PREC_UNKNOWN,
174  const MamaTimeZone* tz = NULL);
175 
185  void setDate (
186  mama_u32_t year,
187  mama_u32_t month,
188  mama_u32_t day);
189 
196  void copyTime (
197  const MamaDateTime& copy);
198 
205  void copyDate (
206  const MamaDateTime& copy);
207 
211  void clear ();
212 
217  void clearTime ();
218 
223  void clearDate ();
224 
225  void addSeconds (mama_f64_t seconds);
226  void addSeconds (mama_i32_t seconds);
227  void addMicroseconds (mama_i64_t microSeconds);
228 
234  mama_u64_t getEpochTimeMicroseconds () const;
235 
243  mama_u64_t getEpochTimeMicroseconds (const MamaTimeZone& tz) const;
244 
245  mama_u64_t getEpochTimeMilliseconds () const;
246  mama_u64_t getEpochTimeMilliseconds (const MamaTimeZone& tz) const;
247 
248  mama_f64_t getEpochTimeSeconds () const;
249  mama_f64_t getEpochTimeSeconds (const MamaTimeZone& tz) const;
250 
257  mama_i64_t getEpochTimeExtSeconds() const;
258 
265  uint32_t getEpochTimeExtNanoseconds() const;
266 
275  void setEpochTimeExt(mama_i64_t seconds, uint32_t nanoseconds) const;
276 
284  mama_f64_t getEpochTimeSecondsWithCheck() const;
285 
286  void getAsString (char* result,
287  mama_size_t maxLen) const;
288  void getTimeAsString (char* result,
289  mama_size_t maxLen) const;
290  void getDateAsString (char* result,
291  mama_size_t maxLen) const;
292 
301  const char* getAsString () const;
302  const char* getTimeAsString () const;
303  const char* getDateAsString () const;
304 
305  void getAsFormattedString (char* result,
306  mama_size_t maxLen,
307  const char* format) const;
308  void getAsFormattedString (char* result,
309  mama_size_t maxLen,
310  const char* format,
311  const MamaTimeZone& tz) const;
312 
313  void getAsStructTimeVal (struct timeval& result) const;
314  void getAsStructTimeVal (struct timeval& result,
315  const MamaTimeZone& tz) const;
316 
317  void getAsStructTimeSpec(struct timespec& result) const;
318 
319  void getAsStructTm (struct tm& result) const;
320  void getAsStructTm (struct tm& result,
321  const MamaTimeZone& tz) const;
322 
323  mama_u32_t getYear () const;
324  mama_u32_t getMonth () const;
325  mama_u32_t getDay () const;
326  mama_u32_t getHour () const;
327  mama_u32_t getMinute () const;
328  mama_u32_t getSecond () const;
329  mama_u32_t getMicrosecond () const;
330  mamaDayOfWeek getDayOfWeek () const;
331 
335  bool hasTime() const;
336 
340  bool hasDate() const;
341 
342  mamaDateTime getCValue();
343  const mamaDateTime getCValue() const;
344 
345 private:
346  mamaDateTime mDateTime;
347  mutable char* mStrRep;
348 };
349 
350 } // namespace Wombat
351 
352 
353 mama_f64_t diffSeconds (const Wombat::MamaDateTime& t1,
354  const Wombat::MamaDateTime& t0);
355 
356 mama_f64_t diffSecondsSameDay (const Wombat::MamaDateTime& t1,
357  const Wombat::MamaDateTime& t0);
358 
359 mama_i64_t diffMicroseconds (const Wombat::MamaDateTime& t1,
360  const Wombat::MamaDateTime& t0);
361 
362 #endif // MamaDateTimeHpp__
mama_f64_t diffSecondsSameDay(const Wombat::MamaDateTime &t1, const Wombat::MamaDateTime &t0)
mama_f64_t diffSeconds(const Wombat::MamaDateTime &t1, const Wombat::MamaDateTime &t0)
Definition: MamaConnection.h:29
A date/time representation with additional hints for precision, advanced output formatting and suppor...
Definition: MamaDateTime.h:67
A time zone representation to make conversion of timestamps to and from particular time zones more co...
Definition: MamaTimeZone.h:50
mama_i64_t diffMicroseconds(const Wombat::MamaDateTime &t1, const Wombat::MamaDateTime &t0)