pub fn ms<T: ToMillis>(value: T) -> T::OutputExpand description
Parse or format the given value.
This is a unified interface that can handle both strings (parsing to milliseconds) and numbers (formatting to time strings). The return type is inferred from the input.
§Arguments
value- The string or number to convert
§Returns
Result<i64, String>if input was a string (parsed to milliseconds)Result<String, String>if input was a number (formatted to time string)
§Errors
Returns an error if the value cannot be parsed or formatted.
§Examples
use millis::ms;
// Parse string to milliseconds
let milliseconds = ms("2h").unwrap();
assert_eq!(milliseconds, 7200000);
let milliseconds = ms("1 day").unwrap();
assert_eq!(milliseconds, 86400000);
// Format milliseconds to string
let formatted = ms(7200000).unwrap();
assert_eq!(formatted, "2h");