summaryrefslogtreecommitdiff
path: root/libimagentrydatetime/src/datepath/accuracy.rs
blob: 47299c148c428f90f13ff279b369cfe2106d01da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
//
// imag - the personal information management suite for the commandline
// Copyright (C) 2015, 2016 Matthias Beyer <mail@beyermatthias.de> and contributors
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; version
// 2.1 of the License.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
//

/// The accuracy with which the compiler should compile the time specification
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
pub enum Accuracy {
    Year,
    Month,
    Day,
    Hour,
    Minute,
    Second
}

impl Accuracy {

    /// Check whether the current setting includes a year.
    pub fn has_year_accuracy(&self) -> bool {
        match *self {
            Accuracy::Year   => true,
            Accuracy::Month  => true,
            Accuracy::Day    => true,
            Accuracy::Hour   => true,
            Accuracy::Minute => true,
            Accuracy::Second => true,
        }
    }

    /// Check whether the current setting includes a month.
    pub fn has_month_accuracy(&self) -> bool {
        match *self {
            Accuracy::Year   => false,
            Accuracy::Month  => true,
            Accuracy::Day    => true,
            Accuracy::Hour   => true,
            Accuracy::Minute => true,
            Accuracy::Second => true,
        }
    }

    /// Check whether the current setting includes a day.
    pub fn has_day_accuracy(&self) -> bool {
        match *self {
            Accuracy::Year   => false,
            Accuracy::Month  => false,
            Accuracy::Day    => true,
            Accuracy::Hour   => true,
            Accuracy::Minute => true,
            Accuracy::Second => true,
        }
    }

    /// Check whether the current setting includes a hour.
    pub fn has_hour_accuracy(&self) -> bool {
        match *self {
            Accuracy::Year   => false,
            Accuracy::Month  => false,
            Accuracy::Day    => false,
            Accuracy::Hour   => true,
            Accuracy::Minute => true,
            Accuracy::Second => true,
        }
    }

    /// Check whether the current setting includes a minute.
    pub fn has_minute_accuracy(&self) -> bool {
        match *self {
            Accuracy::Year   => false,
            Accuracy::Month  => false,
            Accuracy::Day    => false,
            Accuracy::Hour   => false,
            Accuracy::Minute => true,
            Accuracy::Second => true,
        }
    }

    /// Check whether the current setting includes a second.
    pub fn has_second_accuracy(&self) -> bool {
        match *self {
            Accuracy::Year   => false,
            Accuracy::Month  => false,
            Accuracy::Day    => false,
            Accuracy::Hour   => false,
            Accuracy::Minute => false,
            Accuracy::Second => true,
        }
    }

}

impl Default for Accuracy {
    fn default() -> Accuracy {
        Accuracy::Second
    }
}