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;
            }
            dhm => {
                self.duration -= self.duration % dhm.nanos_multiplier() as i128;
            }
        }
        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;
            }
            dhm => {
                self.duration -= self.duration % dhm.nanos_multiplier() as i128;
            }
        }
        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 ; } dhm => { self . duration -= self . duration % dhm . nanos_multiplier ( ) as i128 ; } } 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
fsec_max_precision
Option<u64>
&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 ) .