OpenMAMA
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  void setPrecision (mamaDateTimePrecision precision);
106  void setFromString (const char* str,
107  const MamaTimeZone* tz = NULL);
108  void setFromString (const char* str,
109  mama_size_t strLen,
110  const MamaTimeZone* tz = NULL);
111  void setToNow ();
112  void setToMidnightToday (const MamaTimeZone* tz = NULL);
113 
129  void set (
130  mama_u32_t year,
131  mama_u32_t month,
132  mama_u32_t day,
133  mama_u32_t hour,
134  mama_u32_t minute,
135  mama_u32_t second,
136  mama_u32_t microsecond,
137  mamaDateTimePrecision precision = MAMA_DATE_TIME_PREC_UNKNOWN,
138  const MamaTimeZone* tz = NULL);
139 
151  void setTime (
152  mama_u32_t hour,
153  mama_u32_t minute,
154  mama_u32_t second,
155  mama_u32_t microsecond,
156  mamaDateTimePrecision precision = MAMA_DATE_TIME_PREC_UNKNOWN,
157  const MamaTimeZone* tz = NULL);
158 
168  void setDate (
169  mama_u32_t year,
170  mama_u32_t month,
171  mama_u32_t day);
172 
179  void copyTime (
180  const MamaDateTime& copy);
181 
188  void copyDate (
189  const MamaDateTime& copy);
190 
194  void clear ();
195 
200  void clearTime ();
201 
206  void clearDate ();
207 
208  void addSeconds (mama_f64_t seconds);
209  void addSeconds (mama_i32_t seconds);
210  void addMicroseconds (mama_i64_t microSeconds);
211 
217  mama_u64_t getEpochTimeMicroseconds () const;
218 
226  mama_u64_t getEpochTimeMicroseconds (const MamaTimeZone& tz) const;
227 
228  mama_u64_t getEpochTimeMilliseconds () const;
229  mama_u64_t getEpochTimeMilliseconds (const MamaTimeZone& tz) const;
230 
231  mama_f64_t getEpochTimeSeconds () const;
232  mama_f64_t getEpochTimeSeconds (const MamaTimeZone& tz) const;
233 
241  mama_f64_t getEpochTimeSecondsWithCheck() const;
242 
243  void getAsString (char* result,
244  mama_size_t maxLen) const;
245  void getTimeAsString (char* result,
246  mama_size_t maxLen) const;
247  void getDateAsString (char* result,
248  mama_size_t maxLen) const;
249 
256  const char* getAsString () const;
257  const char* getTimeAsString () const;
258  const char* getDateAsString () const;
259 
260  void getAsFormattedString (char* result,
261  mama_size_t maxLen,
262  const char* format) const;
263  void getAsFormattedString (char* result,
264  mama_size_t maxLen,
265  const char* format,
266  const MamaTimeZone& tz) const;
267 
268  void getAsStructTimeVal (struct timeval& result) const;
269  void getAsStructTimeVal (struct timeval& result,
270  const MamaTimeZone& tz) const;
271 
272  void getAsStructTm (struct tm& result) const;
273  void getAsStructTm (struct tm& result,
274  const MamaTimeZone& tz) const;
275 
276  mama_u32_t getYear () const;
277  mama_u32_t getMonth () const;
278  mama_u32_t getDay () const;
279  mama_u32_t getHour () const;
280  mama_u32_t getMinute () const;
281  mama_u32_t getSecond () const;
282  mama_u32_t getMicrosecond () const;
283  mamaDayOfWeek getDayOfWeek () const;
284 
288  bool hasTime() const;
289 
293  bool hasDate() const;
294 
295  mamaDateTime getCValue();
296  const mamaDateTime getCValue() const;
297 
298 private:
299  mama_u64_t mDateTime;
300  mutable char* mStrRep;
301 };
302 
303 } // namespace Wombat
304 
305 
306 mama_f64_t diffSeconds (const Wombat::MamaDateTime& t1,
307  const Wombat::MamaDateTime& t0);
308 
309 mama_f64_t diffSecondsSameDay (const Wombat::MamaDateTime& t1,
310  const Wombat::MamaDateTime& t0);
311 
312 mama_i64_t diffMicroseconds (const Wombat::MamaDateTime& t1,
313  const Wombat::MamaDateTime& t0);
314 
315 #endif // MamaDateTimeHpp__
diffMicroseconds
mama_i64_t diffMicroseconds(const Wombat::MamaDateTime &t1, const Wombat::MamaDateTime &t0)
diffSecondsSameDay
mama_f64_t diffSecondsSameDay(const Wombat::MamaDateTime &t1, const Wombat::MamaDateTime &t0)
MamaTimeZone.h
Wombat
Definition: MamaBasicSubscription.h:27
Wombat::MamaTimeZone
A time zone representation to make conversion of timestamps to and from particular time zones more co...
Definition: MamaTimeZone.h:50
diffSeconds
mama_f64_t diffSeconds(const Wombat::MamaDateTime &t1, const Wombat::MamaDateTime &t0)
Wombat::MamaDateTime
A date/time representation with additional hints for precision, advanced output formatting and suppor...
Definition: MamaDateTime.h:67


© 2012 Linux Foundation