Skip to main content

convert_timezone

Function convert_timezone 

Source
pub fn convert_timezone(
    datetime: &str,
    target_timezone: &str,
) -> Result<ConvertedDatetime, TruthError>
Expand description

Convert a datetime string to a different timezone representation.

§Arguments

  • datetime — An RFC 3339 datetime string (e.g., "2026-03-15T14:00:00Z")
  • target_timezone — An IANA timezone name (e.g., "America/New_York")

§Returns

A ConvertedDatetime with the same instant expressed in the target timezone, plus metadata (UTC offset, DST status).

§Errors

Returns TruthError::InvalidDatetime if the datetime string cannot be parsed, or TruthError::InvalidTimezone if the timezone name is not a valid IANA timezone.

§Examples

use truth_engine::temporal::convert_timezone;

let result = convert_timezone("2026-03-15T14:00:00Z", "America/New_York").unwrap();
assert_eq!(result.timezone, "America/New_York");
// March 15 2026 is EDT (UTC-4), so 14:00 UTC = 10:00 local
assert!(result.local.contains("10:00:00"));