1#ifndef GIMBAL_DATE_TIME_HPP
2#define GIMBAL_DATE_TIME_HPP
8enum class Month: GblEnum {
24enum class WeekDay: GblEnum {
44TimeSpec operator- (
const TimeSpec& lhs,
const TimeSpec& rhs);
45TimeSpec& operator-=(TimeSpec& lhs,
const TimeSpec& rhs);
46TimeSpec operator+ (
const TimeSpec& lhs,
const TimeSpec& rhs);
47Timespec& operator+=(TimeSpec& lhs,
const TimeSpec& rhs);
49struct Date:
public GblDate {
50 static bool isLeapYear(Year year);
51 static Day monthDays(Month month, Year year);
52 static const char* monthStr(Month month);
53 static const char* monthStrShort(Month month);
54 static const char* weekDayStr(WeekDay weekday);
55 static const char* weekDayStrShort(WeekDay weekday);
57 static Date fromJulian(Day julianDate);
58 static Date fromOrdinal(Year year, Day day);
60 void set(Year year, Month month, Day day);
65 WeekDay weekDay()
const;
67 uint8_t yearWeek()
const;
70struct Time:
public GblTime {
71 static const char* amPmStr(
bool isPm);
72 static Second localUtcOffset();
74 void set(Hour hours, Minute mins, Second secs, NanoSecond nsecs);
81 static DateTime fromUnix(std::time_t epoch);
82 static DateTime fromSpecUtc(TimeSpec spec);
83 static DateTime fromLocal(
const std::tm& local);
84 static DateTime fromUtc(
const std::tm& utc);
87 static DateTime parse(
const char* pString,
const char* pFormat);
89 std::time_t toUnix()
const;
90 TimeSpec toSpecUtc()
const;
91 void toLocal(std::tm* pBrokenDown)
const;
92 void toUtc(std::tm* pBrokenDown)
const;
93 std::string toIso8601(
void)
const;
94 std::string format(
const char* pFmt)
const;
99 Month month = Month::January,
107 void setDate(
const Date& other);
108 void setTime(
const Time& other);
110 bool isValid()
const;
112 bool isLocal()
const;
int32_t GblNanoSecond
Represents a nanosecond within a second (0-1000000000.
struct timespec GblTimeSpec
Represents the difference between two GblTime instances.
int32_t GblMinute
Represents a minute in a 60-minute hour (0-59)
int32_t GblDay
Represents a 24-hour day within a month (0-31)
int32_t GblHour
Represents an hour within a 24-hour day (0-23)
int64_t GblSecond
Represents a second in a 60-second minute (0-59)
int32_t GblYear
Represents a calendar year.
@ GBL_WEEK_DAY_TUESDAY
Tuesday.
@ GBL_WEEK_DAY_MONDAY
Monday.
@ GBL_WEEK_DAY_SUNDAY
Sunday.
@ GBL_WEEK_DAY_THURSDAY
Thursday.
@ GBL_WEEK_DAY_SATURDAY
Saturday.
@ GBL_WEEK_DAY_FRIDAY
Friday.
@ GBL_WEEK_DAY_WEDNESDAY
Wednesday.
@ GBL_WEEK_DAY_COUNT
Days/Week.
@ GBL_MONTH_COUNT
Months/Year.
@ GBL_MONTH_OCTOBER
October.
@ GBL_MONTH_DECEMBER
December.
@ GBL_MONTH_FEBRUARY
February.
@ GBL_MONTH_NOVEMBER
November.
@ GBL_MONTH_JANUARY
January.
@ GBL_MONTH_SEPTEMBER
September.
@ GBL_MONTH_AUGUST
August.