DateTime.cpp
Go to the documentation of this file.
1 #include "DateTime.h"
2 
3 #include <limits>
4 
5 #include <IceUtil/Time.h>
6 
8 
9 #include "ice_conversions.h"
10 
11 
12 namespace armarx::core::time
13 {
14 
16 
17 
18  DateTime::DateTime() : _timeSinceEpoch{}, _clockType{ClockType::Unknown}, _hostname{"unknown"}
19  {
20  ;
21  }
22 
23 
24  DateTime::DateTime(Duration timeSinceEpoch, ClockType clock, const std::string& hostname) :
25  _timeSinceEpoch{timeSinceEpoch}, _clockType{clock}, _hostname{hostname}
26  {
27  ;
28  }
29 
30 
31  DateTime::DateTime(std::int64_t microSecondsSinceEpoch,
32  ClockType clock,
33  const std::string& hostname) :
34  _timeSinceEpoch{Duration::MicroSeconds(microSecondsSinceEpoch)},
35  _clockType{clock},
36  _hostname{hostname}
37  {
38  ;
39  }
40 
42  {
43  fromIce(ice, *this);
44  }
45 
46  DateTime::operator IceUtil::Time() const
47  {
48  IceUtil::Time ice;
49  toIce(ice, *this);
50  return ice;
51  }
52 
53 
54  DateTime
56  {
57  return Clock::Now();
58  }
59 
61  {
63  }
64 
65 
66  std::string
68  {
69  return toString("%Y-%m-%d");
70  }
71 
72 
73  std::string
75  {
76  return toString("%H-%M-%S.%%usec");
77  }
78 
79 
80  std::string
82  {
83  return toDateString() + "_" + toTimeString();
84  }
85 
86 
87  std::string
88  DateTime::toString(const std::string& format) const
89  {
90  return _timeSinceEpoch.toDurationString(format);
91  }
92 
93 
94  std::int64_t
96  {
98  }
99 
100 
101  std::int64_t
103  {
105  }
106 
107 
108  std::int64_t
110  {
111  return _timeSinceEpoch.toSeconds();
112  }
113 
114 
115  Duration
117  {
118  return _timeSinceEpoch;
119  }
120 
121 
122  ClockType
124  {
125  return _clockType;
126  }
127 
128 
129  std::string
131  {
132  return _hostname;
133  }
134 
135  bool DateTime::isValid() const
136  {
138  }
139 
140  bool DateTime::isInvalid() const
141  {
142  return not isValid();
143  }
144 
145 
146  DateTime
147  DateTime::operator+(const Duration& rhs) const
148  {
150  }
151 
152 
153  DateTime&
155  {
156  _timeSinceEpoch += rhs;
157  return *this;
158  }
159 
160 
161  DateTime
162  DateTime::operator-(const Duration& rhs) const
163  {
165  }
166 
167 
168  DateTime&
170  {
171  _timeSinceEpoch -= rhs;
172  return *this;
173  }
174 
175 
176  Duration
177  DateTime::operator-(const DateTime& rhs) const
178  {
179  return _timeSinceEpoch - rhs.toDurationSinceEpoch();
180  }
181 
182 
183  bool
184  DateTime::operator<(const DateTime& rhs) const
185  {
186  return _timeSinceEpoch < rhs.toDurationSinceEpoch();
187  }
188 
189 
190  bool
191  DateTime::operator<=(const DateTime& rhs) const
192  {
193  return _timeSinceEpoch <= rhs.toDurationSinceEpoch();
194  }
195 
196 
197  bool
198  DateTime::operator==(const DateTime& rhs) const
199  {
200  return _timeSinceEpoch == rhs.toDurationSinceEpoch();
201  }
202 
203 
204  bool
205  DateTime::operator>(const DateTime& rhs) const
206  {
207  return _timeSinceEpoch > rhs.toDurationSinceEpoch();
208  }
209 
210 
211  bool
212  DateTime::operator>=(const DateTime& rhs) const
213  {
214  return _timeSinceEpoch >= rhs.toDurationSinceEpoch();
215  }
216 
217 
218  bool
219  DateTime::operator!=(const DateTime& rhs) const
220  {
221  return _timeSinceEpoch != rhs.toDurationSinceEpoch();
222  }
223 
224 
225  std::ostream&
226  operator<<(std::ostream& out, const DateTime& rhs)
227  {
228  out << rhs.toDateTimeString();
229  return out;
230  }
231 
232 } // namespace armarx::core::time
armarx::core::time::DateTime::isValid
bool isValid() const
Definition: DateTime.cpp:135
armarx::core::time::DateTime::operator<
bool operator<(const DateTime &rhs) const
Definition: DateTime.cpp:184
armarx::core::time::DateTime::isInvalid
bool isInvalid() const
Definition: DateTime.cpp:140
armarx::core::time::DateTime::toDateString
std::string toDateString() const
Definition: DateTime.cpp:67
armarx::core::time::fromIce
void fromIce(const dto::ClockType::ClockTypeEnum &dto, ClockType &bo)
Definition: ice_conversions.cpp:12
armarx::core::time::DateTime::toDurationSinceEpoch
Duration toDurationSinceEpoch() const
Definition: DateTime.cpp:116
armarx::core::time::DateTime::Now
static DateTime Now()
Definition: DateTime.cpp:55
armarx::core::time::DateTime::clockType
ClockType clockType() const
Definition: DateTime.cpp:123
DateTime.h
armarx::core::time::toIce
void toIce(dto::ClockType::ClockTypeEnum &dto, const ClockType &bo)
Definition: ice_conversions.cpp:33
armarx::core::time::DateTime::operator==
bool operator==(const DateTime &rhs) const
Definition: DateTime.cpp:198
armarx::core::time
Definition: Clock.cpp:13
armarx::core::time::DateTime::toSecondsSinceEpoch
std::int64_t toSecondsSinceEpoch() const
Definition: DateTime.cpp:109
armarx::core::time::DateTime::operator+
DateTime operator+(const Duration &rhs) const
Definition: DateTime.cpp:147
ice_conversions.h
armarx::core::time::operator<<
std::ostream & operator<<(std::ostream &out, const DateTime &rhs)
Definition: DateTime.cpp:226
armarx::core::time::DateTime::operator-=
DateTime & operator-=(const Duration &rhs)
Definition: DateTime.cpp:169
armarx::core::time::DateTime::DateTime
DateTime()
Definition: DateTime.cpp:18
Clock.h
armarx::core::time::DateTime::operator>=
bool operator>=(const DateTime &rhs) const
Definition: DateTime.cpp:212
armarx::core::time::DateTime::operator<=
bool operator<=(const DateTime &rhs) const
Definition: DateTime.cpp:191
armarx::core::time::ClockType
ClockType
Describes the type of clock.
Definition: ClockType.h:10
armarx::core::time::DateTime::_hostname
std::string _hostname
Definition: DateTime.h:134
armarx::core::time::ClockType::Unknown
@ Unknown
Unknown source of time.
armarx::core::time::DateTime::_timeSinceEpoch
Duration _timeSinceEpoch
Definition: DateTime.h:130
armarx::core::time::DateTime::operator>
bool operator>(const DateTime &rhs) const
Definition: DateTime.cpp:205
armarx::core::time::DateTime::toMicroSecondsSinceEpoch
std::int64_t toMicroSecondsSinceEpoch() const
Definition: DateTime.cpp:95
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
armarx::core::time::DateTime::toMilliSecondsSinceEpoch
std::int64_t toMilliSecondsSinceEpoch() const
Definition: DateTime.cpp:102
armarx::core::time::DateTime::operator-
DateTime operator-(const Duration &rhs) const
Definition: DateTime.cpp:162
armarx::core::time::DateTime
Represents a point in time.
Definition: DateTime.h:24
armarx::core::time::DateTime::toString
std::string toString(const std::string &format) const
String representation of current date time according to given format string.
Definition: DateTime.cpp:88
armarx::core::time::DateTime::hostname
std::string hostname() const
Definition: DateTime.cpp:130
armarx::core::time::DateTime::toTimeString
std::string toTimeString() const
Definition: DateTime.cpp:74
armarx::core::time::Duration
Represents a duration.
Definition: Duration.h:17
armarx::core::time::DateTime::operator!=
bool operator!=(const DateTime &rhs) const
Definition: DateTime.cpp:219
armarx::core::time::Duration::toDurationString
std::string toDurationString() const
String representation of the current duration in minimal/default format.
Definition: Duration.cpp:209
armarx::core::time::Clock::Now
static DateTime Now()
Current time on the virtual clock.
Definition: Clock.cpp:97
armarx::core::time::DateTime::_clockType
ClockType _clockType
Definition: DateTime.h:132
armarx::core::time::Duration::toMilliSeconds
std::int64_t toMilliSeconds() const
Returns the amount of milliseconds.
Definition: Duration.cpp:69
armarx::core::time::Duration::toMicroSeconds
std::int64_t toMicroSeconds() const
Returns the amount of microseconds.
Definition: Duration.cpp:41
min
T min(T t1, T t2)
Definition: gdiam.h:42
armarx::core::time::Duration::MicroSeconds
static Duration MicroSeconds(std::int64_t microSeconds)
Constructs a duration in microseconds.
Definition: Duration.cpp:27
armarx::core::time::DateTime::_invalidTimeSinceEpoch
static const Duration _invalidTimeSinceEpoch
Definition: DateTime.h:128
armarx::core::time::Duration::toSeconds
std::int64_t toSeconds() const
Returns the amount of seconds.
Definition: Duration.cpp:97
armarx::armem::Duration
armarx::core::time::Duration Duration
Definition: forward_declarations.h:14
armarx::core::time::DateTime::Invalid
static DateTime Invalid()
Definition: DateTime.cpp:60
armarx::core::time::DateTime::toDateTimeString
std::string toDateTimeString() const
Definition: DateTime.cpp:81
armarx::core::time::DateTime::operator+=
DateTime & operator+=(const Duration &rhs)
Definition: DateTime.cpp:154