Day - parsicore/parsidate GitHub Wiki
day
Method Returns the day-of-the-month component of this ParsiDate
instance.
Description
This method provides read-only access to the day component of the date stored within the ParsiDate
object. It simply returns the stored day value.
The returned value typically ranges from 1 up to 29, 30, or 31, depending on the specific month and whether the ParsiDate
's year is a Persian leap year.
- Months 1-6 (Farvardin to Shahrivar) have 31 days.
- Months 7-11 (Mehr to Bahman) have 30 days.
- Month 12 (Esfand) has 30 days in a leap year and 29 days in a common year.
Arguments
This method takes no arguments. It is called on an existing ParsiDate
instance (self
).
Returns
- An integer type (typically
u8
oru32
) representing the day of the month (1-31) of theParsiDate
instance.
Note: This method retrieves a pre-validated value from the object and does not perform calculations that could fail. Therefore, it typically does not return an error.
Examples (Rust)
use parsidate::ParsiDate; // Assuming ParsiDate and its constructor exist
// Create a standard date
let date = ParsiDate::new(1403, 5, 2).expect("Failed to create ParsiDate");
// Get the day component
let day_of_month = date.day();
// Verify the day
assert_eq!(day_of_month, 2);
println!("The day is: {}", day_of_month); // Output: The day is: 2
// Example with end of a 31-day month
let date_end_month = ParsiDate::new(1403, 1, 31).expect("Failed to create ParsiDate");
assert_eq!(date_end_month.day(), 31);
println!("End of Farvardin: Day {}", date_end_month.day()); // Output: End of Farvardin: Day 31
// Example with end of a 30-day month
let date_end_month_30 = ParsiDate::new(1403, 7, 30).expect("Failed to create ParsiDate");
assert_eq!(date_end_month_30.day(), 30);
// Example with Persian leap day (Esfand 30th in a leap year like 1403)
let date_leap_day = ParsiDate::new(1403, 12, 30).expect("Failed to create ParsiDate");
assert_eq!(date_leap_day.day(), 30);
println!("Leap Day: Day {}", date_leap_day.day()); // Output: Leap Day: Day 30
// Example with last day of Esfand in a non-leap year (e.g., 1402)
let date_common_esfand = ParsiDate::new(1402, 12, 29).expect("Failed to create ParsiDate");
assert_eq!(date_common_esfand.day(), 29);