Manages date and time values according to the Excel 1900 date system.
More...
#include <XLDateTime.hpp>
|
| static XLDateTime | now () |
| |
| static XLDateTime | fromString (const std::string &dateString, const std::string &format="%Y-%m-%d %H:%M:%S") |
| | Parses a string into an Excel date.
|
| |
Manages date and time values according to the Excel 1900 date system.
Excel represents dates as floating-point numbers where 1.0 is 1900-01-01. This class handles the historical "1900 Leap Year Bug" (Excel incorrectly treats 1900 as a leap year) to ensure absolute compatibility with Microsoft Excel files. All string inputs and outputs are in the ISO 8601-like format (YYYY-MM-DD HH:MM:SS) unless a custom format is specified.
◆ XLDateTime() [1/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
| ) |
|
|
default |
Constructs an object representing the Excel epoch (1900-01-01).
◆ XLDateTime() [2/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
double |
serial | ) |
|
|
explicit |
- Parameters
-
| serial | Excel's floating-point date representation. Must be >= 1.0. |
- Exceptions
-
| XLDateTimeError | if serial is less than 1.0 (Excel doesn't support earlier dates). |
◆ XLDateTime() [3/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
const std::tm & |
timepoint | ) |
|
|
explicit |
- Parameters
-
| timepoint | A standard C tm struct. Only date and time fields are used. |
- Exceptions
-
Converts a standard tm struct to an Excel serial number. The conversion process starts from the 1900 epoch and accounts for every full year and month before adding the current day and fractional time.
◆ XLDateTime() [4/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
time_t |
unixtime | ) |
|
|
explicit |
- Parameters
-
| unixtime | Seconds since the Unix epoch (1970-01-01 00:00:00 UTC). |
Unix-to-Excel conversion uses a fixed offset of 25569 days (the difference between the two epochs).
◆ XLDateTime() [5/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
const std::chrono::system_clock::time_point & |
timepoint | ) |
|
|
explicit |
- Parameters
-
| timepoint | A high-precision system clock time point. |
◆ XLDateTime() [6/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
const XLDateTime & |
other | ) |
|
|
default |
◆ XLDateTime() [7/7]
| OpenXLSX::XLDateTime::XLDateTime |
( |
XLDateTime && |
other | ) |
|
|
defaultnoexcept |
◆ ~XLDateTime()
| OpenXLSX::XLDateTime::~XLDateTime |
( |
| ) |
|
|
default |
◆ chrono()
| std::chrono::system_clock::time_point OpenXLSX::XLDateTime::chrono |
( |
| ) |
const |
Converts the Excel date to a C++ system_clock::time_point.
◆ fromString()
| XLDateTime OpenXLSX::XLDateTime::fromString |
( |
const std::string & |
dateString, |
|
|
const std::string & |
format = "%Y-%m-%d %H:%M:%S" |
|
) |
| |
|
static |
Parses a string into an Excel date.
- Parameters
-
| dateString | The source string (e.g., "2024-03-16 10:00:00"). |
| format | Standard strptime-compatible format string. |
- Exceptions
-
◆ now()
- Returns
- An XLDateTime object initialized to the current system time.
◆ operator std::tm()
| OpenXLSX::XLDateTime::operator std::tm |
( |
| ) |
const |
Explicitly converts the Excel date to a standard C tm struct.
◆ operator T()
template<typename T , typename = std::enable_if_t<std::is_floating_point_v<T>>>
| OpenXLSX::XLDateTime::operator T |
( |
| ) |
const |
|
inline |
Implicitly converts the date to a floating-point serial number.
This allows seamless integration with worksheet cell values.
◆ operator=() [1/4]
| XLDateTime & OpenXLSX::XLDateTime::operator= |
( |
const std::tm & |
timepoint | ) |
|
Updates the date from a tm struct.
◆ operator=() [2/4]
◆ operator=() [3/4]
| XLDateTime & OpenXLSX::XLDateTime::operator= |
( |
double |
serial | ) |
|
Updates the serial number and validates its range.
◆ operator=() [4/4]
◆ serial()
| double OpenXLSX::XLDateTime::serial |
( |
| ) |
const |
- Returns
- The raw Excel serial number (days since 1899-12-30).
◆ tm()
Decomposes the Excel serial number into its date and time components.
This method handles the 1900 leap year bug and rounding overflows to provide an accurate representation of the time.
Decomposition of the Excel serial number. The process handles the 1900 bug by treating 1900 as a leap year, ensuring that all subsequent dates are correctly aligned with Excel's calendar. Time components are extracted through fractional remainders, with an overflow check to handle precision rounding issues that could push a timestamp into the next second or day.
◆ toString()
| std::string OpenXLSX::XLDateTime::toString |
( |
const std::string & |
format = "%Y-%m-%d %H:%M:%S" | ) |
const |
Formats the date into a human-readable string.
- Parameters
-
| format | Standard strftime-compatible format string. |
The documentation for this class was generated from the following files:
- /home/runner/work/OpenXLSX-NX/OpenXLSX-NX/OpenXLSX/headers/XLDateTime.hpp
- /home/runner/work/OpenXLSX-NX/OpenXLSX-NX/OpenXLSX/sources/XLDateTime.cpp