PDateTime.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015-2018 Digital Barriers plc. All rights reserved.
3  * Contact: http://www.digitalbarriers.com/
4  *
5  * This file is part of the Papillon SDK.
6  *
7  * You can't use, modify or distribute any part of this file without
8  * the explicit written agreements of Digital Barriers.
9  */
10 
15 #pragma once
16 #include <PObject.h>
17 #include <PString.h>
18 
19 PAPILLON_BEGIN_NAMESPACE
20 
21 class PDate;
22 class PTime;
23 
38 class PAPILLON_API_CORE PDateTime : public PObject
39 {
40 public:
45  {
47  E_UTC
48  };
49 
53  static const PDateTime& Bad() { static const PDateTime BAD; return BAD; }
54 
60  PDateTime();
61 
69  explicit PDateTime(const PDate& date, const PTime& time, EDateTimeZone timeZone = PDateTime::E_UTC);
70 
74  PDateTime(const PDateTime& other);
75 
86  explicit PDateTime(const PString& ISOdateTime);
87 
91  virtual ~PDateTime();
92 
96  PDateTime& operator=(const PDateTime& other);
97 
101  PDateTime ToLocalTime() const;
102 
106  PDateTime ToUTC() const;
107 
112  static PDateTime Current();
113 
117  static PDateTime CurrentUTC();
118 
122  PDate GetDate() const;
123 
127  PTime GetTime() const;
128 
135  papillon::int32 GetOffsetFromUTCInSeconds() const;
136 
140  bool IsValid() const;
141 
148  PDateTime AddMillisecond(papillon::int64 n) const;
149 
156  papillon::int64 GetMillisecondsTo(const PDateTime& d) const;
157 
162  static PDateTime FromMillisecondsSinceEpoch(papillon::int64 n);
163 
168  static PDateTime FromMicrosecondsSinceEpoch(papillon::int64 n);
169 
174  papillon::int64 ToMillisecondsSinceEpoch() const;
175 
181  papillon::int32 Compare(const PDateTime& other) const;
182 
186  bool operator!=(const PDateTime& d) const;
187 
191  bool operator<(const PDateTime& d) const;
192 
196  bool operator<=(const PDateTime& d) const;
197 
201  bool operator==(const PDateTime& d) const;
202 
206  bool operator>(const PDateTime& d) const;
207 
211  bool operator>=(const PDateTime& d) const;
212 
253  PString ToString(const PString& format = PString("yyyy-MM-dd hh:mm:ss,zzzt")) const;
254 
261  PString ToStringISO() const;
262 
269  PString ToStringISOWithMs() const;
270 
271 };
272 
273 PAPILLON_END_NAMESPACE
EDateTimeZone
Constants to specify if a datetime uses a local time zone or UTC.
Definition: PDateTime.h:44
The PString class provides an Unicode character strings.
Definition: PString.h:38
The PDateTime class provides date and time functions, including time-zone management and UTC conversi...
Definition: PDateTime.h:38
The PDate class provides a calendar date (year, month, and day numbers) in the Gregorian calendar; PD...
Definition: PDate.h:27
The PTime class provides clock time functions; PTime instances are immutable (thread-safe).
Definition: PTime.h:32
Coordinated Universal Time.
Definition: PDateTime.h:47
The PObject class is the root class of all Papillon classes; all PObject behaves like shared referenc...
Definition: PObject.h:27
Class PString: an unicode character strings (use copy-on-write idiom).
PString ToString() const
Returns a string representation of this object.
static const PDateTime & Bad()
Returns the constant holding the bad instance of a PDateTime.
Definition: PDateTime.h:53
Class PObject: the root class of all Papillon classes.
PObject & operator=(const PObject &obj)
Performs a shared copy of other to this object.
Definition: PObject.h:45
Locale dependent time.
Definition: PDateTime.h:46