With TimeZone (ZonedParsiDateTime) - parsicore/parsidate GitHub Wiki
Changes the timezone of this ZonedParsiDateTime
.
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.
-
new_tz
: A reference to a timezone object implementing theTimeZone
trait (&NewTz
).
This specifies the target timezone for conversion.
-
ZonedParsiDateTime<NewTz>
: A new instance with the datetime adjusted to the specified timezone.
The original instance remains unchanged.
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);