pub fn parse_time(input: &str) -> Result<i64, ObzError>Expand description
Parse a time expression into Unix seconds.
Supports Prometheus/Grafana shorthand (now-1h, -30m), Unix
timestamps (@<seconds> or @<milliseconds>), and all formats
supported by parse_datetime (RFC3339, natural language like
yesterday, 1 hour ago).
For @<digits> timestamps, 13-digit values are treated as
milliseconds and automatically converted to seconds.
§Arguments
input— The time expression string.
§Errors
Returns ObzError::InvalidArgument if the input cannot be parsed.
§Examples
use obz_core::time::parse_time;
// These all work:
let ts = parse_time("now").unwrap();
assert!(ts > 0);
let ts = parse_time("@1740280800").unwrap();
assert_eq!(ts, 1740280800);
// 13-digit millisecond timestamp → auto-converted to seconds
let ts = parse_time("@1740280800000").unwrap();
assert_eq!(ts, 1740280800);
let ts = parse_time("2026-03-24T10:00:00Z").unwrap();
assert_eq!(ts, 1774346400);