pub fn truncate_low_fields(
        &mut self,
        f: DateTimeField,
        fsec_max_precision: Option<u64>,
    ) -> Result<(), anyhow::Error> {
        use DateTimeField::*;
        match f {
            Year => {
                self.months -= self.months % 12;
                self.duration = 0;
            }
            Month => {
                self.duration = 0;
            }
            // Round nanoseconds.
            Second => {
                let default_precision = 6;
                let precision = match fsec_max_precision {
                    Some(p) => p,
                    None => default_precision,
                };

                if precision > default_precision {
                    bail!(
                        "SECOND precision must be (0, 6), have SECOND({})",
                        precision
                    )
                }

                // Check if value should round up to nearest fractional place.
                let remainder = self.duration % 10_i128.pow(9 - precision as u32);
                if remainder / 10_i128.pow(8 - precision as u32) > 4 {
                    self.duration += 10_i128.pow(9 - precision as u32);
                }

                self.duration -= remainder;
            }
            Day | Hour | Minute => {
                self.duration -= self.duration % f.nanos_multiplier() as i128;
            }
            Millennium | Century | Decade | Milliseconds | Microseconds => {
                unreachable!(format!("Cannot truncate interval by {}", f))
            }
        }
        Ok(())
    }
/// Truncate the "tail" of the interval, removing all time units less than `f`.
/// # Arguments
/// - `f`: Round the interval down to the specified time unit.
/// - `fsec_max_precision`: If `Some(x)`, keep only `x` places of nanosecond precision.
///    Must be `(0,6)`.
///
/// # Errors
/// - If `fsec_max_precision` is not None or within (0,6).
Truncate the "tail" of the interval, removing all time units less than `f`.
Truncate the " tail " of the interval removing all time units less than ` f ` .
pub fn truncate_low_fields(
        &mut self,
        f: DateTimeField,
        fsec_max_precision: Option<u64>,
    ) -> Result<(), anyhow::Error> {
        use DateTimeField::*;
        match f {
            Year => {
                self.months -= self.months % 12;
                self.duration = 0;
            }
            Month => {
                self.duration = 0;
            }
            // Round nanoseconds.
            Second => {
                let default_precision = 6;
                let precision = match fsec_max_precision {
                    Some(p) => p,
                    None => default_precision,
                };
                if precision > default_precision {
                    bail!(
                        "SECOND precision must be (0, 6), have SECOND({})",
                        precision
                    )
                }
                // Check if value should round up to nearest fractional place.
                let remainder = self.duration % 10_i128.pow(9 - precision as u32);
                if remainder / 10_i128.pow(8 - precision as u32) > 4 {
                    self.duration += 10_i128.pow(9 - precision as u32);
                }
                self.duration -= remainder;
            }
            Day | Hour | Minute => {
                self.duration -= self.duration % f.nanos_multiplier() as i128;
            }
            Millennium | Century | Decade | Milliseconds | Microseconds => {
                unreachable!(format!("Cannot truncate interval by {}", f))
            }
        }
        Ok(())
    }
pub fn truncate_low_fields ( & mut self , f : DateTimeField , fsec_max_precision : Option < u64 > , ) -> Result < ( ) , anyhow :: Error > { use DateTimeField :: * ; match f { Year => { self . months -= self . months % 12 ; self . duration = 0 ; } Month => { self . duration = 0 ; } // Round nanoseconds. Second => { let default_precision = 6 ; let precision = match fsec_max_precision { Some ( p ) => p , None => default_precision , } ; if precision > default_precision { bail ! ( " " precision ) } // Check if value should round up to nearest fractional place. let remainder = self . duration % 10_i128 . pow ( 9 - precision as u32 ) ; if remainder / 10_i128 . pow ( 8 - precision as u32 ) > 4 { self . duration += 10_i128 . pow ( 9 - precision as u32 ) ; } self . duration -= remainder ; } Day | Hour | Minute => { self . duration -= self . duration % f . nanos_multiplier ( ) as i128 ; } Millennium | Century | Decade | Milliseconds | Microseconds => { unreachable ! ( format ( " " f ) ) } } Ok ( ( ) ) }
Truncate the "tail" of the interval, removing all time units less than `f`.
Truncate the " tail " of the interval removing all time units less than ` f ` .
&mut self
f
DateTimeField
Round the interval down to the specified time unit.
Round the interval down to the specified time unit .
fsec_max_precision
Option<u64>
If `Some(x)`, keep only `x` places of nanosecond precision.
If ` Some ( x ) ` keep only ` x ` places of nanosecond precision .
errors
If `fsec_max_precision` is not None or within (0,6).
If ` fsec_max_precision ` is not None or within ( 0 6 ) .