40 PT_API std::string dateTimeToString(
const DateTime& dt);
43 PT_API DateTime dateTimeFromString(
const std::string& s);
70 unsigned h = 0,
unsigned min = 0,
71 unsigned s = 0,
unsigned ms = 0)
73 , _time(h, min, s, ms)
79 : _date( dateTime.
date() )
80 , _time( dateTime.
time() )
90 unsigned hour = 0,
unsigned min = 0,
unsigned sec = 0,
unsigned msec = 0);
95 unsigned&
hour,
unsigned& min,
unsigned& sec,
unsigned&
msec)
const;
110 { _date = dt;
return *
this; }
125 { _time = t;
return *
this; }
165 {
return dateTimeToString(*
this); }
170 {
return dateTimeFromString(s); }
178 Pt::int64_t overrun = totalMSecs % Time::MSecsPerDay;
180 if( (-overrun) > _time.
toMSecs() )
184 else if( overrun + _time.
toMSecs() > Time::MSecsPerDay)
189 _date +=
static_cast<int>(days);
200 Pt::int64_t overrun = totalMSecs % Time::MSecsPerDay;
202 if( overrun > _time.
toMSecs() )
206 else if(_time.
toMSecs() - overrun > Time::MSecsPerDay)
211 _date -=
static_cast<int>(days);
212 _time -=
Timespan( overrun * 1000 );
236 PT_API
void operator >>=(
const SerializationInfo& si, DateTime& dt);
242 PT_API
void operator <<=(SerializationInfo& si,
const DateTime& dt);
267 Pt::int64_t result = (dayDiff * Time::MSecsPerDay + milliSecDiff) * 1000;
348 _date = dateTime.
date();
349 _time = dateTime.
time();
355 unsigned h,
unsigned min,
unsigned s,
unsigned ms)
357 _date.
set(y, mon, d);
358 _time.
set(h, min, s, ms);
363 unsigned& h,
unsigned& min,
unsigned& s,
unsigned& ms)
const
365 _date.
get(y, mon, d);
366 _time.
get(h, min, s, ms);
371 unsigned hour,
unsigned minute,
unsigned second,
unsigned msec)
378 #endif // PT_DATETIME_H
DateTime(const DateTime &dateTime)
Copy Constructor.
Definition: DateTime.h:78
Represents time spans in microsecond resolution.
Definition: Timespan.h:62
DateTime()
Default Constructor.
Definition: DateTime.h:64
uint32_t toMSecs() const
Converts to milliseconds.
Definition: Time.h:173
Date expressed in year, month, and day.
Definition: Date.h:102
Timespan operator-(const DateTime &first, const DateTime &second)
Subtract two DateTimes.
Definition: DateTime.h:259
void get(int &year, unsigned &month, unsigned &day) const
Gets the year, month and day.
Definition: Date.h:448
unsigned month() const
Returns the month-part of the date.
Definition: Date.h:471
int year() const
Returns the year-part of the date.
Definition: DateTime.h:139
DateTime & setDate(const Date &dt)
Sets the date.
Definition: DateTime.h:109
static bool isValid(int y, int m, int d)
Returns true if values describe a valid date.
Definition: Date.h:529
unsigned julian() const
Returns the Date as a julian day.
Definition: Date.h:235
void set(int y, unsigned m, unsigned d)
Sets the date to a year, month and day.
Definition: Date.h:243
Combined Date and Time value.
Definition: DateTime.h:59
unsigned hour() const
Returns the hour-part.
Definition: Time.h:145
unsigned hour() const
Returns the hour-part of the Time.
Definition: DateTime.h:144
static bool isValid(unsigned h, unsigned m, unsigned s, unsigned ms)
Returns true if values are a valid time.
Definition: Time.h:298
const Time & time() const
Gets the time.
Definition: DateTime.h:114
unsigned msec() const
Returns the millisecond-part.
Definition: Time.h:166
int_type int64_t
Signed 64-bit integer type.
Definition: Types.h:48
DateTime & setTime(const Time &t)
Sets the time.
Definition: DateTime.h:124
unsigned month() const
Returns the month-part of the date.
Definition: DateTime.h:134
const Date & date() const
Gets the date.
Definition: DateTime.h:99
std::string toIsoString() const
Returns the date and time in ISO-format.
Definition: DateTime.h:164
void set(int year, unsigned month, unsigned day, unsigned hour=0, unsigned min=0, unsigned sec=0, unsigned msec=0)
Sets the date and time.
Definition: DateTime.h:354
unsigned day() const
Returns the day-part of the date.
Definition: Date.h:463
static bool isValid(int year, unsigned month, unsigned day, unsigned hour, unsigned minute, unsigned second, unsigned msec)
Returns true if values are a valid date and time.
Definition: DateTime.h:370
void get(unsigned &h, unsigned &m, unsigned &s, unsigned &ms) const
Get the time values.
Definition: Time.h:206
DateTime operator-(const DateTime &dt, const Timespan &ts)
Subtract a timespan.
Definition: DateTime.h:276
bool operator!=(const DateTime &a, const DateTime &b)
Returns true if not equal.
Definition: DateTime.h:340
unsigned minute() const
Returns the minute-part.
Definition: Time.h:152
static DateTime fromIsoString(const std::string &s)
Interprets a string as a date and time in ISO-format.
Definition: DateTime.h:169
void set(unsigned h, unsigned m, unsigned s, unsigned ms=0)
Sets the time.
Definition: Time.h:192
bool operator==(const DateTime &a, const DateTime &b)
Returns true if equal.
Definition: DateTime.h:331
unsigned msec() const
Returns the millisecond-part of the Time.
Definition: DateTime.h:159
void get(int &year, unsigned &month, unsigned &day, unsigned &hour, unsigned &min, unsigned &sec, unsigned &msec) const
Gets the date and time.
Definition: DateTime.h:362
int year() const
Returns the year-part of the date.
Definition: Date.h:479
unsigned second() const
Returns the second-part.
Definition: Time.h:159
DateTime & operator-=(const Timespan &ts)
Assignment by difference operator.
Definition: DateTime.h:196
Date & date()
Gets the date.
Definition: DateTime.h:104
Pt::int64_t toMSecs() const
Returns the total number of milliseconds.
Definition: Timespan.h:291
DateTime & operator+=(const Timespan &ts)
Assignment by sum operator.
Definition: DateTime.h:174
DateTime operator+(const DateTime &dt, const Timespan &ts)
Add a timespan.
Definition: DateTime.h:248
Time & time()
Gets the time.
Definition: DateTime.h:119
DateTime(int y, unsigned mon, unsigned d, unsigned h=0, unsigned min=0, unsigned s=0, unsigned ms=0)
Construct to date and time.
Definition: DateTime.h:69
unsigned second() const
Returns the second-part of the Time.
Definition: DateTime.h:154
unsigned day() const
Returns the day-part of the date.
Definition: DateTime.h:129
unsigned minute() const
Returns the minute-part of the Time.
Definition: DateTime.h:149
Time expressed in hours, minutes, seconds and milliseconds.
Definition: Time.h:97
DateTime & operator=(const DateTime &dateTime)
Assignment operator.
Definition: DateTime.h:346