Season (ParsiDateTime) - parsicore/parsidate GitHub Wiki
season
(on ParsiDateTime)
Method Returns the Persian season (بهار, تابستان, پاییز, زمستان) corresponding to the date part of this ParsiDateTime
instance.
Description
This method determines which of the four Persian seasons the date component (year
, month
, day
) of the ParsiDateTime
instance falls into.
It achieves this by delegating the calculation to the season
method of the underlying ParsiDate
component. For the specific rules defining which months belong to which season, please refer to the documentation of ParsiDate::season
.
- Spring (بهار): Months 1-3
- Summer (تابستان): Months 4-6
- Autumn (پاییز): Months 7-9
- Winter (زمستان): Months 10-12
Assumption: This method typically assumes the ParsiDateTime
instance holds a valid date. If the instance could potentially hold an invalid date (e.g., due to unsafe
creation), the error condition applies.
Returns
Ok(Season)
: If the date component is valid, returns the correspondingSeason
enum variant (e.g.,Season::Bahar
,Season::Tabestan
,Season::Paeez
,Season::Zemestan
) wrapped inOk
.Err(DateError::InvalidDate)
: If the date component of theParsiDateTime
instance is invalid (e.g., month 0 or 13). This error is propagated from the underlyingParsiDate::season
call.
Examples (Rust)
use parsidate::{ParsiDateTime, Season, DateError}; // Assuming these types exist
// Example 1: A date in Mordad (Month 5) falls in Summer (Tabestan)
let dt_summer = ParsiDateTime::new(1403, 5, 10, 12, 30, 0).unwrap();
assert_eq!(dt_summer.season(), Ok(Season::Tabestan));
// Example 2: A date in Dey (Month 10) falls in Winter (Zemestan)
let dt_winter = ParsiDateTime::new(1403, 10, 1, 0, 0, 0).unwrap();
assert_eq!(dt_winter.season(), Ok(Season::Zemestan));
// Example 3: Handling a potentially invalid date (if created unsafely)
// let invalid_dt = unsafe { ParsiDateTime::new_unchecked(1403, 0, 1, 10, 0, 0) }; // Invalid month 0
// assert_eq!(invalid_dt.season(), Err(DateError::InvalidDate));