|
nfx-datetime 0.1.1
Cross-platform C++ DateTime library with 100-nanosecond precision and ISO 8601 support
|
Cross-platform DateTime type with 100-nanosecond precision. More...
#include <nfx/datetime/DateTime.h>
Public Types | |
| enum class | Format : std::uint8_t { Iso8601Basic , Iso8601Extended , Iso8601WithOffset , DateOnly , TimeOnly , UnixSeconds , UnixMilliseconds } |
| DateTime string format options. More... | |
Public Member Functions | |
| constexpr | DateTime () noexcept |
| Default constructor (minimum DateTime value). | |
| constexpr | DateTime (std::int64_t ticks) noexcept |
| Construct from tick count (100-nanosecond units since year 1). | |
| DateTime (std::chrono::system_clock::time_point timePoint) noexcept | |
| Construct from system clock time point. | |
| DateTime (std::int32_t year, std::int32_t month, std::int32_t day) noexcept | |
| Construct from date components. | |
| DateTime (std::int32_t year, std::int32_t month, std::int32_t day, std::int32_t hour, std::int32_t minute, std::int32_t second) noexcept | |
| Construct from date and time components. | |
| DateTime (std::int32_t year, std::int32_t month, std::int32_t day, std::int32_t hour, std::int32_t minute, std::int32_t second, std::int32_t millisecond) noexcept | |
| Construct from date and time components with milliseconds. | |
| DateTime (std::string_view iso8601String) | |
| Parse from ISO 8601 string. | |
| DateTime (const DateTime &)=default | |
| Copy constructor. | |
| DateTime (DateTime &&) noexcept=default | |
| Move constructor. | |
| ~DateTime ()=default | |
| Destructor. | |
| DateTime & | operator= (const DateTime &)=default |
| Copy assignment operator. | |
| DateTime & | operator= (DateTime &&) noexcept=default |
| Move assignment operator. | |
| constexpr std::strong_ordering | operator<=> (const DateTime &other) const noexcept |
| Three-way comparison operator. | |
| constexpr bool | operator== (const DateTime &other) const noexcept |
| Equality comparison. | |
| constexpr DateTime | operator+ (const TimeSpan &duration) const noexcept |
| Add time duration. | |
| constexpr DateTime | operator- (const TimeSpan &duration) const noexcept |
| Subtract time duration. | |
| constexpr TimeSpan | operator- (const DateTime &other) const noexcept |
| Get time difference between DateTimes. | |
| constexpr DateTime & | operator+= (const TimeSpan &duration) noexcept |
| Add time duration (in-place). | |
| constexpr DateTime & | operator-= (const TimeSpan &duration) noexcept |
| Subtract time duration (in-place). | |
| std::int32_t | year () const noexcept |
| Get year component (1-9999). | |
| std::int32_t | month () const noexcept |
| Get month component (1-12). | |
| std::int32_t | day () const noexcept |
| Get day component (1-31). | |
| std::int32_t | hour () const noexcept |
| Get hour component (0-23). | |
| std::int32_t | minute () const noexcept |
| Get minute component (0-59). | |
| std::int32_t | second () const noexcept |
| Get second component (0-59). | |
| std::int32_t | millisecond () const noexcept |
| Get millisecond component (0-999). | |
| std::int32_t | microsecond () const noexcept |
| Get microsecond component (0-999). | |
| std::int32_t | nanosecond () const noexcept |
| Get nanosecond component (0-900, in 100ns increments). | |
| constexpr std::int64_t | ticks () const noexcept |
| Get tick count (100-nanosecond units since year 1). | |
| std::int32_t | dayOfWeek () const noexcept |
| Get day of week (0=Sunday, 6=Saturday). | |
| std::int32_t | dayOfYear () const noexcept |
| Get day of year (1-366). | |
| constexpr std::int64_t | toEpochSeconds () const noexcept |
| Convert to Epoch timestamp (seconds since epoch). | |
| constexpr std::int64_t | toEpochMilliseconds () const noexcept |
| Convert to Epoch timestamp (milliseconds since epoch). | |
| DateTime | date () const noexcept |
| Get date component (time set to 00:00:00). | |
| TimeSpan | timeOfDay () const noexcept |
| Get time of day as duration since midnight. | |
| bool | isValid () const noexcept |
| Check if this DateTime is valid. | |
| std::string | toString () const |
| Convert to ISO 8601 string (basic format). | |
| std::string | toString (Format format) const |
| Convert to string using specified format. | |
| std::string | toIso8601Extended () const |
| Convert to ISO 8601 extended format with full precision. | |
| std::chrono::system_clock::time_point | toChrono () const noexcept |
| Convert to std::chrono::system_clock::time_point. | |
Static Public Member Functions | |
| static constexpr bool | isLeapYear (std::int32_t year) noexcept |
| Check if given year is a leap year. | |
| static constexpr std::int32_t | daysInMonth (std::int32_t year, std::int32_t month) noexcept |
| Get days in month for given year and month. | |
| static DateTime | now () noexcept |
| Get current local time. | |
| static DateTime | utcNow () noexcept |
| Get current UTC time. | |
| static DateTime | today () noexcept |
| Get current local date (time set to 00:00:00). | |
| static constexpr DateTime | min () noexcept |
| Get minimum DateTime value. | |
| static constexpr DateTime | max () noexcept |
| Get maximum DateTime value. | |
| static constexpr DateTime | epoch () noexcept |
| Get Unix epoch DateTime (January 1, 1970 00:00:00 UTC). | |
| static bool | fromString (std::string_view iso8601String, DateTime &result) noexcept |
| Parse ISO 8601 string safely without throwing exceptions. | |
| static std::optional< DateTime > | fromString (std::string_view iso8601String) noexcept |
| Parse ISO 8601 string and return optional DateTime. | |
| static constexpr DateTime | fromEpochSeconds (std::int64_t seconds) noexcept |
| Create from Epoch timestamp (seconds since epoch). | |
| static constexpr DateTime | fromEpochMilliseconds (std::int64_t milliseconds) noexcept |
| Create from Epoch timestamp (milliseconds since epoch). | |
| static DateTime | fromChrono (const std::chrono::system_clock::time_point &timePoint) noexcept |
| Create DateTime from std::chrono::system_clock::time_point. | |
Cross-platform DateTime type with 100-nanosecond precision.
Implements datetime operations with:
Note: DateTime doesn't store timezone information. For explicit timezone offset tracking, use DateTimeOffset instead.
Definition at line 223 of file datetime/DateTime.h.
|
strong |
DateTime string format options.
Provides type-safe format selection with self-documenting format names
Definition at line 234 of file datetime/DateTime.h.
|
inlineexplicitconstexprnoexcept |
Construct from tick count (100-nanosecond units since year 1).
| ticks | Number of 100-nanosecond intervals since January 1, 0001 UTC |

|
inlineexplicitnoexcept |
Construct from system clock time point.
| timePoint | System clock time point to convert from |

|
noexcept |
Construct from date components.
| year | Year component (1-9999) |
| month | Month component (1-12) |
| day | Day component (1-31) |

|
noexcept |
Construct from date and time components.
| year | Year component (1-9999) |
| month | Month component (1-12) |
| day | Day component (1-31) |
| hour | Hour component (0-23) |
| minute | Minute component (0-59) |
| second | Second component (0-59) |

|
noexcept |
Construct from date and time components with milliseconds.
| year | Year component (1-9999) |
| month | Month component (1-12) |
| day | Day component (1-31) |
| hour | Hour component (0-23) |
| minute | Minute component (0-59) |
| second | Second component (0-59) |
| millisecond | Millisecond component (0-999) |

|
inlineexplicit |
Parse from ISO 8601 string.
| iso8601String | ISO 8601 formatted string to parse |

|
nodiscardnoexcept |
Get date component (time set to 00:00:00).


|
nodiscardnoexcept |
Get day component (1-31).


|
nodiscardnoexcept |
Get day of week (0=Sunday, 6=Saturday).


|
nodiscardnoexcept |
Get day of year (1-366).


|
inlinestaticnodiscardconstexprnoexcept |
Get days in month for given year and month.
| year | The year to check (1-9999) |
| month | The month to check (1-12) |


|
inlinestaticnodiscardconstexprnoexcept |
Get Unix epoch DateTime (January 1, 1970 00:00:00 UTC).


|
staticnodiscardnoexcept |
Create DateTime from std::chrono::system_clock::time_point.
Values outside the representable range of DateTime will be clamped to the nearest valid DateTime value.
| timePoint | The system_clock time point to convert |


|
inlinestaticnodiscardconstexprnoexcept |
Create from Epoch timestamp (milliseconds since epoch).
| milliseconds | The number of milliseconds since Unix epoch (January 1, 1970 00:00:00 UTC) |


|
inlinestaticnodiscardconstexprnoexcept |
Create from Epoch timestamp (seconds since epoch).
| seconds | The number of seconds since Unix epoch (January 1, 1970 00:00:00 UTC) |


|
staticnodiscardnoexcept |
Parse ISO 8601 string and return optional DateTime.
| iso8601String | The ISO 8601 formatted string to parse |

|
staticnodiscardnoexcept |
Parse ISO 8601 string safely without throwing exceptions.
| iso8601String | The ISO 8601 formatted string to parse |
| result | Reference to store the parsed DateTime if successful |


|
nodiscardnoexcept |
Get hour component (0-23).


|
inlinestaticnodiscardconstexprnoexcept |
Check if given year is a leap year.
| year | The year to check for leap year status |


|
nodiscardnoexcept |
Check if this DateTime is valid.


|
inlinestaticnodiscardconstexprnoexcept |
Get maximum DateTime value.


|
nodiscardnoexcept |
Get microsecond component (0-999).


|
nodiscardnoexcept |
Get millisecond component (0-999).


|
inlinestaticnodiscardconstexprnoexcept |
Get minimum DateTime value.


|
nodiscardnoexcept |
Get minute component (0-59).


|
nodiscardnoexcept |
Get month component (1-12).


|
nodiscardnoexcept |
Get nanosecond component (0-900, in 100ns increments).


|
staticnodiscardnoexcept |
Get current local time.


Add time duration.
| duration | The TimeSpan to add to this DateTime |

Add time duration (in-place).
| duration | The TimeSpan to add to this DateTime |

Get time difference between DateTimes.
| other | The DateTime to subtract from this DateTime |

Subtract time duration.
| duration | The TimeSpan to subtract from this DateTime |

Subtract time duration (in-place).
| duration | The TimeSpan to subtract from this DateTime |

|
inlineconstexprnoexcept |
Three-way comparison operator.
| other | The DateTime to compare with |

Copy assignment operator.

Move assignment operator.

|
inlineconstexprnoexcept |
Equality comparison.
| other | The DateTime to compare with |

|
nodiscardnoexcept |
Get second component (0-59).


|
nodiscardconstexprnoexcept |
Get tick count (100-nanosecond units since year 1).


|
nodiscardnoexcept |
Get time of day as duration since midnight.


|
nodiscardnoexcept |
Convert to std::chrono::system_clock::time_point.
Values outside the representable range of std::chrono::system_clock (approximately years 1677-2262 on 64-bit Linux systems) will be clamped to the nearest representable value. This means extreme dates (near year 1 or year 9999) cannot round-trip through chrono.


|
staticnodiscardnoexcept |
Get current local date (time set to 00:00:00).


|
inlinenodiscardconstexprnoexcept |
Convert to Epoch timestamp (milliseconds since epoch).


|
inlinenodiscardconstexprnoexcept |
Convert to Epoch timestamp (seconds since epoch).


|
nodiscard |
Convert to ISO 8601 extended format with full precision.


|
nodiscard |
Convert to ISO 8601 string (basic format).


|
nodiscard |
Convert to string using specified format.
| format | The format to use for string conversion |

|
staticnodiscardnoexcept |
Get current UTC time.


|
nodiscardnoexcept |
Get year component (1-9999).

