Add Duration (ZonedParsiDateTime) - parsicore/parsidate GitHub Wiki
Method add_duration (on ZonedParsiDateTime)
Adds a specified chrono::Duration to this ZonedParsiDateTime, returning a new ZonedParsiDateTime instance.
Description
This convenience method calculates a new ZonedParsiDateTime by adding the provided duration to the current datetime. All components of the datetime (date, time, and timezone offset) are taken into account.
For more idiomatic Rust code, you can alternatively use the + operator with chrono::Duration directly.
Arguments
duration: Achrono::Durationto add.- Positive values move the datetime forward.
- Negative values move the datetime backward.
Returns
ZonedParsiDateTime: A new instance with the datetime adjusted by the specified duration.
The original instance remains unchanged.
Examples (Rust)
use parsidate::{ZonedParsiDateTime}; // Assuming this type exists
use chrono::Duration;
// Create a ZonedParsiDateTime for 1403-01-01 23:00:00 in Tehran timezone
let dt = ZonedParsiDateTime::new(1403, 1, 1, 23, 0, 0, Tehran).unwrap();
// Add 2 hours. Same as using `+ Duration::hours(2)`
let later = dt.add_duration(Duration::hours(2));
// --- Check results ---
// Adding 2 hours crosses into the next day.
assert_eq!(later.date(), dt.date().with_day(2).unwrap()); // Expected date: 1403-01-02
assert_eq!(later.hour(), 1); // Hour correctly adjusted