pub fn iso8601_to_unix_nanos(date_string: String) -> Result<UnixNanos>
Expand description
Converts an ISO 8601 (RFC 3339) format string to UNIX nanoseconds timestamp.
This function accepts various ISO 8601 formats including:
- Full RFC 3339 with nanosecond precision: “2024-02-10T14:58:43.456789Z”
- RFC 3339 without fractional seconds: “2024-02-10T14:58:43Z”
- Simple date format: “2024-02-10” (interpreted as midnight UTC)
§Parameters
date_string
: The ISO 8601 formatted date string to parse
§Returns
Returns Ok(UnixNanos)
if the string is successfully parsed, or an error if the format
is invalid or the timestamp is out of range.
§Errors
Returns an error if:
- The string format is not a valid ISO 8601 format
- The timestamp is out of range for
UnixNanos
- The date/time values are invalid
§Examples
use nautilus_core::datetime::iso8601_to_unix_nanos;
use nautilus_core::UnixNanos;
// Full RFC 3339 format
let nanos = iso8601_to_unix_nanos("2024-02-10T14:58:43.456789Z".to_string())?;
assert_eq!(nanos, UnixNanos::from(1_707_577_123_456_789_000));
// Without fractional seconds
let nanos = iso8601_to_unix_nanos("2024-02-10T14:58:43Z".to_string())?;
assert_eq!(nanos, UnixNanos::from(1_707_577_123_000_000_000));
// Simple date format (midnight UTC)
let nanos = iso8601_to_unix_nanos("2024-02-10".to_string())?;
assert_eq!(nanos, UnixNanos::from(1_707_523_200_000_000_000));