pub fn index(&self, mut idx: i32) -> Option<DateRange> {
        let len = i32::try_from(self.len).ok()?;
        if idx >= len || idx < -len {
            return None;
        }
        if idx < 0 {
            idx += len;
        }
        let dur1: Duration;
        let dur2: Duration;
        match self.periodicity {
            Period::Day => {
                dur1 = Duration::new(idx, 0, 0);
                dur2 = Duration::new(1, 0, 0);
            }
            Period::Week => {
                dur1 = Duration::new(7 * idx, 0, 0);
                dur2 = Duration::new(7, 0, 0);
            }
            Period::Month => {
                dur1 = Duration::new(0, idx, 0);
                dur2 = Duration::new(0, 1, 0);
            }
            Period::Quarter => {
                dur1 = Duration::new(0, 3 * idx, 0);
                dur2 = Duration::new(0, 3, 0);
            }
            Period::Year => {
                dur1 = Duration::new(0, 0, idx);
                dur2 = Duration::new(0, 0, 1);
            }
        };
        let start = (self.range.from + dur1).ok()?.primary();
        let mut end = (start + dur2).ok()?.primary();
        end = cmp::min(end, self.range.to);
        Some(DateRange::new(start, end))
    }
/// Return the date range that represents a single period at the index.
/// Period is defined by the periodicity of the Timeline,
/// so a monthly timeline would return a month date range
Return the date range that represents a single period at the index.
Period is defined by the periodicity of the Timeline,
so a monthly timeline would return a month date range
Return the date range that represents a single period at the index . Period is defined by the periodicity of the Timeline so a monthly timeline would return a month date range
pub fn index(&self, mut idx: i32) -> Option<DateRange> {
        let len = i32::try_from(self.len).ok()?;
        if idx >= len || idx < -len {
            return None;
        }
        if idx < 0 {
            idx += len;
        }
        let dur1: Duration;
        let dur2: Duration;
        match self.periodicity {
            Period::Day => {
                dur1 = Duration::new(idx, 0, 0);
                dur2 = Duration::new(1, 0, 0);
            }
            Period::Week => {
                dur1 = Duration::new(7 * idx, 0, 0);
                dur2 = Duration::new(7, 0, 0);
            }
            Period::Month => {
                dur1 = Duration::new(0, idx, 0);
                dur2 = Duration::new(0, 1, 0);
            }
            Period::Quarter => {
                dur1 = Duration::new(0, 3 * idx, 0);
                dur2 = Duration::new(0, 3, 0);
            }
            Period::Year => {
                dur1 = Duration::new(0, 0, idx);
                dur2 = Duration::new(0, 0, 1);
            }
        };
        let start = (self.range.from + dur1).ok()?.primary();
        let mut end = (start + dur2).ok()?.primary();
        end = cmp::min(end, self.range.to);
        Some(DateRange::new(start, end))
    }
pub fn index ( & self , mut idx : i32 ) -> Option < DateRange > { let len = i32 :: try_from ( self . len ) . ok ( ) ? ; if idx >= len || idx < - len { return None ; } if idx < 0 { idx += len ; } let dur1 : Duration ; let dur2 : Duration ; match self . periodicity { Period :: Day => { dur1 = Duration :: new ( idx , 0 , 0 ) ; dur2 = Duration :: new ( 1 , 0 , 0 ) ; } Period :: Week => { dur1 = Duration :: new ( 7 * idx , 0 , 0 ) ; dur2 = Duration :: new ( 7 , 0 , 0 ) ; } Period :: Month => { dur1 = Duration :: new ( 0 , idx , 0 ) ; dur2 = Duration :: new ( 0 , 1 , 0 ) ; } Period :: Quarter => { dur1 = Duration :: new ( 0 , 3 * idx , 0 ) ; dur2 = Duration :: new ( 0 , 3 , 0 ) ; } Period :: Year => { dur1 = Duration :: new ( 0 , 0 , idx ) ; dur2 = Duration :: new ( 0 , 0 , 1 ) ; } } ; let start = ( self . range . from + dur1 ) . ok ( ) ? . primary ( ) ; let mut end = ( start + dur2 ) . ok ( ) ? . primary ( ) ; end = cmp :: min ( end , self . range . to ) ; Some ( DateRange :: new ( start , end ) ) }
Return the date range that represents a single period at the index.
Return the date range that represents a single period at the index .
&self
idx
i32
&self
idx
i32