DLS  1.6
Time.h
1 /******************************************************************************
2  *
3  * This file is part of the Data Logging Service (DLS).
4  *
5  * DLS is free software: you can redistribute it and/or modify it under the
6  * terms of the GNU General Public License as published by the Free Software
7  * Foundation, either version 3 of the License, or (at your option) any later
8  * version.
9  *
10  * DLS is distributed in the hope that it will be useful, but WITHOUT ANY
11  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13  * details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with DLS. If not, see <http://www.gnu.org/licenses/>.
17  *
18  *****************************************************************************/
19 
20 #ifndef LibDLSTimeH
21 #define LibDLSTimeH
22 
23 /*****************************************************************************/
24 
25 #include <sys/time.h>
26 #include <stdint.h>
27 
28 #include <chrono>
29 #include <ostream>
30 
31 #include "globals.h"
32 
33 /*****************************************************************************/
34 
35 namespace LibDLS {
36 
37 /*****************************************************************************/
38 
47 {
48  friend std::ostream &operator <<(std::ostream &, const Time &);
49 
50  public:
51  Time();
52  Time(int64_t);
53  Time(uint64_t);
54  Time(double);
55  Time(struct timeval *);
56  Time(struct tm *, unsigned int);
57 
58  template <typename T, typename Period>
59  Time(std::chrono::duration<T, Period> t)
60  : Time(std::chrono::duration_cast<std::chrono::microseconds>(t).count())
61  {}
62 
63  void from_dbl_time(double);
64  void set_null();
65  void set_now();
66  int set_date(int, int = 1, int = 1, int = 0, int = 0, int = 0);
67 
68  Time &operator =(int64_t);
69  Time &operator =(uint64_t);
70  Time &operator =(double);
71  Time &operator =(struct timeval);
72 
73  bool operator ==(const Time &) const;
74  bool operator !=(const Time &) const;
75  bool operator <(const Time &) const;
76  bool operator >(const Time &) const;
77  bool operator <=(const Time &) const;
78  bool operator >=(const Time &) const;
79  bool is_null() const;
80 
81  Time operator +(const Time &) const;
82  Time &operator +=(const Time &);
83  Time operator -(const Time &) const;
84  Time operator *(int64_t) const;
85 
86  double to_dbl() const;
87  double to_dbl_time() const;
88  int64_t to_int64() const;
89  uint64_t to_uint64() const;
90  time_t to_time_t() const;
91  std::string to_str() const;
92  struct timeval to_tv() const;
93  std::string to_real_time() const;
94  std::string format_time(const char *) const;
95  std::string to_rfc811_time() const;
96  std::string to_iso_time() const;
97  std::string diff_str_to(const Time &) const;
98  int year() const;
99  int month() const;
100  int day() const;
101  int hour() const;
102  int min() const;
103  int sec() const;
104  int day_of_week() const;
105  bool is_leap_year() const;
106  int month_days() const;
107 
108  static Time now();
109 
110  private:
111  int64_t _time;
112 };
113 
114 /*****************************************************************************/
115 
116 std::ostream &operator <<(std::ostream &, const Time &);
117 
118 /*****************************************************************************/
119 
120 } // namespace
121 
122 /*****************************************************************************/
123 
124 #endif
Global data structures and functions.
Definition: Channel.h:44
Datentyp zur Speicherung der Zeit in Mikrosekunden.
Definition: Time.h:46
#define DLS_PUBLIC
Macro for public method definitions (empty on non-win32).
Definition: globals.h:57