Hour (ParsiDateTime) - jalalvandi/ParsiDate GitHub Wiki

Method hour (on ParsiDateTime)

Returns the hour component of the time part of this ParsiDateTime.

Description

This method provides simple, read-only access to the hour value stored within the ParsiDateTime instance. The hour is represented using a 24-hour clock format.

The value returned will be an integer between 0 and 23 (inclusive):

  • 0 represents midnight (start of the day).
  • 12 represents noon.
  • 23 represents the hour from 11:00 PM to 11:59:59 PM.

Assumption: This method assumes the ParsiDateTime instance holds a valid hour number (0-23), as usually ensured by safe constructors.

Returns

  • An integer (u8 or similar type) representing the hour of the day (0-23).

Examples (Rust)

use parsidate::ParsiDateTime; // Assuming use of a hypothetical ParsiDateTime struct

// Example 1: Morning hour (9 AM)
let dt_morning = ParsiDateTime::new(1403, 1, 1, 9, 15, 30).unwrap();
assert_eq!(dt_morning.hour(), 9);

// Example 2: Evening hour (9 PM)
let dt_evening = ParsiDateTime::new(1403, 1, 1, 21, 0, 0).unwrap();
assert_eq!(dt_evening.hour(), 21);

// Example 3: Midnight hour (00:00)
let dt_midnight = ParsiDateTime::new(1403, 1, 1, 0, 5, 10).unwrap();
assert_eq!(dt_midnight.hour(), 0);

// Example 4: Hour just before midnight (11 PM)
// let dt_before_midnight = ParsiDateTime::new(1403, 1, 1, 23, 59, 59).unwrap();
// assert_eq!(dt_before_midnight.hour(), 23);