AnCH Framework 0.1
Another C++ Hack Framework
Loading...
Searching...
No Matches
date.hpp
1/*
2 ANCH Framework: ANother C++ Hack is a C++ framework based on C++11 standard
3 Copyright (C) 2012 Vincent Lachenal
4
5 This file is part of ANCH Framework.
6
7 ANCH Framework is free software: you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11
12 ANCH Framework is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public License
18 along with ANCH Framework. If not, see <http://www.gnu.org/licenses/>.
19*/
20#pragma once
21
22#include <memory>
23#include <mutex>
24#include <chrono>
25#include <ctime>
26
27
28namespace anch::date {
29
30 class DateFormatter;
32
43 class Date {
44
45 friend class IDatePartFormatter;
46 friend class DateFormatter;
47
48 // Attributes +
49 protected:
51 static std::mutex _mutex;
52
54 std::int64_t _timestamp;
55
57 int32_t _years = 0;
58
60 uint16_t _months = 0;
61
63 uint16_t _ydays = 0;
64
66 uint16_t _mdays = 0;
67
69 uint16_t _wdays = 0;
70
72 uint16_t _hours = 0;
73
75 uint16_t _minutes = 0;
76
78 uint16_t _seconds = 0;
79
81 uint16_t _milliseconds = 0;
82
84 uint16_t _microseconds = 0;
85
87 uint16_t _nanoseconds = 0;
88 // Attributes -
89
90 // Constructors +
91 public:
97 Date(bool init = true);
98
104 Date(const std::time_t& time);
105
111 Date(const std::tm* const time);
112
118 Date(const std::timespec& time);
119 // Constructors -
120
121 // Destructor +
122 public:
126 virtual ~Date();
127 // Destructor -
128
129 // Methods +
130 private:
136 template<typename R, typename P>
137 void initialize(const std::chrono::duration<R,P>& duration) noexcept;
138
144 void initialize(const std::tm* const time);
145
149 void computeTimestamp();
150
154 void computeTm(std::tm& time) const;
155
156 public:
164 bool after(const Date& date) const noexcept;
165
173 bool before(const Date& date) const noexcept;
174
182 bool equals(const Date& date) const noexcept;
183 // Methods -
184
185 // Operators +
186 public:
193 bool operator > (const Date& date) const noexcept;
194
201 bool operator >= (const Date& date) const noexcept;
202
209 bool operator < (const Date& date) const noexcept;
210
217 bool operator <= (const Date& date) const noexcept;
218
225 bool operator == (const Date& date) const noexcept;
226
233 bool operator != (const Date& date) const noexcept;
234
240 operator std::time_t() const noexcept;
241
247 operator std::tm() const noexcept;
248
254 operator std::timespec() const noexcept;
255 // Operators -
256
257 };
258
259} // anch::date
260
261#include "date/impl/date.hpp"
Definition dateFormatter.hpp:56
operator std::tm() const noexcept
bool equals(const Date &date) const noexcept
bool operator>(const Date &date) const noexcept
uint16_t _mdays
Definition date.hpp:66
Date(const std::time_t &time)
Date(const std::tm *const time)
int32_t _years
Definition date.hpp:57
bool operator!=(const Date &date) const noexcept
uint16_t _nanoseconds
Definition date.hpp:87
bool before(const Date &date) const noexcept
bool operator>=(const Date &date) const noexcept
uint16_t _ydays
Definition date.hpp:63
std::int64_t _timestamp
Definition date.hpp:54
Date(bool init=true)
uint16_t _minutes
Definition date.hpp:75
uint16_t _seconds
Definition date.hpp:78
uint16_t _microseconds
Definition date.hpp:84
bool operator==(const Date &date) const noexcept
uint16_t _months
Definition date.hpp:60
uint16_t _wdays
Definition date.hpp:69
bool operator<(const Date &date) const noexcept
bool after(const Date &date) const noexcept
bool operator<=(const Date &date) const noexcept
uint16_t _milliseconds
Definition date.hpp:81
uint16_t _hours
Definition date.hpp:72
static std::mutex _mutex
Definition date.hpp:51
Date(const std::timespec &time)
operator std::timespec() const noexcept
Definition iDatePartFormatter.hpp:35
Date namespace.