Skip to content

Commit e7fdf70

Browse files
author
Devdutt Shenoi
committed
doc: code comments
1 parent e011daf commit e7fdf70

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/utils/time.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,31 @@ pub enum TimeParseError {
3030
StartTimeAfterEndTime,
3131
}
3232

33+
/// Represents a range of time with a start and end point.
3334
#[derive(Debug)]
3435
pub struct TimeRange {
3536
pub start: DateTime<Utc>,
3637
pub end: DateTime<Utc>,
3738
}
3839

3940
impl TimeRange {
41+
/// Parses human-readable time strings into a `TimeRange` object.
42+
///
43+
/// # Arguments
44+
/// - `start_time`: A string representing the start of the time range. This can either be
45+
/// a human-readable duration (e.g., `"2 hours"`) or an RFC 3339 formatted timestamp.
46+
/// - `end_time`: A string representing the end of the time range. This can either be
47+
/// the keyword `"now"` (to represent the current time) or an RFC 3339 formatted timestamp.
48+
///
49+
/// # Errors
50+
/// - `TimeParseError::StartTimeAfterEndTime`: Returned when the parsed start time is later than the end time.
51+
/// - Any error that might occur during parsing of durations or RFC 3339 timestamps.
52+
///
53+
/// # Example
54+
/// ```
55+
/// let range = TimeRange::parse_human_time("2 hours", "now");
56+
/// let range = TimeRange::parse_human_time("2023-01-01T12:00:00Z", "2023-01-01T15:00:00Z");
57+
/// ```
4058
pub fn parse_human_time(start_time: &str, end_time: &str) -> Result<Self, TimeParseError> {
4159
let start: DateTime<Utc>;
4260
let end: DateTime<Utc>;

0 commit comments

Comments
 (0)