lgraph_date_time
Implemnets the DateTime, Date and TimeZone classes.
-
namespace lgraph_api
Functions
-
static inline constexpr int32_t MaxDaysSinceEpochForDate()
Maximum days since epoch for date
-
static inline constexpr int64_t MinSecondsSinceEpochForDateTime()
min and max values that Date can hold
-
static inline constexpr int64_t MaxSecondsSinceEpochForDateTime()
Maximum seconds since epoch for date time
-
class Date
- #include <lgraph_date_time.h>
Implements the Date class. Range of dates is from 0/1/1 to 12/31/9999.
Public Functions
-
explicit Date(const std::chrono::system_clock::time_point &tp)
Construct a new Date object with date set to the specified time. The time point must be in the range of 0/1/1 to 12/31/9999.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
tp – Time point to set the date to.
-
explicit Date(const YearMonthDay &ymd)
Construct a new Date object with date set to the specified date. The date must be in the range of 0/1/1 to 12/31/9999.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
ymd – Date in the form of year, month and day.
-
explicit Date(int32_t days_since_epoch)
Construct a new Date object with date set to an offset from epoch, i.e. the date is set to the specified number of days from epoch. The result date must be in the range of 0/1/1 to 12/31/9999.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
days_since_epoch – Number of days since epoch.
-
explicit Date(const std::string &str)
Parse date from a YYYY-MM-DD string.
- 抛出
InputError – if the string is not in the correct format.
- 参数
str – The string.
-
YearMonthDay GetYearMonthDay() const noexcept
Returns the current Date in the form of year, month and day.
- 返回
The year month day.
-
Date operator+(int days) const
Add a number of days to the Date object.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
days – Number of days to add.
- 返回
The resulting Date object.
-
Date &operator+=(int days)
Add a number of days to the current Date object. In case of overflow, current object is not modified.
- 抛出
OutOfRangeError – Thrown if the resulting date is out of range.
- 参数
days – Number of days to add.
- 返回
Reference to the current date.
-
Date operator-(int days) const
Subtract a number of days from the Date object.
- 抛出
OutOfRangeError – Thrown if the resulting date is out of range.
- 参数
days – Number of days to subtract.
- 返回
The resulting Date object.
-
Date &operator-=(int days)
Subtract a number of days from the current Date object. In case of overflow, current object is not modified.
- 抛出
OutOfRangeError – Thrown if the resulting date is out of range.
- 参数
days – Number of days to subtract.
- 返回
Reference to the current Date object.
-
int32_t DaysSinceEpoch() const noexcept
Returns the number of days this date is since epoch.
-
int32_t GetStorage() const noexcept
Returns the number of days this date is since epoch.
-
explicit operator int32_t() const noexcept
Returns the number of days this date is since epoch.
-
std::chrono::system_clock::time_point TimePoint() const noexcept
Returns the timepoint corresponding to this date at 00:00 am.
-
std::string ToString() const noexcept
Get the string representation of the date in the format of YYYY-MM-DD.
Public Static Functions
-
static bool Parse(const std::string &str, Date &d) noexcept
Parse date from YYYY-MM-DD, save value in d.
- 参数
str – The string.
d – [out] The resulting Date.
- 返回
True if success, otherwise false.
Private Members
-
int32_t days_since_epoch_
The days since epoch
-
struct YearMonthDay
- #include <lgraph_date_time.h>
Structure representing a date in the format of year, month and day.
-
explicit Date(const std::chrono::system_clock::time_point &tp)
-
class DateTime
- #include <lgraph_date_time.h>
Implements a DateTime class that holds DateTime in the range of 0000-01-01 00:00:00 to 9999-12-31 23:59:59.
Public Functions
-
DateTime()
Construct a new DateTime object with date set to the epoch time, i.e., 1970-1-1 00:00:00.
-
explicit DateTime(const std::chrono::system_clock::time_point &tp)
Construct a new DateTime object with date set to the specified timepoint.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
tp – Timepoint to set the DateTime to.
-
explicit DateTime(const YMDHMS &ymdhms)
Construct a new DateTime object with date set to the specified date and time given in YMDHMS.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
-
explicit DateTime(int64_t seconds_since_epoch)
Construct a new DateTime object with date set to specified number of seconds since epoch.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
- 参数
seconds_since_epoch – Number of seconds since epoch.
-
explicit DateTime(const std::string &str)
Construct a new DateTime object with date set to the specified date and time given in the form of YYYY-MM-DD HH:MM:SS.
- 抛出
OutOfRangeError – Thrown if the time point is out of range.
InputError – Thrown if str has invalid format.
- 参数
str – String representation of the date and time in the form of YYYY-MM-DD HH:MM:SS.
-
YMDHMS GetYMDHMS() const noexcept
Get current DateTime in the form of year, month, day, hour, minute, second.
- 返回
The ymdhms.
-
DateTime operator+(int64_t n_seconds) const
Add a number of seconds to the DateTime.
- 抛出
OutOfRangeError – Thrown if the resulting DateTime is out of range.
- 参数
n_seconds – Number of seconds to add.
- 返回
The resulting DateTime.
-
DateTime &operator+=(int64_t n_seconds)
Adds a number of seconds to the current DateTime object. In case of overflow, the current DateTime object is not modified.
- 抛出
OutOfRangeError – Thrown if the resulting DateTime is out of range.
- 参数
n_seconds – Number of seconds to add.
- 返回
A reference to current object.
-
DateTime operator-(int64_t n_seconds) const
Subtract a number of seconds from the DateTime.
- 抛出
OutOfRangeError – Thrown if the resulting DateTime is out of range.
- 参数
n_seconds – Number of seconds to subtract.
- 返回
The resulting DateTime.
-
DateTime &operator-=(int64_t n_seconds)
Subtract a number of seconds from the current DateTime object. In case of overflow, the current DateTime object is not modified.
- 抛出
OutOfRangeError – Thrown if the resulting DateTime is out of range.
- 参数
n_seconds – Number of seconds to subtract.
- 返回
A reference to current object.
-
std::chrono::system_clock::time_point TimePoint() const noexcept
Get the timepoint correponding to this DateTime.
-
std::string ToString() const noexcept
Get string representation of the date and time in the form of YYYY-MM-DD HH:MM:SS.
Public Static Functions
-
static bool Parse(const std::string &str, DateTime &d) noexcept
Parse date from YYYY-MM-DD HH:MM:SS, save valud in d.
- 参数
str – The string.
d – [out] A DateTime to process.
- 返回
True if success, otherwise false.
Private Members
-
int64_t seconds_since_epoch_
-
DateTime()
-
class TimeZone
- #include <lgraph_date_time.h>
A class that represents a time zone.
Public Functions
-
explicit TimeZone(int time_diff_hours = 0)
Create a timezone which has time difference with UTC in hours time_diff_hours.
- 抛出
InvalidParameterError – Thrown if time_diff_hours is invalid.
- 参数
time_diff_hours – (Optional) Difference between local timezone and UTC. Must be > =-10 && <=14. Otherwise the function will throw.
-
DateTime FromUTC(const DateTime &dt) const
Convert a DateTime from UTC time to this time zone.
- 抛出
OutOfRangeError – Thrown if the resulting value is out of range.
- 参数
dt – DateTime in UTC time.
- 返回
DateTime in local timezone.
-
DateTime ToUTC(const DateTime &dt) const
Convert a DateTime from this timezone to UTC time.
- 抛出
OutOfRangeError – Thrown if the resulting value is out of range.
- 参数
dt – DateTime in local timezone.
- 返回
DateTime in UTC.
Public Static Functions
-
static const TimeZone &LocalTimeZone() noexcept
Get local timezone.
- 返回
A const reference to local timezone.
-
static void UpdateLocalTimeZone() noexcept
Update local timezone, used only when daylight saving time changes. Daylight saving time may change after LocalTZ was initialized, in which case we need to update it. This function will update all references returned by LocalTimeZone().
Private Members
-
int time_diff_seconds_
-
explicit TimeZone(int time_diff_hours = 0)
-
static inline constexpr int32_t MaxDaysSinceEpochForDate()