libGimbal 0.2.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_date_time.h
Go to the documentation of this file.
1/*! \file
2 * \brief Date and time conversions and utilities
3 * \ingroup utils
4 * \todo
5 * - GblDateTime_fromIso8601()
6 * - double GblDateTime_toJulian(): higher res, with seconds
7 * - toIso8601() string corrupting with msec resolution
8 * - GblDateTime_format() support ms, us, ns
9 * - GblDateTime_parse() support ms, us, ns
10 * - are we misnaming GMT as UTC anywhere?
11 * - GstDateTime maintains whether fields have been set or not...
12 *
13 * \author 2023 Falco Girgis
14 * \copyright MIT License
15 */
16#ifndef GIMBAL_DATE_TIME_H
17#define GIMBAL_DATE_TIME_H
18
19#include "../gimbal_core.h"
20
21#define GBL_DATE_TIME_TYPE (GBL_TYPEID(GblDateTime))
22#define GBL_DATE_TIME_CLASS(klass) (GBL_CLASS_CAST(GblDateTime, klass))
23
24/*! \name Second Conversions
25 * \brief Defines for second conversion factors
26 * @{
27 */
28#define GBL_TIME_MSECS_PER_SEC 1000 //!< Number of milliseconds per second
29#define GBL_TIME_USECS_PER_SEC 1000000 //!< Number of microseconds per second
30#define GBL_TIME_NSECS_PER_SEC 1000000000 //!< Number of nanoseconds per second
31//! @}
32
33/*! \name Start Dates
34 * \brief Initial dates of epochs
35 * @{
36 */
37#define GBL_DATE_GREGORIAN_YEAR_FIRST 1582 //!< First year in Gregorian calendar
38#define GBL_DATE_UNIX_EPOCH_YEAR 1970 //!< Year of the Unix epoch
39#define GBL_DATE_UNIX_EPOCH_MONTH GBL_MONTH_JANUARY //!< Month of the Unix epoch
40#define GBL_DATE_UNIX_EPOCH_DAY 1 //!< Day of the unix epoch
41//! @}
42
43/*! \name Broken-down Time
44 * \brief Defines for working with broken-down time
45 * @{
46 */
47#define GBL_DATE_TIME_BROKEN_DOWN_YEAR_FIRST 1900 //!< Year offset of a broken-down time's date
48#define GBL_DATE_TIME_BROKEN_DOWN_YEAR_MIN 1970 //!< The oldest year a broken-down time can handle by spec
49#define GBL_DATE_TIME_BROKEN_DOWN_MONTH_OFFSET -1 //!< Month offset from GblMonth to a broken-down month
50//! @}
51
52/*! \name Formatting
53 * \brief Defines used when formatting and stringifying
54 * @{
55 */
56#define GBL_DATE_TIME_FORMAT_BUFFER_SIZE_INCREMENT 128 //!< Size increment when resizing format buffers
57#define GBL_DATE_TIME_FORMAT_BUFFER_SIZE_MULTIPLIER_MAX 10 //!< Maximum number of size increments for format buffers
58//! @}
59
60#define GBL_DATE_TIME_ISO8601_STRING_SIZE 29 //!< Required buffer size for going to an ISO8601-formatted string
61
63
64//! Represents a month of the 12-month year
66 GBL_MONTH_JANUARY = 1, //!< January
67 GBL_MONTH_FEBRUARY, //!< February
68 GBL_MONTH_MARCH, //!< March
69 GBL_MONTH_APRIL, //!< April
70 GBL_MONTH_MAY, //!< May
71 GBL_MONTH_JUNE, //!< June
72 GBL_MONTH_JULY, //!< July
73 GBL_MONTH_AUGUST, //!< August
74 GBL_MONTH_SEPTEMBER, //!< September
75 GBL_MONTH_OCTOBER, //!< October
76 GBL_MONTH_NOVEMBER, //!< November
77 GBL_MONTH_DECEMBER, //!< December
78 GBL_MONTH_COUNT = 12 //!< Months/Year
79};
80
81//! Represents a day of the 7-day week
92
93typedef int32_t GblYear; //!< Represents a calendar year
94typedef int32_t GblDay; //!< Represents a 24-hour day within a month (0-31)
95typedef int32_t GblNanoSecond; //!< Represents a nanosecond within a second (0-1000000000
96typedef int64_t GblSecond; //!< Represents a second in a 60-second minute (0-59)
97typedef int32_t GblMinute; //!< Represents a minute in a 60-minute hour (0-59)
98typedef int32_t GblHour; //!< Represents an hour within a 24-hour day (0-23)
99
100//! Represents the difference between two GblTime instances
101typedef struct timespec GblTimeSpec;
102
103/*! \name Type System
104 * \brief Type declarations for GblVariant time type
105 * @{
106 */
107GBL_DECLARE_TYPE(GblDateTime);
108GBL_CLASS_DERIVE_EMPTY(GblDateTime, GblOpaque);
109//! @}
110
111/*! Represents a calendar date
112 * \ingroup utils
113 */
114typedef struct GblDate {
115 GblYear year; //!< Year
116 GblMonth month; //!< Month of the year (1-12)
117 GblDay day; //!< Day of the month (1-31)
118} GblDate; // 12 Total bytes
119
120/*! Represents a time-of-day
121 * \ingroup utils
122 */
123typedef struct GblTime {
124 GblHour hours; //!< Hour within a day (0-23)
125 GblMinute minutes; //!< Minutes within an hour (0-59)
126 GblSecond seconds; //!< Seconds within a minute (0-59)
127 GblNanoSecond nSeconds; //!< Nanosconds within a second (0-1000000000)
128} GblTime; // 20 Total bytes
129
130/*! Represents a combined calendar date with time-of-day
131 * \ingroup utils
132 */
133typedef struct GblDateTime {
134 GblDate date; //!< Date structure
135 GblTime time; //!< Time structure
136 int16_t utcOffset; //!< Timezone second offset from UTC
137} GblDateTime; // 34 Total bytes
138
139/*! \name Date Static Methods
140 * \brief Non-member functions for date management
141 * @{
142 */
143//! Returns GBL_TRUE if the given year was a leap year, otherwise returns GBL_FALSE
145//! Returns the number of days in the given \p month of the given \p year
147 GblYear year) GBL_NOEXCEPT;
148//! Returns the string name of the given \p month
150//! Returns the short-handed string name of the given \p month
152//! Returns the string name of the given \p weekday
154//! Returns the short-handed string name of the given \p weekday
156//! @}
157
158/*! \name Date Methods
159 * \brief Member functions for GblDate
160 * \relatesalso GblDate
161 * @{
162 */
163//! Returns GBL_TRUE if the given structure represents a valid GblDate
165//! Returns GBL_TRUE if the given date is during daylight savings time
167//! Returns the Julian Day from the given date
169//! Returns the day of the week for the given date
171//! Returns the day-of-the-year (1-365) for the given date
173//! Returns the week-of-the-year (1-52) for the given date
174GBL_EXPORT uint8_t GblDate_yearWeek (const GblDate* pSelf) GBL_NOEXCEPT;
175//! Converts the given julian date to a GblDate, storing it in \p pSelf and returning it
176GBL_EXPORT GblDate* GblDate_fromJulian (GblDate* pSelf,
177 GblDay julianDate) GBL_NOEXCEPT;
178//! Converts the given ordinal date to a GblDate, storing it in \p pSelf and returning it
179GBL_EXPORT GblDate* GblDate_fromOrdinal (GblDate* pSelf,
180 GblYear year,
181 GblDay day) GBL_NOEXCEPT;
182//! Sets the given date structure, given its \p year, \p month, and \p day
183GBL_EXPORT void GblDate_set (GblDate* pSelf,
184 GblYear year,
185 GblMonth month,
186 GblDay day) GBL_NOEXCEPT;
187//! @}
188
189/*! \name Time Static Methods
190 * \brief Non-member functions for time management
191 * @{
192 */
193//! Returns the string "PM" if \p isPm is GBL_TRUE, otherwise returns "AM"
195//! Returns the number of seconds the local time is offset from UTC time
197//! Returns the difference between two NS-resolution GblTimeSpec values
199 const GblTimeSpec* pSrc2) GBL_NOEXCEPT;
200//! @}
201
202/*! \name Time Methods
203 * \brief Member functions for GblTime
204 * \relatesalso GblTime
205 * @{
206 */
207//! Returns GBL_TRUE if the given time structure represents a valid time
209//! Returns GBL_TRUE if the given GblTime is PM, false if it's AM
211//! Sets the values of the given GblTime structure, with nsecs defaulting to 0
212GBL_EXPORT void GblTime_set (GblTime* pSelf,
213 GblHour hours,
214 GblMinute mins,
215 GblSecond secs,
216 GblNanoSecond nsec/*=0*/) GBL_NOEXCEPT;
217//! @}
218
219/*! \name Read Accessors
220 * \brief Methods for getting values
221 * \relatesalso GblDateTime
222 * @{
223 */
224//! Returns GBL_TRUE if the given GblDateTime structure contains both a valid date and time
226//! Returns GBL_TRUE if the given date/time represents a date and time within the UTC timezone
228//! Returns GBL_TRUE if the given date/time represents a date and time in the local timezone
230//! @}
231
232/*! \name Dynamic Lifetime
233 * \brief Methods for managing shared references
234 * \relatesalso GblDateTime
235 * @{
236 */
237//! Creates and allocates a new shared reference to a GblDateTime
239 GblMonth month/*=1*/,
240 GblDay day /*=1*/,
241 GblHour hours/*=0*/,
242 GblMinute mins /*=0*/,
243 GblSecond secs /*=0*/,
244 GblNanoSecond ns /*=0*/,
245 GblSecond tzOff/*=0*/) GBL_NOEXCEPT;
246//! Returns a newly acquired reference to the given GblDateTime structure
247GBL_EXPORT GblDateTime* GblDateTime_ref (GblDateTime* pDt) GBL_NOEXCEPT;
248//! Decrements the refCounter by 1, destroying the struct at 0, and returning the new refCount value
250//! @}
251
252/*! \name Initialization
253 * \brief Methods for constructing and populating
254 * \relatesalso GblDateTime
255 * @{
256 */
257//! Sets the given date/time structure from a unix epoch time, returning a pointer to it
258GBL_EXPORT GblDateTime* GblDateTime_fromUnix (GblDateTime* pSelf,
259 time_t epoch) GBL_NOEXCEPT;
260//! Sets the given date/time from a GblTimeSpec value, returning a pointer to it
261GBL_EXPORT GblDateTime* GblDateTime_fromSpecUtc (GblDateTime* pSelf,
262 const GblTimeSpec* pSpec) GBL_NOEXCEPT;
263//! Sets the given date/time from a local broken-down time, returning a pointer to it
264GBL_EXPORT GblDateTime* GblDateTime_fromLocal (GblDateTime* pSelf,
265 const struct tm* pLocal) GBL_NOEXCEPT;
266//! Sets the given date/time from a UTC broken-down time, returning a pointer to it
267GBL_EXPORT GblDateTime* GblDateTime_fromUtc (GblDateTime* pSelf,
268 const struct tm* pUtc) GBL_NOEXCEPT;
269//! Sets the given date/time to the current local time, returning a pointer to it
270GBL_EXPORT GblDateTime* GblDateTime_nowLocal (GblDateTime* pSelf) GBL_NOEXCEPT;
271//! Sets the given date/time to the current UTC time, returning a pointer to it
272GBL_EXPORT GblDateTime* GblDateTime_nowUtc (GblDateTime* pSelf) GBL_NOEXCEPT;
273//! Parses the given string using the strptime() formatter, storing and returning \p pSelf
274GBL_EXPORT GblDateTime* GblDateTime_parse (GblDateTime* pSelf,
275 const char* pString,
276 const char* pFormat) GBL_NOEXCEPT;
277//! @}
278
279/*! \name Conversions
280 * \brief Methods for converting to another format
281 * \relatesalso GblDateTime
282 * @{
283 */
284//! Converts the given GblDateTime to a unix epoch time
285GBL_EXPORT time_t GblDateTime_toUnix (const GblDateTime* pSelf) GBL_NOEXCEPT;
286//! Converts the given GblDateTime to a timespec UTC time
288//! Converts the given GblDateTime to a broken-down local time
289GBL_EXPORT GBL_RESULT GblDateTime_toLocal (const GblDateTime* pSelf,
290 struct tm* pTm) GBL_NOEXCEPT;
291//! Converts the given GblDateTime to a broken-down UTC time
292GBL_EXPORT GBL_RESULT GblDateTime_toUtc (const GblDateTime* pSelf,
293 struct tm* pTm) GBL_NOEXCEPT;
294//! Fills in the given buffer with the ISO8601 representation of the given date/time, return its C string
295GBL_EXPORT const char* GblDateTime_toIso8601 (const GblDateTime* pSelf,
296 GblStringBuffer* pBuff) GBL_NOEXCEPT;
297//! Fills in the given buffer with the strftime()-formatted GblDateTime, returning its C string
298GBL_EXPORT const char* GblDateTime_format (const GblDateTime* pSelf,
299 GblStringBuffer* pBuffer,
300 const char* pFmt) GBL_NOEXCEPT;
301//! @}
302
303/*! \name Write Accessors
304 * \brief Methods for writing values
305 * \relatesalso GblDateTime
306 * @{
307 */
308//! Ensures all values within the given GblDateTime are within range and returns a pointer to it
309GBL_EXPORT GblDateTime* GblDateTime_normalize (GblDateTime* pSelf) GBL_NOEXCEPT;
310//! Sets the GblDate value of the given GblDateTime to \p pDate
311GBL_EXPORT void GblDateTime_setDate (GblDateTime* pSelf,
312 const GblDate* pDate) GBL_NOEXCEPT;
313//! Sets the GblTime value of the given GblDateTime to \p pTime
314GBL_EXPORT void GblDateTime_setTime (GblDateTime* pSelf,
315 const GblTime* pTime) GBL_NOEXCEPT;
316//! Sets the values of the given GblDateTime, with default argument values provided
317GBL_EXPORT GblDateTime* GblDateTime_set (GblDateTime* pSelf,
318 GblYear year,
319 GblMonth month/*=1*/,
320 GblDay day /*=1*/,
321 GblHour hours/*=0*/,
322 GblMinute mins /*=0*/,
323 GblSecond secs /*=0*/,
324 GblNanoSecond ns /*=0*/,
325 GblSecond tzOff/*=0*/) GBL_NOEXCEPT;
326//! @}
327
328/*! \name Operators
329 * \brief Methods implementing operations
330 * \relatesalso GblDateTime
331 * @{
332 */
333//! Lexacographically compares the two GblDateTimes, returning 0, -1, or 1
334GBL_EXPORT int GblDateTime_compare (const GblDateTime* pSelf,
335 const GblDateTime* pRhs) GBL_NOEXCEPT;
336//! Returns GBL_TRUE if the two provided GblDateTimes have the same value
337GBL_EXPORT GblBool GblDateTime_equals (const GblDateTime* pSelf,
338 const GblDateTime* pRhs) GBL_NOEXCEPT;
339//! Returns the NS-resolution GblTimeSpec difference between two GblDateTime values
340GBL_EXPORT GblTimeSpec GblDateTime_diff (const GblDateTime* pSelf,
341 const GblDateTime* pRhs) GBL_NOEXCEPT;
342//! Adds the \p pRhs GblDateTime to \p pSelf, returning a pointer to \p pSelf
343GBL_EXPORT GblDateTime* GblDateTime_add (GblDateTime* pSelf,
344 const GblDateTime* pRhs) GBL_NOEXCEPT;
345//! Adds the given number of \p days to the given GblDateTime, returning a pointer to it
346GBL_EXPORT GblDateTime* GblDateTime_addDays (GblDateTime* pSelf,
347 GblDay days) GBL_NOEXCEPT;
348//! Adds the given number of \p hours to the given GblDateTime, returning a pointer to it
349GBL_EXPORT GblDateTime* GblDateTime_addHours (GblDateTime* pSelf,
350 GblHour hours) GBL_NOEXCEPT;
351//! Adds the given number of \p minutes to the given GblDateTime, returning a pointer to it
352GBL_EXPORT GblDateTime* GblDateTime_addMinutes (GblDateTime* pSelf,
353 GblMinute minutes) GBL_NOEXCEPT;
354//! Adds the given number of \p seconds to the given GblDateTime, returning a pointer to it
355GBL_EXPORT GblDateTime* GblDateTime_addSeconds (GblDateTime* pSelf,
356 GblSecond seconds) GBL_NOEXCEPT;
357//! Adds the given number of milliseconds to the given GblDateTime, returning a pointer to it
358GBL_EXPORT GblDateTime* GblDateTime_addMilliSecs (GblDateTime* pSelf,
359 int mSecs) GBL_NOEXCEPT;
360//! Adds the given number of microseconds to the given GblDateTime, returning a pointer to it
361GBL_EXPORT GblDateTime* GblDateTime_addMicroSecs (GblDateTime* pSelf,
362 int uSecs) GBL_NOEXCEPT;
363//! Adds the given number of nanoseconds s to the given GblDateTime, returning a pointer to it
364GBL_EXPORT GblDateTime* GblDateTime_addNanoSecs (GblDateTime* pSelf,
366//! Adds the given number of \p weeks to the given GblDateTime, returning a pointer to it
367GBL_EXPORT GblDateTime* GblDateTime_addWeeks (GblDateTime* pSelf,
368 int weeks) GBL_NOEXCEPT;
369//! Adds the given number of \p months to the given GblDateTime, returning a pointer to it
370GBL_EXPORT GblDateTime* GblDateTime_addMonths (GblDateTime* pSelf,
371 int months) GBL_NOEXCEPT;
372//! Adds the given number of \p years to the given GblDateTime, returning a pointer to it
373GBL_EXPORT GblDateTime* GblDateTime_addYears (GblDateTime* pSelf,
374 GblYear years) GBL_NOEXCEPT;
375//! @}
376
378
379///\cond
380#define GblTime_set_5(self, hour, min, sec, ns)
381 (GblTime_set)(self, hour, min, sec, ns)
382#define GblTime_set_4(self, hour, min, sec)
383 (GblTime_set_5(self, hour, min, sec, 0))
384#define GblTime_set(...)
385 GBL_VA_OVERLOAD_CALL_ARGC(GblTime_set, __VA_ARGS__)
386
387#define GblDateTime_create_1(year)
388 (GblDateTime_create_2(year, GBL_MONTH_JANUARY))
389#define GblDateTime_create_2(year, month)
390 (GblDateTime_create_3(year, month, 1))
391#define GblDateTime_create_3(year, month, day)
392 (GblDateTime_create_4(year, month, day, 0))
393#define GblDateTime_create_4(year, month, day, hour)
394 (GblDateTime_create_5(year, month, day, hour, 0))
395#define GblDateTime_create_5(year, month, day, hour, min)
396 (GblDateTime_create_6(year, month, day, hour, min, 0))
397#define GblDateTime_create_6(year, month, day, hour, min, sec)
398 (GblDateTime_create_7(year, month, day, hour, min, sec, 0))
399#define GblDateTime_create_7(year, month, day, hour, min, sec, ns)
400 (GblDateTime_create_8(year, month, day, hour, min, sec, ns, 0))
401#define GblDateTime_create_8(year, month, day, hour, min, sec, ns, tz)
402 ((GblDateTime_create)(year, month, day, hour, min, sec, ns, tz))
403#define GblDateTime_create(...)
404 GBL_VA_OVERLOAD_CALL_ARGC(GblDateTime_create, __VA_ARGS__)
405
406#define GblDateTime_set_2(self, year)
407 (GblDateTime_set_3(self, year, GBL_MONTH_JANUARY))
408#define GblDateTime_set_3(self, year, month)
409 (GblDatetime_set_4(self, year, month, 1))
410#define GblDateTime_set_4(self, year, month, day)
411 (GblDateTime_set_5(self, year, month, day, 0))
412#define GblDateTime_set_5(self, year, month, day, hour)
413 (GblDateTime_set_6(self, year, month, day, hour, 0))
414#define GblDateTime_set_6(self, year, month, day, hour, min)
415 (GblDateTime_set_7(self, year, month, day, hour, min, 0))
416#define GblDateTime_set_7(self, year, month, day, hour, min, sec)
417 (GblDateTime_set_8(self, year, month, day, hour, min, sec, 0))
418#define GblDateTime_set_8(self, year, month, day, hour, min, sec, ns)
419 (GblDateTime_set_9(self, year, month, day, hour, min, sec, ns, 0))
420#define GblDateTime_set_9(self, year, month, day, hour, min, sec, ns, tz)
421 ((GblDateTime_set)(self, year, month, day, hour, min, sec, ns, tz))
422#define GblDateTime_set(...)
423 GBL_VA_OVERLOAD_CALL_ARGC(GblDateTime_set, __VA_ARGS__)
424///\endcond
425
426#endif // GIMBAL_DATE_TIME_H
#define GBL_NOEXCEPT
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.
GblSecond GblTime_localUtcOffset(void)
Returns the number of seconds the local time is offset from UTC time.
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 * GblTime_amPmStr(GblBool isPm)
Returns the string "PM" if isPm is GBL_TRUE, otherwise returns "AM".
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.
GblWeekDay
@ 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.
GblTimeSpec GblTime_specDiff(const GblTimeSpec *pSrc1, const GblTimeSpec *pSrc2)
Returns the difference between two NS-resolution GblTimeSpec values.
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_MAY
May.
@ GBL_MONTH_JULY
July.
@ GBL_MONTH_MARCH
March.
@ GBL_MONTH_APRIL
April.
@ GBL_MONTH_JANUARY
January.
@ GBL_MONTH_SEPTEMBER
September.
@ GBL_MONTH_JUNE
June.
@ GBL_MONTH_AUGUST
August.
#define GBL_DECLS_BEGIN
#define GBL_TYPEID(instanceStruct)
#define GBL_DECLARE_ENUM(E)
#define GBL_DECLARE_TYPE(instanceStruct)
#define GBL_CLASS_DERIVE_EMPTY(...)
#define GBL_EXPORT
#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.
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.
GblYear year
Year.
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.
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.
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.