pub struct ExcelDateTime { /* private fields */ }Expand description
Structure for Excel date and time representation.
Implementations§
Source§impl ExcelDateTime
impl ExcelDateTime
Sourcepub fn new(value: f64, datetime_type: ExcelDateTimeType, is_1904: bool) -> Self
pub fn new(value: f64, datetime_type: ExcelDateTimeType, is_1904: bool) -> Self
Creates a new ExcelDateTime
Sourcepub fn is_duration(&self) -> bool
pub fn is_duration(&self) -> bool
True if excel datetime has duration format ([hh]:mm:ss, for example)
Sourcepub fn is_datetime(&self) -> bool
pub fn is_datetime(&self) -> bool
True if excel datetime has datetime format (not duration)
Sourcepub fn to_ymd_hms_milli(&self) -> (u16, u8, u8, u8, u8, u8, u16)
pub fn to_ymd_hms_milli(&self) -> (u16, u8, u8, u8, u8, u8, u16)
Convert an Excel serial datetime to standard date components.
Datetimes in Excel are serial dates with days counted from an epoch (usually 1900-01-01) and where the time is a percentage/decimal of the milliseconds in the day. Both the date and time are stored in the same f64 value. For example, 2025/10/13 12:00:00 is stored as 45943.5.
This function returns a tuple of (year, month, day, hour, minutes, seconds, milliseconds). It works for serial dates in both the 1900 and 1904 epochs.
This function always returns a date, even if the serial value is outside
of Excel’s range of 0.0 <= datetime < 10000.0. It also returns, as
Excel does, the invalid date 1900/02/29 due to the Excel 1900 leap year
bug.
Excel only supports millisecond precision and it also doesn’t use or encode timezone information in any way.
§Examples
An example of converting an Excel date/time to standard components.
use calamine::{ExcelDateTime, ExcelDateTimeType};
// Create an Excel datetime from the serial value 45943.541 which is
// equivalent to the date "2025/10/13 12:59:02.400".
let excel_datetime = ExcelDateTime::new(
45943.541,
ExcelDateTimeType::DateTime,
false, // Using 1900 epoch (not 1904).
);
// Convert to standard date/time components.
let (year, month, day, hour, min, sec, milli) = excel_datetime.to_ymd_hms_milli();
assert_eq!(year, 2025);
assert_eq!(month, 10);
assert_eq!(day, 13);
assert_eq!(hour, 12);
assert_eq!(min, 59);
assert_eq!(sec, 2);
assert_eq!(milli, 400);Sourcepub fn as_duration(&self) -> Option<Duration>
Available on crate feature chrono only.
pub fn as_duration(&self) -> Option<Duration>
chrono only.Try converting data type into a duration.
Sourcepub fn as_datetime(&self) -> Option<NaiveDateTime>
Available on crate feature chrono only.
pub fn as_datetime(&self) -> Option<NaiveDateTime>
chrono only.Try converting data type into a datetime.
Trait Implementations§
Source§impl Clone for ExcelDateTime
impl Clone for ExcelDateTime
Source§fn clone(&self) -> ExcelDateTime
fn clone(&self) -> ExcelDateTime
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more