prost_validate/errors/
timestamp.rs1use thiserror::Error;
2
3#[derive(Debug, Clone, Error)]
4pub enum Error {
5 #[error("must be equal to {0:?}")]
6 Const(time::OffsetDateTime),
7 #[error("must be less than {0:?}")]
8 Lt(time::OffsetDateTime),
9 #[error("must be less than or equal to {0:?}")]
10 Lte(time::OffsetDateTime),
11 #[error("must be greater than {0:?}")]
12 Gt(time::OffsetDateTime),
13 #[error("must be greater than or equal to {0:?}")]
14 Gte(time::OffsetDateTime),
15 #[error("must be in range {0}{1:?}, {2:?}{3}")]
16 InRange(String, time::OffsetDateTime, time::OffsetDateTime, String),
17 #[error("must not be in range {0}{1:?}, {2:?}{3}")]
18 NotInRange(String, time::OffsetDateTime, time::OffsetDateTime, String),
19 #[error("must less than current time")]
20 LtNow,
21 #[error("must be less than now or within {0} from now")]
22 LtNowWithin(time::Duration),
23 #[error("must be greater than current time")]
24 GtNow,
25 #[error("must be greater than now or within {0} from now")]
26 GtNowWithin(time::Duration),
27 #[error("must be within {0:?} from current time")]
28 Within(time::Duration),
29}
30
31impl Error {
32 pub fn in_range(
33 start_inclusive: bool,
34 start: time::OffsetDateTime,
35 end: time::OffsetDateTime,
36 end_inclusive: bool,
37 ) -> Self {
38 Self::InRange(
39 if start_inclusive { "[" } else { "(" }.to_string(),
40 start,
41 end,
42 if end_inclusive { "]" } else { ")" }.to_string(),
43 )
44 }
45 pub fn not_in_range(
46 start_inclusive: bool,
47 start: time::OffsetDateTime,
48 end: time::OffsetDateTime,
49 end_inclusive: bool,
50 ) -> Self {
51 Self::NotInRange(
52 if start_inclusive { "[" } else { "(" }.to_string(),
53 start,
54 end,
55 if end_inclusive { "]" } else { ")" }.to_string(),
56 )
57 }
58}
59
60impl From<Error> for super::Error {
61 fn from(value: Error) -> Self {
62 Self::Timestamp(value)
63 }
64}