Skip to main content

nodedb_types/datetime/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! Error type for datetime and duration construction and arithmetic.
4
5/// Error type for datetime and duration construction and arithmetic.
6#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
7pub enum NdbDateTimeError {
8    /// A multiplication would overflow `i64`.
9    #[error("datetime overflow: input {input} {unit} overflows i64 microseconds")]
10    Overflow { input: i64, unit: &'static str },
11
12    /// Addition of two datetime/duration values would overflow `i64`.
13    #[error("datetime overflow: addition overflows i64 microseconds")]
14    AddOverflow,
15
16    /// Subtraction of two datetime/duration values would overflow `i64`.
17    #[error("datetime overflow: subtraction overflows i64 microseconds")]
18    SubOverflow,
19}
20
21impl From<NdbDateTimeError> for crate::error::NodeDbError {
22    fn from(e: NdbDateTimeError) -> Self {
23        crate::error::NodeDbError::plan_error_at("datetime", e.to_string())
24    }
25}