fn with_start(&self, start: DateTime<Utc>) -> UnnamedTimeSegment {
        let shift = |datetime: DateTime<Utc>| -> DateTime<Utc> {
            let diff_ns = (datetime - start)
                .num_nanoseconds()
                .expect("300 years is a long time");
            let period_ns = self
                .period()
                .num_nanoseconds()
                .expect("300 years is a long time");
            let quotient = if diff_ns < 0 {
                diff_ns / period_ns - 1
            } else {
                diff_ns / period_ns
            };
            datetime - Duration::nanoseconds(quotient * period_ns)
        };
        let ranges = self
            .ranges()
            .iter()
            .map(|range| {
                let start = shift(range.start);
                let end = start + (range.end - range.start);
                start..end
            })
            .sorted_by_key(|range| range.start)
            .flat_map(|range| {
                if range.end <= start + self.period() {
                    vec![range]
                } else {
                    vec![
                        range.start..start + self.period(),
                        start..range.end - self.period(),
                    ]
                }
            })
            .sorted_by_key(|range| range.start)
            .collect();
        UnnamedTimeSegment {
            ranges,
            start,
            period: self.period(),
        }
    }
/// Returns a new time segment with its start and ranges shifted towards the
/// given start time.
Returns a new time segment with its start and ranges shifted towards the
given start time.
Returns a new time segment with its start and ranges shifted towards the given start time .
fn with_start(&self, start: DateTime<Utc>) -> UnnamedTimeSegment {
        let shift = |datetime: DateTime<Utc>| -> DateTime<Utc> {
            let diff_ns = (datetime - start)
                .num_nanoseconds()
                .expect("300 years is a long time");
            let period_ns = self
                .period()
                .num_nanoseconds()
                .expect("300 years is a long time");
            let quotient = if diff_ns < 0 {
                diff_ns / period_ns - 1
            } else {
                diff_ns / period_ns
            };
            datetime - Duration::nanoseconds(quotient * period_ns)
        };
        let ranges = self
            .ranges()
            .iter()
            .map(|range| {
                let start = shift(range.start);
                let end = start + (range.end - range.start);
                start..end
            })
            .sorted_by_key(|range| range.start)
            .flat_map(|range| {
                if range.end <= start + self.period() {
                    vec![range]
                } else {
                    vec![
                        range.start..start + self.period(),
                        start..range.end - self.period(),
                    ]
                }
            })
            .sorted_by_key(|range| range.start)
            .collect();
        UnnamedTimeSegment {
            ranges,
            start,
            period: self.period(),
        }
    }
fn with_start ( & self , start : DateTime < Utc > ) -> UnnamedTimeSegment { let shift = | datetime : DateTime < Utc > | -> DateTime < Utc > { let diff_ns = ( datetime - start ) . num_nanoseconds ( ) . expect ( " " ) ; let period_ns = self . period ( ) . num_nanoseconds ( ) . expect ( " " ) ; let quotient = if diff_ns < 0 { diff_ns / period_ns - 1 } else { diff_ns / period_ns } ; datetime - Duration :: nanoseconds ( quotient * period_ns ) } ; let ranges = self . ranges ( ) . iter ( ) . map ( | range | { let start = shift ( range . start ) ; let end = start + ( range . end - range . start ) ; start .. end } ) . sorted_by_key ( | range | range . start ) . flat_map ( | range | { if range . end <= start + self . period ( ) { vec ! [ range ] } else { vec ! [ range start start self period ( ) start range end self period ( ) ] } } ) . sorted_by_key ( | range | range . start ) . collect ( ) ; UnnamedTimeSegment { ranges , start , period : self . period ( ) , } }
Returns a new time segment with its start and ranges shifted towards the
given start time.
Returns a new time segment with its start and ranges shifted towards the given start time .
&self
start
DateTime<Utc>
&self
start
DateTime<Utc>