Leosac  0.8.0
Open Source Access Control
SingleTimeFrame.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
21 #include <tuple>
22 
23 namespace Leosac
24 {
25 namespace Tools
26 {
27 
28 SingleTimeFrame::SingleTimeFrame(int d, int sh, int sm, int eh, int em)
29  : day(d)
30  , start_hour(sh)
31  , start_min(sm)
32  , end_hour(eh)
33  , end_min(em)
34 {
35 }
36 
38  : day(0)
39  , start_hour(0)
40  , start_min(0)
41  , end_hour(0)
42  , end_min(0)
43 {
44 }
45 
47  const std::chrono::system_clock::time_point &tp) const
48 {
49  std::time_t time_temp = std::chrono::system_clock::to_time_t(tp);
50  std::tm const *time_out = std::localtime(&time_temp);
51 
52  if (this->day != time_out->tm_wday)
53  return false;
54  if (!(this->start_hour < time_out->tm_hour ||
55  (this->start_hour == time_out->tm_hour &&
56  this->start_min <= time_out->tm_min)))
57  return false;
58  if (!(this->end_hour > time_out->tm_hour ||
59  (this->end_hour == time_out->tm_hour &&
60  this->end_min >= time_out->tm_min)))
61  return false;
62  return true;
63 }
64 
66 {
67  return day == o.day && start_hour == o.start_hour && start_min == o.start_min &&
68  end_hour == o.end_hour && end_min == o.end_min;
69 }
70 
72 {
73  return std::make_tuple(day, start_hour, start_min, end_hour, end_min) <
74  std::make_tuple(o.day, o.start_hour, o.start_min, o.end_hour, o.end_min);
75 }
76 }
77 }
Leosac::Tools::SingleTimeFrame::SingleTimeFrame
SingleTimeFrame()
Definition: SingleTimeFrame.cpp:37
Leosac::Tools::SingleTimeFrame::operator==
bool operator==(const SingleTimeFrame &o) const
Definition: SingleTimeFrame.cpp:65
Leosac::Tools::SingleTimeFrame::operator<
bool operator<(const SingleTimeFrame &o) const
Definition: SingleTimeFrame.cpp:71
Leosac::Tools::SingleTimeFrame::day
int day
Definition: SingleTimeFrame.hpp:59
Leosac
This is the header file for a generated source file, GitSHA1.cpp.
Definition: APIStatusCode.hpp:22
Leosac::Tools::SingleTimeFrame::is_in_timeframe
bool is_in_timeframe(const std::chrono::system_clock::time_point &tp) const
Is the given timepoint in the time frame ?
Definition: SingleTimeFrame.cpp:46
Leosac::Tools::SingleTimeFrame::end_hour
int end_hour
Definition: SingleTimeFrame.hpp:62
Leosac::Tools::SingleTimeFrame::start_min
int start_min
Definition: SingleTimeFrame.hpp:61
Leosac::Tools::SingleTimeFrame
This struct abstracts what we call a single time frame.
Definition: SingleTimeFrame.hpp:38
Leosac::Tools::SingleTimeFrame::end_min
int end_min
Definition: SingleTimeFrame.hpp:63
Leosac::Tools::SingleTimeFrame::start_hour
int start_hour
Definition: SingleTimeFrame.hpp:60
SingleTimeFrame.hpp