@@ -128,6 +128,9 @@ where
128128 }
129129
130130 /// Returns the range from series start (inclusive) to series end (exclusive).
131+ ///
132+ /// If the series has a non-zero event duration configured, the returned range will end at
133+ /// `initial_end - event_duration`.
131134 pub fn range ( & self ) -> & Range < DateTime > {
132135 & self . range
133136 }
@@ -142,7 +145,10 @@ where
142145 /// Returns the `DateTime` at which the series ends (exclusive).
143146 ///
144147 /// Don't confuse this with the time of the last event in the series. It is merely an upper
145- /// bound until which the series will yield events.
148+ /// bound until after which the series will stop yielding events.
149+ ///
150+ /// If the series has a non-zero event duration configured, this will return `initial_end -
151+ /// event_duration`.
146152 pub fn end ( & self ) -> DateTime {
147153 self . range . end
148154 }
@@ -578,6 +584,9 @@ where
578584 /// If `.event_duration()` is not called with a custom value, events will not have an end
579585 /// datetime.
580586 ///
587+ /// The event duration may be longer than the time between the dates produces by the recurrence
588+ /// pattern, in which case events will overlap.
589+ ///
581590 /// # Example
582591 ///
583592 /// ```
@@ -625,8 +634,9 @@ where
625634 ///
626635 /// # Errors
627636 ///
628- /// Returns an `Error` if the configured `end` is less than or equal to `start`, or if the
629- /// configured `event_duration` is negative.
637+ /// Returns an `Error` if the configured `end` is less than or equal to `start`, if the
638+ /// configured `event_duration` is negative, or if the `event_duration` greater or equal to the
639+ /// range (`start..end`) of the series.
630640 ///
631641 /// # Example
632642 ///
@@ -642,15 +652,20 @@ where
642652 /// # Ok::<(), Box<dyn core::error::Error>>(())
643653 /// ```
644654 pub fn build ( self ) -> Result < Series < P > , Error > {
645- let range = try_simplify_range ( self . bounds ) ?;
646- if range. start >= range. end {
647- return Err ( Error :: from ( ErrorKind :: InvalidBounds ) ) ;
648- }
655+ let mut range = try_simplify_range ( self . bounds ) ?;
649656
650657 if self . event_duration . is_negative ( ) {
651658 return Err ( Error :: from ( ErrorKind :: InvalidEventDuration ) ) ;
652659 }
653660
661+ if self . event_duration . is_positive ( ) {
662+ range. end = range. end . checked_sub ( self . event_duration ) ?;
663+ }
664+
665+ if range. start >= range. end {
666+ return Err ( Error :: from ( ErrorKind :: InvalidBounds ) ) ;
667+ }
668+
654669 Ok ( Series {
655670 pattern : self . pattern ,
656671 range,
0 commit comments