Skip to main content

postgresql/
interval.rs

1//! PostgreSQL `interval`.
2
3/// A PostgreSQL `interval`: an exact count of months and days plus a
4/// microsecond time component.
5///
6/// Months and days are kept separate because their length depends on the
7/// calendar (a month may be 28–31 days) and they cannot be collapsed into a
8/// single duration losslessly.
9#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Hash)]
10pub struct Interval {
11    /// Number of months.
12    pub months: i32,
13    /// Number of days.
14    pub days: i32,
15    /// Number of microseconds.
16    pub micros: i64,
17}
18
19impl Interval {
20    /// Creates an interval from its components.
21    pub const fn new(months: i32, days: i32, micros: i64) -> Self {
22        Interval {
23            months,
24            days,
25            micros,
26        }
27    }
28}