File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -30,13 +30,31 @@ pub enum TimeParseError {
30
30
StartTimeAfterEndTime ,
31
31
}
32
32
33
+ /// Represents a range of time with a start and end point.
33
34
#[ derive( Debug ) ]
34
35
pub struct TimeRange {
35
36
pub start : DateTime < Utc > ,
36
37
pub end : DateTime < Utc > ,
37
38
}
38
39
39
40
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
+ /// ```
40
58
pub fn parse_human_time ( start_time : & str , end_time : & str ) -> Result < Self , TimeParseError > {
41
59
let start: DateTime < Utc > ;
42
60
let end: DateTime < Utc > ;
You can’t perform that action at this time.
0 commit comments