herald  2.0.0
date.h
1 // Copyright 2020-2021 Herald Project Contributors
2 // SPDX-License-Identifier: Apache-2.0
3 //
4 
5 #ifndef HERALD_DATE_H
6 #define HERALD_DATE_H
7 
8 #include <string>
9 #include <memory>
10 
11 namespace herald {
12 namespace datatype {
13 
14 class TimeInterval; // fwd decl
15 
16 // Basic date representation. Uses epoch seconds since Jan 1st 1970. Subclasses
17 // can use different mechanisms if they wish
18 class Date {
19 public:
20  Date(); // now
21  Date(std::uint64_t secondsSinceEpochOrRestart);
22  Date(const Date& from);
23  Date(Date&& from);
24  ~Date();
25 
26  Date& operator=(const Date& other) noexcept;
27  Date& operator=(Date&& other) noexcept;
28 
30  void setToNow() noexcept;
31 
32  std::string iso8601DateTime() const noexcept;
33  operator std::string() const noexcept;
34  std::uint64_t secondsSinceUnixEpoch() const noexcept;
35 
36  bool operator==(const Date& other) const noexcept;
37  bool operator!=(const Date& other) const noexcept;
38  bool operator<(const Date& other) const noexcept;
39  bool operator>(const Date& other) const noexcept;
40  bool operator<=(const Date& other) const noexcept;
41  bool operator>=(const Date& other) const noexcept;
42 
43  Date operator-(const TimeInterval& other) noexcept;
44  Date& operator-=(const TimeInterval& other) noexcept;
45  Date operator+(const TimeInterval& other) noexcept;
46  Date& operator+=(const TimeInterval& other) noexcept;
47 
48  operator long() const noexcept;
49 
50 private:
51  std::uint64_t seconds;
52 };
53 
54 } // end namespace
55 } // end namespace
56 
57 #endif
Definition: date.h:18
void setToNow() noexcept
Sets the value to now without any temporaries being created/destroyed.
Definition: time_interval.h:19
Acts as a non-global memory arena for arbitrary classes.
Definition: aggregates.h:15
Definition: data.h:562