With TimeZone (ZonedParsiDateTime) - parsicore/parsidate GitHub Wiki

Method with_timezone (on ZonedParsiDateTime)

Changes the timezone of this ZonedParsiDateTime.

Description

This method converts the datetime to a different timezone while preserving the absolute instant in time.

The local (“wall-clock”) date and time components will be adjusted to reflect the new timezone.
This is useful for converting events or datetimes between timezones without altering the actual moment in time.

Arguments

  • new_tz: A reference to a timezone object implementing the TimeZone trait (&NewTz).
    This specifies the target timezone for conversion.

Returns

  • ZonedParsiDateTime<NewTz>: A new instance with the datetime adjusted to the specified timezone.
    The original instance remains unchanged.

Examples (Rust)

use parsidate::{ZonedParsiDateTime, ParsiDate, Tz}; // Assuming these types exist

// An event at 2:00 AM in Tehran on Dey 10th.
let dt_tehran = ZonedParsiDateTime::new(1402, 10, 10, 2, 0, 0, Tehran).unwrap();

// Find out what time it was in London at that same moment.
let dt_london = dt_tehran.with_timezone(&London);

// In winter, Tehran (UTC+3:30) is 3.5 hours ahead of London (UTC+0).
// So, 2:00 AM in Tehran is 10:30 PM the *previous day* in London.
assert_eq!(dt_london.date(), ParsiDate::new(1402, 10, 9).unwrap());
assert_eq!(dt_london.hour(), 22);
assert_eq!(dt_london.minute(), 30);
⚠️ **GitHub.com Fallback** ⚠️