35 #ifndef _Wolframe_TYPES_DATETIME_HPP_INCLUDED
36 #define _Wolframe_TYPES_DATETIME_HPP_INCLUDED
41 #include <boost/cstdint.hpp>
91 check( YY, MM, DD, hh, mm, ss, ll, cc);
112 check( YY, MM, DD, hh, mm, ss, ll, 0);
130 check( YY, MM, DD, hh, mm, ss, 0, 0);
142 check( YY, MM, DD, 0, 0, 0, 0, 0);
212 void init(
const std::string& str);
223 void init(
const char* str, std::size_t strsize);
278 if (aa == bb)
return 0;
279 if (aa < bb)
return -1;
287 static void setBits(
Timestamp& dest,
unsigned int val,
unsigned int bitidx,
unsigned int bitrange)
289 dest |= ((
Timestamp) val << (63-bitidx-bitrange));
295 static unsigned int getBits(
const Timestamp& from,
unsigned int bitidx,
unsigned int bitrange)
297 return (
unsigned int)(from >> (63-bitidx-bitrange)) & ((1<<bitrange)-1);
305 return std::atoi( std::string( from + idx, range).c_str());
312 static void check_range(
unsigned int val,
unsigned int from,
unsigned int to)
314 if (val < from || val > to)
316 throw std::runtime_error(
"value out of range");
327 throw std::runtime_error(
"value out of range");
339 static void check(
unsigned short YY,
unsigned short MM,
unsigned short DD,
unsigned short hh,
unsigned short mm,
unsigned short ss,
unsigned short ll,
unsigned short cc);
345 static void appendValue( std::string& dest,
unsigned int value,
unsigned int nofDigits);
boost::uint64_t Timestamp
Timestamp equivalent to a date time value for variant type.
Definition: datetime.hpp:47
date with time down to milliseconds (1/1'000 seconds)
Definition: datetime.hpp:64
unsigned int hour() const
Get the hour of the datetime.
Definition: datetime.hpp:156
unsigned int millisecond() const
Get the milliseconds part of the datetime.
Definition: datetime.hpp:165
static unsigned int getBits(const Timestamp &from, unsigned int bitidx, unsigned int bitrange)
Get the bits [bitidx..bitidx+bitrange-1] of a value.
Definition: datetime.hpp:295
Timestamp timestamp() const
Get the datetime timestamp value of the datetime.
unsigned int day() const
Get the day of the datetime in the month starting with 1.
Definition: datetime.hpp:153
std::string tostring(StringFormat::Id sf=StringFormat::YYYYMMDDhhmmssxxxxxx) const
Get the string value of the datetime.
bool operator>(const DateTime &o) const
Test if this datetime is bigger than argument.
Definition: datetime.hpp:261
DateTime(unsigned short YY, unsigned short MM, unsigned short DD, unsigned short hh, unsigned short mm, unsigned short ss)
Constructor of datetime format YYYYMMDDhhmmss.
Definition: datetime.hpp:122
double toMSDNtimestamp() const
Get the MSDN DATE type from the date.
static void setBits(Timestamp &dest, unsigned int val, unsigned int bitidx, unsigned int bitrange)
Initialize the bits [bitidx..bitidx+bitrange-1] of a value.
Definition: datetime.hpp:287
unsigned int year() const
Get the year AD of the datetime.
Definition: datetime.hpp:147
static unsigned int getSubstringAsInt(const char *from, unsigned int idx, unsigned int range)
Get the characters [idx..idx+bitrange-1] of a value as unsigned int.
Definition: datetime.hpp:303
SubType
Describing the format of the DateTime value.
Definition: datetime.hpp:60
date
Definition: datetime.hpp:62
unsigned short m_microsecond
[49..59] micorseconds part
Definition: datetime.hpp:355
DateTime(const Timestamp &t)
Constructor.
Definition: datetime.hpp:178
unsigned int month() const
Get the month of the datetime in the year starting with 1.
Definition: datetime.hpp:150
DateTime(unsigned short YY, unsigned short MM, unsigned short DD, unsigned short hh, unsigned short mm, unsigned short ss, unsigned short ll, unsigned short cc)
Constructor of datetime format YYYYMMDDhhmmss_lllccc.
Definition: datetime.hpp:81
bool operator<(const DateTime &o) const
Test if this datetime is smaller than argument.
Definition: datetime.hpp:267
Data type for normalized date time (absolute time without time zone info)
Definition: datetime.hpp:55
static int compareValue(unsigned int aa, unsigned int bb)
Compare two integer values.
Definition: datetime.hpp:276
SubType m_subtype
[59..60] subtype (format) of the datetime
Definition: datetime.hpp:356
bool operator!=(const DateTime &o) const
Test argument datetime for inequality.
Definition: datetime.hpp:255
Forward declaration.
Definition: variant.hpp:65
unsigned int microsecond() const
Get the microseconds part of the datetime.
Definition: datetime.hpp:168
static DateTime fromMSDNtimestamp(double tm)
Get the date and time from an MSDN DATE type as YYYYMMDDhhmmss.
static void appendValue(std::string &dest, unsigned int value, unsigned int nofDigits)
Append value formatted (filling zero's)
void init(Timestamp timestamp_)
Initialize the datetime with its timestamp value.
DateTime(const DateTime &o)
Copy constructor.
Definition: datetime.hpp:68
DateTime(unsigned short YY, unsigned short MM, unsigned short DD)
Constructor of datetime format YYYYMMDD.
Definition: datetime.hpp:137
DateTime(const char *str, std::size_t strsize)
Constructor.
Definition: datetime.hpp:192
unsigned char m_month
[13..16] 2 digits month in year starting with 1
Definition: datetime.hpp:349
DateTime(const std::string &s)
Constructor.
Definition: datetime.hpp:184
static void check_range(unsigned int val, unsigned int maximum)
Check the value to be within the range of [0,to].
Definition: datetime.hpp:323
bool operator>=(const DateTime &o) const
Test if this datetime is bigger or equal than argument.
Definition: datetime.hpp:258
unsigned short m_millisecond
[39..49] milliseconds part
Definition: datetime.hpp:354
unsigned char m_minute
[27..32] minutes part
Definition: datetime.hpp:352
DateTime(unsigned short YY, unsigned short MM, unsigned short DD, unsigned short hh, unsigned short mm, unsigned short ss, unsigned short ll)
Constructor of datetime format YYYYMMDDhhmmss_lll.
Definition: datetime.hpp:103
date with time down to microseconds (1/1'000'000 seconds)
Definition: datetime.hpp:65
unsigned char m_day
[17..21] 2 digits day in month starting with 1
Definition: datetime.hpp:350
date with time down to seconds
Definition: datetime.hpp:63
bool operator<=(const DateTime &o) const
Test if this datetime is smaller or equal than argument.
Definition: datetime.hpp:264
unsigned int usecond() const
Get the format (subtype) of the datetime.
Definition: datetime.hpp:171
unsigned char m_hour
[22..26] hour of day [0..23]
Definition: datetime.hpp:351
unsigned char m_second
[33..39] seconds part
Definition: datetime.hpp:353
bool operator==(const DateTime &o) const
Test argument datetime for equality.
Definition: datetime.hpp:252
static void check_range(unsigned int val, unsigned int from, unsigned int to)
Check the value to be within the range of [from,to].
Definition: datetime.hpp:312
unsigned int second() const
Get the seconds part of the datetime.
Definition: datetime.hpp:162
unsigned int minute() const
Get the minutes part of the datetime.
Definition: datetime.hpp:159
static void check(unsigned short YY, unsigned short MM, unsigned short DD, unsigned short hh, unsigned short mm, unsigned short ss, unsigned short ll, unsigned short cc)
Verify the date element without calendar validity checks.
int compare(const DateTime &o) const
Compare with argument datetime.
SubType subtype() const
Get the format (subtype) of the datetime.
Definition: datetime.hpp:174
unsigned short m_year
[ 0..12] 4 digits year AD
Definition: datetime.hpp:348