2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#ifndef GIMBAL_DATE_TIME_H
17#define GIMBAL_DATE_TIME_H
19#include "../gimbal_core.h"
20#include "../platform/gimbal_time_.h"
22#define GBL_DATE_TIME_TYPE (GBL_TYPEID(GblDateTime))
23#define GBL_DATE_TIME_CLASS(klass) (GBL_CLASS_CAST(GblDateTime, klass))
26
27
28
29#define GBL_TIME_MSECS_PER_SEC 1000
30#define GBL_TIME_USECS_PER_SEC 1000000
31#define GBL_TIME_NSECS_PER_SEC 1000000000
35
36
37
38#define GBL_DATE_GREGORIAN_YEAR_FIRST 1582
39#define GBL_DATE_UNIX_EPOCH_YEAR 1970
40#define GBL_DATE_UNIX_EPOCH_MONTH GBL_MONTH_JANUARY
41#define GBL_DATE_UNIX_EPOCH_DAY 1
45
46
47
48#define GBL_DATE_TIME_BROKEN_DOWN_YEAR_FIRST 1900
49#define GBL_DATE_TIME_BROKEN_DOWN_YEAR_MIN 1970
50#define GBL_DATE_TIME_BROKEN_DOWN_MONTH_OFFSET -1
54
55
56
57#define GBL_DATE_TIME_FORMAT_BUFFER_SIZE_INCREMENT 128
58#define GBL_DATE_TIME_FORMAT_BUFFER_SIZE_MULTIPLIER_MAX 10
61#define GBL_DATE_TIME_ISO8601_STRING_SIZE 29
105
106
107
113
114
122
123
132
133
141
142
143
160
161
162
163
191
192
193
204
205
206
207
221
222
223
224
234
235
236
237
254
255
256
257
281
282
283
284
300 GblStringBuffer* pBuffer,
305
306
307
308
330
331
332
333
381#define GblTime_set_5(self, hour, min, sec, ns)
382 (GblTime_set
)(self, hour, min, sec, ns)
383#define GblTime_set_4(self, hour, min, sec)
384 (GblTime_set_5
(self, hour, min, sec, 0
))
385#define GblTime_set(...)
388#define GblDateTime_create_1(year)
389 (GblDateTime_create_2
(year, GBL_MONTH_JANUARY))
390#define GblDateTime_create_2(year, month)
391 (GblDateTime_create_3
(year, month, 1
))
392#define GblDateTime_create_3(year, month, day)
393 (GblDateTime_create_4
(year, month, day, 0
))
394#define GblDateTime_create_4(year, month, day, hour)
395 (GblDateTime_create_5
(year, month, day, hour, 0
))
396#define GblDateTime_create_5(year, month, day, hour, min)
397 (GblDateTime_create_6
(year, month, day, hour, min, 0
))
398#define GblDateTime_create_6(year, month, day, hour, min, sec)
399 (GblDateTime_create_7
(year, month, day, hour, min, sec, 0
))
400#define GblDateTime_create_7(year, month, day, hour, min, sec, ns)
401 (GblDateTime_create_8
(year, month, day, hour, min, sec, ns, 0
))
402#define GblDateTime_create_8(year, month, day, hour, min, sec, ns, tz)
403 ((GblDateTime_create
)(year, month, day, hour, min, sec, ns, tz))
404#define GblDateTime_create(...)
407#define GblDateTime_set_2(self, year)
408 (GblDateTime_set_3
(self, year, GBL_MONTH_JANUARY))
409#define GblDateTime_set_3(self, year, month)
410 (GblDatetime_set_4(self, year, month, 1
))
411#define GblDateTime_set_4(self, year, month, day)
412 (GblDateTime_set_5
(self, year, month, day, 0
))
413#define GblDateTime_set_5(self, year, month, day, hour)
414 (GblDateTime_set_6
(self, year, month, day, hour, 0
))
415#define GblDateTime_set_6(self, year, month, day, hour, min)
416 (GblDateTime_set_7
(self, year, month, day, hour, min, 0
))
417#define GblDateTime_set_7(self, year, month, day, hour, min, sec)
418 (GblDateTime_set_8
(self, year, month, day, hour, min, sec, 0
))
419#define GblDateTime_set_8(self, year, month, day, hour, min, sec, ns)
420 (GblDateTime_set_9
(self, year, month, day, hour, min, sec, ns, 0
))
421#define GblDateTime_set_9(self, year, month, day, hour, min, sec, ns, tz)
422 ((GblDateTime_set
)(self, year, month, day, hour, min, sec, ns, tz))
423#define GblDateTime_set(...)
#define GBL_CLASS_CAST(cType, klass)
int32_t GblNanoSecond
Represents a nanosecond within a second (0-1000000000.
struct timespec GblTimeSpec
Represents the difference between two GblTime instances.
GblDay GblDate_monthDays(GblMonth month, GblYear year)
Returns the number of days in the given month of the given year.
int32_t GblMinute
Represents a minute in a 60-minute hour (0-59)
const char * GblDate_monthStrShort(GblMonth month)
Returns the short-handed string name of the given month.
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)
const char * GblDate_monthStr(GblMonth month)
Returns the string name of the given month.
const char * GblDate_weekDayStrShort(GblWeekDay weekDay)
Returns the short-handed string name of the given weekday.
int64_t GblSecond
Represents a second in a 60-second minute (0-59)
int32_t GblYear
Represents a calendar year.
const char * GblDate_weekDayStr(GblWeekDay weekDay)
Returns the string name of the given weekday.
@ 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.
GblBool GblDate_isLeapYear(GblYear year)
Returns GBL_TRUE if the given year was a leap year, otherwise returns GBL_FALSE.
@ 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.
#define GBL_TYPEID(instanceStruct)
#define GBL_DECLARE_ENUM(E)
#define GBL_DECLARE_TYPE(instanceStruct)
#define GBL_CLASS_DERIVE_EMPTY(...)
#define GBL_VA_OVERLOAD_CALL_ARGC(BASE,...)
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
Represents a calendar date.
GblWeekDay GblDate_weekDay(const GblDate *pSelf)
Returns the day of the week for the given date.
void GblDate_set(GblDate *pSelf, GblYear year, GblMonth month, GblDay day)
Sets the given date structure, given its year, month, and day.
GblDay GblDate_yearDay(const GblDate *pSelf)
Returns the day-of-the-year (1-365) for the given date.
GblSecond GblTime_localUtcOffset(void)
Returns the number of seconds the local time is offset from UTC time.
GblDay GblDate_toJulian(const GblDate *pSelf)
Returns the Julian Day from the given date.
GblMonth month
Month of the year (1-12)
GblDate * GblDate_fromOrdinal(GblDate *pSelf, GblYear year, GblDay day)
Converts the given ordinal date to a GblDate, storing it in pSelf and returning it.
GblDay day
Day of the month (1-31)
GblDate * GblDate_fromJulian(GblDate *pSelf, GblDay julianDate)
Converts the given julian date to a GblDate, storing it in pSelf and returning it.
const char * GblTime_amPmStr(GblBool isPm)
Returns the string "PM" if isPm is GBL_TRUE, otherwise returns "AM".
uint8_t GblDate_yearWeek(const GblDate *pSelf)
Returns the week-of-the-year (1-52) for the given date.
GblBool GblDate_isDst(const GblDate *pSelf)
Returns GBL_TRUE if the given date is during daylight savings time.
GblTimeSpec GblTime_specDiff(const GblTimeSpec *pSrc1, const GblTimeSpec *pSrc2)
Returns the difference between two NS-resolution GblTimeSpec values.
GblBool GblDate_isValid(const GblDate *pSelf)
Returns GBL_TRUE if the given structure represents a valid GblDate.
Represents a combined calendar date with time-of-day.
const char * GblDateTime_format(const GblDateTime *pSelf, GblStringBuffer *pBuffer, const char *pFmt)
Fills in the given buffer with the strftime()-formatted GblDateTime, returning its C string.
GBL_RESULT GblDateTime_toUtc(const GblDateTime *pSelf, struct tm *pTm)
Converts the given GblDateTime to a broken-down UTC time.
GblTimeSpec GblDateTime_toSpecUtc(const GblDateTime *pSelf)
Converts the given GblDateTime to a timespec UTC time.
GblDateTime * GblDateTime_addHours(GblDateTime *pSelf, GblHour hours)
Adds the given number of hours to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_addMilliSecs(GblDateTime *pSelf, int mSecs)
Adds the given number of milliseconds to the given GblDateTime, returning a pointer to it.
time_t GblDateTime_toUnix(const GblDateTime *pSelf)
Converts the given GblDateTime to a unix epoch time.
GblBool GblDateTime_equals(const GblDateTime *pSelf, const GblDateTime *pRhs)
Returns GBL_TRUE if the two provided GblDateTimes have the same value.
GblDateTime * GblDateTime_addMonths(GblDateTime *pSelf, int months)
Adds the given number of months to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_fromLocal(GblDateTime *pSelf, const struct tm *pLocal)
Sets the given date/time from a local broken-down time, returning a pointer to it.
GblBool GblDateTime_isUtc(const GblDateTime *pSelf)
Returns GBL_TRUE if the given date/time represents a date and time within the UTC timezone.
GblDateTime * GblDateTime_fromUtc(GblDateTime *pSelf, const struct tm *pUtc)
Sets the given date/time from a UTC broken-down time, returning a pointer to it.
GblTimeSpec GblDateTime_diff(const GblDateTime *pSelf, const GblDateTime *pRhs)
Returns the NS-resolution GblTimeSpec difference between two GblDateTime values.
GblDateTime * GblDateTime_addMicroSecs(GblDateTime *pSelf, int uSecs)
Adds the given number of microseconds to the given GblDateTime, returning a pointer to it.
GblBool GblDateTime_isLocal(const GblDateTime *pSelf)
Returns GBL_TRUE if the given date/time represents a date and time in the local timezone.
GblDateTime * GblDateTime_nowLocal(GblDateTime *pSelf)
Sets the given date/time to the current local time, returning a pointer to it.
GblDate date
Date structure.
int GblDateTime_compare(const GblDateTime *pSelf, const GblDateTime *pRhs)
Lexacographically compares the two GblDateTimes, returning 0, -1, or 1.
GBL_RESULT GblDateTime_toLocal(const GblDateTime *pSelf, struct tm *pTm)
Converts the given GblDateTime to a broken-down local time.
void GblDateTime_setTime(GblDateTime *pSelf, const GblTime *pTime)
Sets the GblTime value of the given GblDateTime to pTime.
GblDateTime * GblDateTime_normalize(GblDateTime *pSelf)
Ensures all values within the given GblDateTime are within range and returns a pointer to it.
GblDateTime * GblDateTime_addWeeks(GblDateTime *pSelf, int weeks)
Adds the given number of weeks to the given GblDateTime, returning a pointer to it.
GblRefCount GblDateTime_unref(GblDateTime *pDt)
Decrements the refCounter by 1, destroying the struct at 0, and returning the new refCount value.
GblDateTime * GblDateTime_ref(GblDateTime *pDt)
Returns a newly acquired reference to the given GblDateTime structure.
GblDateTime * GblDateTime_fromSpecUtc(GblDateTime *pSelf, const GblTimeSpec *pSpec)
Sets the given date/time from a GblTimeSpec value, returning a pointer to it.
GblDateTime * GblDateTime_addYears(GblDateTime *pSelf, GblYear years)
Adds the given number of years to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_addMinutes(GblDateTime *pSelf, GblMinute minutes)
Adds the given number of minutes to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_parse(GblDateTime *pSelf, const char *pString, const char *pFormat)
Parses the given string using the strptime() formatter, storing and returning pSelf.
int16_t utcOffset
Timezone second offset from UTC.
GblDateTime * GblDateTime_addDays(GblDateTime *pSelf, GblDay days)
Adds the given number of days to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_addNanoSecs(GblDateTime *pSelf, GblNanoSecond nSecs)
Adds the given number of nanoseconds s to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_fromUnix(GblDateTime *pSelf, time_t epoch)
Sets the given date/time structure from a unix epoch time, returning a pointer to it.
GblBool GblDateTime_isValid(const GblDateTime *pSelf)
Returns GBL_TRUE if the given GblDateTime structure contains both a valid date and time.
GblDateTime * GblDateTime_addSeconds(GblDateTime *pSelf, GblSecond seconds)
Adds the given number of seconds to the given GblDateTime, returning a pointer to it.
GblDateTime * GblDateTime_set(GblDateTime *pSelf, GblYear year, GblMonth month, GblDay day, GblHour hours, GblMinute mins, GblSecond secs, GblNanoSecond ns, GblSecond tzOff)
Sets the values of the given GblDateTime, with default argument values provided.
GblDateTime * GblDateTime_add(GblDateTime *pSelf, const GblDateTime *pRhs)
Adds the pRhs GblDateTime to pSelf, returning a pointer to pSelf.
GblDateTime * GblDateTime_nowUtc(GblDateTime *pSelf)
Sets the given date/time to the current UTC time, returning a pointer to it.
void GblDateTime_setDate(GblDateTime *pSelf, const GblDate *pDate)
Sets the GblDate value of the given GblDateTime to pDate.
GblDateTime * GblDateTime_create(GblYear year, GblMonth month, GblDay day, GblHour hours, GblMinute mins, GblSecond secs, GblNanoSecond ns, GblSecond tzOff)
Creates and allocates a new shared reference to a GblDateTime.
GblTime time
Time structure.
const char * GblDateTime_toIso8601(const GblDateTime *pSelf, GblStringBuffer *pBuff)
Fills in the given buffer with the ISO8601 representation of the given date/time, return its C string...
Represents a time-of-day.
GblHour hours
Hour within a day (0-23)
GblSecond seconds
Seconds within a minute (0-59)
GblNanoSecond nSeconds
Nanosconds within a second (0-1000000000)
void GblTime_set(GblTime *pSelf, GblHour hours, GblMinute mins, GblSecond secs, GblNanoSecond nsec)
Sets the values of the given GblTime structure, with nsecs defaulting to 0.
GblBool GblTime_isValid(const GblTime *pSelf)
Returns GBL_TRUE if the given time structure represents a valid time.
GblMinute minutes
Minutes within an hour (0-59)
GblBool GblTime_isPm(const GblTime *pSelf)
Returns GBL_TRUE if the given GblTime is PM, false if it's AM.