libGimbal 0.1.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#include "../platform/gimbal_time_.h"
21
22#define GBL_DATE_TIME_TYPE (GBL_TYPEID(GblDateTime))
23#define GBL_DATE_TIME_CLASS(klass) (GBL_CLASS_CAST(GblDateTime, klass))
24
25/*! \name Second Conversions
26 * \brief Defines for second conversion factors
27 * @{
28 */
29#define GBL_TIME_MSECS_PER_SEC 1000 //!< Number of milliseconds per second
30#define GBL_TIME_USECS_PER_SEC 1000000 //!< Number of microseconds per second
31#define GBL_TIME_NSECS_PER_SEC 1000000000 //!< Number of nanoseconds per second
32//! @}
33
34/*! \name Start Dates
35 * \brief Initial dates of epochs
36 * @{
37 */
38#define GBL_DATE_GREGORIAN_YEAR_FIRST 1582 //!< First year in Gregorian calendar
39#define GBL_DATE_UNIX_EPOCH_YEAR 1970 //!< Year of the Unix epoch
40#define GBL_DATE_UNIX_EPOCH_MONTH GBL_MONTH_JANUARY //!< Month of the Unix epoch
41#define GBL_DATE_UNIX_EPOCH_DAY 1 //!< Day of the unix epoch
42//! @}
43
44/*! \name Broken-down Time
45 * \brief Defines for working with broken-down time
46 * @{
47 */
48#define GBL_DATE_TIME_BROKEN_DOWN_YEAR_FIRST 1900 //!< Year offset of a broken-down time's date
49#define GBL_DATE_TIME_BROKEN_DOWN_YEAR_MIN 1970 //!< The oldest year a broken-down time can handle by spec
50#define GBL_DATE_TIME_BROKEN_DOWN_MONTH_OFFSET -1 //!< Month offset from GblMonth to a broken-down month
51//! @}
52
53/*! \name Formatting
54 * \brief Defines used when formatting and stringifying
55 * @{
56 */
57#define GBL_DATE_TIME_FORMAT_BUFFER_SIZE_INCREMENT 128 //!< Size increment when resizing format buffers
58#define GBL_DATE_TIME_FORMAT_BUFFER_SIZE_MULTIPLIER_MAX 10 //!< Maximum number of size increments for format buffers
59//! @}
60
61#define GBL_DATE_TIME_ISO8601_STRING_SIZE 29 //!< Required buffer size for going to an ISO8601-formatted string
62
64
65//! Represents a month of the 12-month year
67 GBL_MONTH_JANUARY = 1, //!< January
68 GBL_MONTH_FEBRUARY, //!< February
69 GBL_MONTH_MARCH, //!< March
70 GBL_MONTH_APRIL, //!< April
71 GBL_MONTH_MAY, //!< May
72 GBL_MONTH_JUNE, //!< June
73 GBL_MONTH_JULY, //!< July
74 GBL_MONTH_AUGUST, //!< August
75 GBL_MONTH_SEPTEMBER, //!< September
76 GBL_MONTH_OCTOBER, //!< October
77 GBL_MONTH_NOVEMBER, //!< November
78 GBL_MONTH_DECEMBER, //!< December
79 GBL_MONTH_COUNT = 12 //!< Months/Year
80};
81
82//! Represents a day of the 7-day week
87 GBL_WEEK_DAY_WEDNESDAY, //!< Wednesday
88 GBL_WEEK_DAY_THURSDAY, //!< Thursday
90 GBL_WEEK_DAY_SATURDAY, //!< Saturday
91 GBL_WEEK_DAY_COUNT //!< Days/Week
92};
93
94typedef int32_t GblYear; //!< Represents a calendar year
95typedef int32_t GblDay; //!< Represents a 24-hour day within a month (0-31)
96typedef int32_t GblNanoSecond; //!< Represents a nanosecond within a second (0-1000000000
97typedef int64_t GblSecond; //!< Represents a second in a 60-second minute (0-59)
98typedef int32_t GblMinute; //!< Represents a minute in a 60-minute hour (0-59)
99typedef int32_t GblHour; //!< Represents an hour within a 24-hour day (0-23)
100
101//! Represents the difference between two GblTime instances
102typedef struct timespec GblTimeSpec;
103
104/*! \name Type System
105 * \brief Type declarations for GblVariant time type
106 * @{
107 */
108GBL_DECLARE_TYPE(GblDateTime);
109GBL_CLASS_DERIVE_EMPTY(GblDateTime, GblOpaque);
110//! @}
111
112/*! Represents a calendar date
113 * \ingroup utils
114 */
115typedef struct GblDate {
116 GblYear year; //!< Year
117 GblMonth month; //!< Month of the year (1-12)
118 GblDay day; //!< Day of the month (1-31)
119} GblDate; // 12 Total bytes
120
121/*! Represents a time-of-day
122 * \ingroup utils
123 */
124typedef struct GblTime {
125 GblHour hours; //!< Hour within a day (0-23)
126 GblMinute minutes; //!< Minutes within an hour (0-59)
127 GblSecond seconds; //!< Seconds within a minute (0-59)
128 GblNanoSecond nSeconds; //!< Nanosconds within a second (0-1000000000)
129} GblTime; // 20 Total bytes
130
131/*! Represents a combined calendar date with time-of-day
132 * \ingroup utils
133 */
134typedef struct GblDateTime {
135 GblDate date; //!< Date structure
136 GblTime time; //!< Time structure
137 int16_t utcOffset; //!< Timezone second offset from UTC
138} GblDateTime; // 34 Total bytes
139
140/*! \name Date Static Methods
141 * \brief Non-member functions for date management
142 * @{
143 */
144//! Returns GBL_TRUE if the given year was a leap year, otherwise returns GBL_FALSE
146//! Returns the number of days in the given \p month of the given \p year
148 GblYear year) GBL_NOEXCEPT;
149//! Returns the string name of the given \p month
151//! Returns the short-handed string name of the given \p month
153//! Returns the string name of the given \p weekday
155//! Returns the short-handed string name of the given \p weekday
157//! @}
158
159/*! \name Date Methods
160 * \brief Member functions for GblDate
161 * \relatesalso GblDate
162 * @{
163 */
164//! Returns GBL_TRUE if the given structure represents a valid GblDate
166//! Returns GBL_TRUE if the given date is during daylight savings time
168//! Returns the Julian Day from the given date
170//! Returns the day of the week for the given date
172//! Returns the day-of-the-year (1-365) for the given date
174//! Returns the week-of-the-year (1-52) for the given date
175GBL_EXPORT uint8_t GblDate_yearWeek (const GblDate* pSelf) GBL_NOEXCEPT;
176//! Converts the given julian date to a GblDate, storing it in \p pSelf and returning it
177GBL_EXPORT GblDate* GblDate_fromJulian (GblDate* pSelf,
178 GblDay julianDate) GBL_NOEXCEPT;
179//! Converts the given ordinal date to a GblDate, storing it in \p pSelf and returning it
180GBL_EXPORT GblDate* GblDate_fromOrdinal (GblDate* pSelf,
181 GblYear year,
182 GblDay day) GBL_NOEXCEPT;
183//! Sets the given date structure, given its \p year, \p month, and \p day
184GBL_EXPORT void GblDate_set (GblDate* pSelf,
185 GblYear year,
186 GblMonth month,
187 GblDay day) GBL_NOEXCEPT;
188//! @}
189
190/*! \name Time Static Methods
191 * \brief Non-member functions for time management
192 * @{
193 */
194//! Returns the string "PM" if \p isPm is GBL_TRUE, otherwise returns "AM"
196//! Returns the number of seconds the local time is offset from UTC time
198//! Returns the difference between two NS-resolution GblTimeSpec values
200 const GblTimeSpec* pSrc2) GBL_NOEXCEPT;
201//! @}
202
203/*! \name Time Methods
204 * \brief Member functions for GblTime
205 * \relatesalso GblTime
206 * @{
207 */
208//! Returns GBL_TRUE if the given time structure represents a valid time
210//! Returns GBL_TRUE if the given GblTime is PM, false if it's AM
212//! Sets the values of the given GblTime structure, with nsecs defaulting to 0
213GBL_EXPORT void GblTime_set (GblTime* pSelf,
214 GblHour hours,
215 GblMinute mins,
216 GblSecond secs,
217 GblNanoSecond nsec/*=0*/) GBL_NOEXCEPT;
218//! @}
219
220/*! \name Read Accessors
221 * \brief Methods for getting values
222 * \relatesalso GblDateTime
223 * @{
224 */
225//! Returns GBL_TRUE if the given GblDateTime structure contains both a valid date and time
227//! Returns GBL_TRUE if the given date/time represents a date and time within the UTC timezone
229//! Returns GBL_TRUE if the given date/time represents a date and time in the local timezone
231//! @}
232
233/*! \name Dynamic Lifetime
234 * \brief Methods for managing shared references
235 * \relatesalso GblDateTime
236 * @{
237 */
238//! Creates and allocates a new shared reference to a GblDateTime
240 GblMonth month/*=1*/,
241 GblDay day /*=1*/,
242 GblHour hours/*=0*/,
243 GblMinute mins /*=0*/,
244 GblSecond secs /*=0*/,
245 GblNanoSecond ns /*=0*/,
246 GblSecond tzOff/*=0*/) GBL_NOEXCEPT;
247//! Returns a newly acquired reference to the given GblDateTime structure
248GBL_EXPORT GblDateTime* GblDateTime_ref (GblDateTime* pDt) GBL_NOEXCEPT;
249//! Decrements the refCounter by 1, destroying the struct at 0, and returning the new refCount value
251//! @}
252
253/*! \name Initialization
254 * \brief Methods for constructing and populating
255 * \relatesalso GblDateTime
256 * @{
257 */
258//! Sets the given date/time structure from a unix epoch time, returning a pointer to it
259GBL_EXPORT GblDateTime* GblDateTime_fromUnix (GblDateTime* pSelf,
260 time_t epoch) GBL_NOEXCEPT;
261//! Sets the given date/time from a GblTimeSpec value, returning a pointer to it
262GBL_EXPORT GblDateTime* GblDateTime_fromSpecUtc (GblDateTime* pSelf,
263 const GblTimeSpec* pSpec) GBL_NOEXCEPT;
264//! Sets the given date/time from a local broken-down time, returning a pointer to it
265GBL_EXPORT GblDateTime* GblDateTime_fromLocal (GblDateTime* pSelf,
266 const struct tm* pLocal) GBL_NOEXCEPT;
267//! Sets the given date/time from a UTC broken-down time, returning a pointer to it
268GBL_EXPORT GblDateTime* GblDateTime_fromUtc (GblDateTime* pSelf,
269 const struct tm* pUtc) GBL_NOEXCEPT;
270//! Sets the given date/time to the current local time, returning a pointer to it
271GBL_EXPORT GblDateTime* GblDateTime_nowLocal (GblDateTime* pSelf) GBL_NOEXCEPT;
272//! Sets the given date/time to the current UTC time, returning a pointer to it
273GBL_EXPORT GblDateTime* GblDateTime_nowUtc (GblDateTime* pSelf) GBL_NOEXCEPT;
274//! Parses the given string using the strptime() formatter, storing and returning \p pSelf
275GBL_EXPORT GblDateTime* GblDateTime_parse (GblDateTime* pSelf,
276 const char* pString,
277 const char* pFormat) GBL_NOEXCEPT;
278//! @}
279
280/*! \name Conversions
281 * \brief Methods for converting to another format
282 * \relatesalso GblDateTime
283 * @{
284 */
285//! Converts the given GblDateTime to a unix epoch time
286GBL_EXPORT time_t GblDateTime_toUnix (const GblDateTime* pSelf) GBL_NOEXCEPT;
287//! Converts the given GblDateTime to a timespec UTC time
289//! Converts the given GblDateTime to a broken-down local time
290GBL_EXPORT GBL_RESULT GblDateTime_toLocal (const GblDateTime* pSelf,
291 struct tm* pTm) GBL_NOEXCEPT;
292//! Converts the given GblDateTime to a broken-down UTC time
293GBL_EXPORT GBL_RESULT GblDateTime_toUtc (const GblDateTime* pSelf,
294 struct tm* pTm) GBL_NOEXCEPT;
295//! Fills in the given buffer with the ISO8601 representation of the given date/time, return its C string
296GBL_EXPORT const char* GblDateTime_toIso8601 (const GblDateTime* pSelf,
297 GblStringBuffer* pBuff) GBL_NOEXCEPT;
298//! Fills in the given buffer with the strftime()-formatted GblDateTime, returning its C string
299GBL_EXPORT const char* GblDateTime_format (const GblDateTime* pSelf,
300 GblStringBuffer* pBuffer,
301 const char* pFmt) GBL_NOEXCEPT;
302//! @}
303
304/*! \name Write Accessors
305 * \brief Methods for writing values
306 * \relatesalso GblDateTime
307 * @{
308 */
309//! Ensures all values within the given GblDateTime are within range and returns a pointer to it
310GBL_EXPORT GblDateTime* GblDateTime_normalize (GblDateTime* pSelf) GBL_NOEXCEPT;
311//! Sets the GblDate value of the given GblDateTime to \p pDate
312GBL_EXPORT void GblDateTime_setDate (GblDateTime* pSelf,
313 const GblDate* pDate) GBL_NOEXCEPT;
314//! Sets the GblTime value of the given GblDateTime to \p pTime
315GBL_EXPORT void GblDateTime_setTime (GblDateTime* pSelf,
316 const GblTime* pTime) GBL_NOEXCEPT;
317//! Sets the values of the given GblDateTime, with default argument values provided
318GBL_EXPORT GblDateTime* GblDateTime_set (GblDateTime* pSelf,
319 GblYear year,
320 GblMonth month/*=1*/,
321 GblDay day /*=1*/,
322 GblHour hours/*=0*/,
323 GblMinute mins /*=0*/,
324 GblSecond secs /*=0*/,
325 GblNanoSecond ns /*=0*/,
326 GblSecond tzOff/*=0*/) GBL_NOEXCEPT;
327//! @}
328
329/*! \name Operators
330 * \brief Methods implementing operations
331 * \relatesalso GblDateTime
332 * @{
333 */
334//! Lexacographically compares the two GblDateTimes, returning 0, -1, or 1
335GBL_EXPORT int GblDateTime_compare (const GblDateTime* pSelf,
336 const GblDateTime* pRhs) GBL_NOEXCEPT;
337//! Returns GBL_TRUE if the two provided GblDateTimes have the same value
338GBL_EXPORT GblBool GblDateTime_equals (const GblDateTime* pSelf,
339 const GblDateTime* pRhs) GBL_NOEXCEPT;
340//! Returns the NS-resolution GblTimeSpec difference between two GblDateTime values
341GBL_EXPORT GblTimeSpec GblDateTime_diff (const GblDateTime* pSelf,
342 const GblDateTime* pRhs) GBL_NOEXCEPT;
343//! Adds the \p pRhs GblDateTime to \p pSelf, returning a pointer to \p pSelf
344GBL_EXPORT GblDateTime* GblDateTime_add (GblDateTime* pSelf,
345 const GblDateTime* pRhs) GBL_NOEXCEPT;
346//! Adds the given number of \p days to the given GblDateTime, returning a pointer to it
347GBL_EXPORT GblDateTime* GblDateTime_addDays (GblDateTime* pSelf,
348 GblDay days) GBL_NOEXCEPT;
349//! Adds the given number of \p hours to the given GblDateTime, returning a pointer to it
350GBL_EXPORT GblDateTime* GblDateTime_addHours (GblDateTime* pSelf,
351 GblHour hours) GBL_NOEXCEPT;
352//! Adds the given number of \p minutes to the given GblDateTime, returning a pointer to it
353GBL_EXPORT GblDateTime* GblDateTime_addMinutes (GblDateTime* pSelf,
354 GblMinute minutes) GBL_NOEXCEPT;
355//! Adds the given number of \p seconds to the given GblDateTime, returning a pointer to it
356GBL_EXPORT GblDateTime* GblDateTime_addSeconds (GblDateTime* pSelf,
357 GblSecond seconds) GBL_NOEXCEPT;
358//! Adds the given number of milliseconds to the given GblDateTime, returning a pointer to it
359GBL_EXPORT GblDateTime* GblDateTime_addMilliSecs (GblDateTime* pSelf,
360 int mSecs) GBL_NOEXCEPT;
361//! Adds the given number of microseconds to the given GblDateTime, returning a pointer to it
362GBL_EXPORT GblDateTime* GblDateTime_addMicroSecs (GblDateTime* pSelf,
363 int uSecs) GBL_NOEXCEPT;
364//! Adds the given number of nanoseconds s to the given GblDateTime, returning a pointer to it
365GBL_EXPORT GblDateTime* GblDateTime_addNanoSecs (GblDateTime* pSelf,
367//! Adds the given number of \p weeks to the given GblDateTime, returning a pointer to it
368GBL_EXPORT GblDateTime* GblDateTime_addWeeks (GblDateTime* pSelf,
369 int weeks) GBL_NOEXCEPT;
370//! Adds the given number of \p months to the given GblDateTime, returning a pointer to it
371GBL_EXPORT GblDateTime* GblDateTime_addMonths (GblDateTime* pSelf,
372 int months) GBL_NOEXCEPT;
373//! Adds the given number of \p years to the given GblDateTime, returning a pointer to it
374GBL_EXPORT GblDateTime* GblDateTime_addYears (GblDateTime* pSelf,
375 GblYear years) GBL_NOEXCEPT;
376//! @}
377
379
380///\cond
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(...)
386 GBL_VA_OVERLOAD_CALL_ARGC(GblTime_set, __VA_ARGS__)
387
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(...)
405 GBL_VA_OVERLOAD_CALL_ARGC(GblDateTime_create, __VA_ARGS__)
406
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(...)
424 GBL_VA_OVERLOAD_CALL_ARGC(GblDateTime_set, __VA_ARGS__)
425///\endcond
426
427#endif // GIMBAL_DATE_TIME_H
#define GBL_CLASS_CAST(cType, klass)
#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.
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.
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.
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.
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.
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.
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.