nlib
DateTime.h
Go to the documentation of this file.
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_DATETIME_H_
4 #define INCLUDE_NN_NLIB_DATETIME_H_
5 
6 #include "nn/nlib/Config.h"
7 
8 #ifdef NLIB_CXX11_STDLIB_CHRONO
9 #include <chrono> // NOLINT
10 #endif
11 
12 NLIB_NAMESPACE_BEGIN
13 
14 // writes the duration in milliseconds from 2000/01/01.
16 
18  NLIB_EINVAL_IFNULL(t);
19  nlib_time time;
20  errno_t e = nlib_epochtime(&time);
21  if (e != 0) return e;
22  // 1970/01/01 -> 2000/01/01(in milliseconds)
23  *t = time / 10000 - (10957LL * 24LL * 60LL * 60LL * 1000LL);
24  return 0;
25 }
26 
27 // returns in milliseconds after the system boot.
28 inline uint64_t GetTickTime() NLIB_NOEXCEPT {
29  nlib_time t;
30  (void)nlib_ticktime(&t);
31  return static_cast<uint64_t>(t / 10000);
32 }
33 
34 // NOTE:
35 // TimeValue has a 64bit value, and 1 represents 100ns, 1ms is 10000.
36 // We can represent the time from A.D 1 to 9999 within 64bits.
39  NLIB_CEXPR explicit TimeValue(int64_t tick_) NLIB_NOEXCEPT : tick(tick_) {}
40 
42  tick += rhs.tick;
43  return *this;
44  }
46  tick -= rhs.tick;
47  return *this;
48  }
49  void Abs() NLIB_NOEXCEPT {
50  if (tick < 0) tick = -tick;
51  }
52  TimeValue operator-() const NLIB_NOEXCEPT { return TimeValue(-tick); }
53  TimeValue operator+() const NLIB_NOEXCEPT { return *this; }
54 
55  public:
56  int64_t tick; // nlib_time, nlib_duration
57 };
58 
59 inline bool operator==(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
60  return lhs.tick == rhs.tick;
61 }
62 inline bool operator<(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
63  return lhs.tick < rhs.tick;
64 }
65 inline bool operator!=(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
66  return !(lhs == rhs);
67 }
68 inline bool operator>(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
69  return rhs < lhs;
70 }
71 inline bool operator<=(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
72  return !(lhs > rhs);
73 }
74 inline bool operator>=(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
75  return !(lhs < rhs);
76 }
77 
78 inline TimeValue operator+(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
79  TimeValue result(lhs);
80  result += rhs;
81  return result;
82 }
83 
84 inline TimeValue operator-(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
85  TimeValue result(lhs);
86  result -= rhs;
87  return result;
88 }
89 
90 // TimeValue(tick_1d) is 1 day
91 NLIB_CEXPR const int64_t tick_1d = (10LL * 1000 * 1000 * 60 * 60 * 24);
92 
94  public:
96  explicit TimeSpan(const TimeValue& rhs) NLIB_NOEXCEPT : value_(rhs) {}
97  NLIB_CEXPR explicit TimeSpan(int days) NLIB_NOEXCEPT
98  : value_(static_cast<int64_t>(days) * tick_1d) {}
99  NLIB_CEXPR TimeSpan(int days, int seconds) NLIB_NOEXCEPT
100  : value_(days* tick_1d + seconds*(10LL * 1000 * 1000)) {}
101  // TimeSpan(0, 0, 1) for 1msec
102  NLIB_CEXPR TimeSpan(int days, int seconds,
103  int milliseconds, int microseconds = 0) NLIB_NOEXCEPT
104  : value_(days* tick_1d + seconds*(10LL * 1000 * 1000) + milliseconds*(10LL * 1000) +
105  microseconds * 10LL) {}
106 
107  void Get(int* days,
108  int* seconds,
109  int* milliseconds,
110  int* microseconds) NLIB_NOEXCEPT;
111 
112  TimeValue ToTimeValue() const NLIB_NOEXCEPT { return value_; }
113  int ToDays() const NLIB_NOEXCEPT {
114  return static_cast<int>(value_.tick / (10LL * 1000 * 1000 * 60 * 60 * 24));
115  }
116  int ToHours() const NLIB_NOEXCEPT {
117  return static_cast<int>(value_.tick / (10LL * 1000 * 1000 * 60 * 60));
118  }
119  int64_t ToMinutes() const NLIB_NOEXCEPT {
120  return value_.tick / (10 * 1000 * 1000 * 60);
121  }
122  int64_t ToSeconds() const NLIB_NOEXCEPT {
123  return value_.tick / (10 * 1000 * 1000);
124  }
125  int64_t ToMilliSeconds() const NLIB_NOEXCEPT {
126  return value_.tick / (10 * 1000);
127  }
128  int64_t ToMicroSeconds() const NLIB_NOEXCEPT {
129  return value_.tick / (10);
130  }
131  template <class TIMEVAL>
132  void ToTimeVal(TIMEVAL* tv) const NLIB_NOEXCEPT {
133  int64_t usec = ToMicroSeconds();
134  int64_t sec = usec / (1000 * 1000);
135  tv->tv_sec = static_cast<time_t>(sec);
136  tv->tv_usec = static_cast<int32_t>(usec - sec * (1000 * 1000));
137  }
138  explicit TimeSpan(const struct timespec* tm) NLIB_NOEXCEPT {
139  NLIB_FROM_TIMESPEC(tm, value_.tick);
140  }
141  void ToTimeSpec(struct timespec* tm) const NLIB_NOEXCEPT {
142  NLIB_TO_TIMESPEC(tm, value_.tick);
143  }
144 #ifdef NLIB_CXX11_STDLIB_CHRONO
145  template <class Rep, class Period>
146  TimeSpan(const std::chrono::duration<Rep, Period>& rhs) { // NOLINT
147  auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(rhs);
148  value_.tick = static_cast<nlib_duration>(tmp.count() * 10);
149  }
150  template <class T>
151  T ToChrono() const {
152  auto tmp = std::chrono::microseconds(value_.tick / 10);
153  return std::chrono::duration_cast<T>(tmp);
154  }
155 #endif
156 
157  public:
158  TimeSpan& operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT {
159  value_ += rhs.value_;
160  return *this;
161  }
162  TimeSpan& operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT {
163  value_ -= rhs.value_;
164  return *this;
165  }
166  TimeSpan& operator*=(int i) NLIB_NOEXCEPT {
167  value_.tick *= i;
168  return *this;
169  }
170  TimeSpan& operator*=(double d) NLIB_NOEXCEPT {
171  value_.tick = static_cast<int64_t>(value_.tick * d);
172  return *this;
173  }
174  void Abs() NLIB_NOEXCEPT { value_.Abs(); }
175  TimeSpan operator-() const NLIB_NOEXCEPT { return TimeSpan(-value_); }
176  TimeSpan operator+() const NLIB_NOEXCEPT { return *this; }
177  bool operator==(const TimeSpan& rhs) const NLIB_NOEXCEPT {
178  return value_ == rhs.value_;
179  }
180  bool operator!=(const TimeSpan& rhs) const NLIB_NOEXCEPT {
181  return value_ != rhs.value_;
182  }
183  bool operator<(const TimeSpan& rhs) const NLIB_NOEXCEPT {
184  return value_ < rhs.value_;
185  }
186  bool operator>(const TimeSpan& rhs) const NLIB_NOEXCEPT {
187  return value_ > rhs.value_;
188  }
189  bool operator<=(const TimeSpan& rhs) const NLIB_NOEXCEPT {
190  return value_ <= rhs.value_;
191  }
192  bool operator>=(const TimeSpan& rhs) const NLIB_NOEXCEPT {
193  return value_ >= rhs.value_;
194  }
195 
196  private:
197  TimeValue value_;
198 };
199 
200 inline TimeSpan operator+(const TimeSpan& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
201  TimeSpan result(lhs);
202  result += rhs;
203  return result;
204 }
205 
206 inline TimeSpan operator-(const TimeSpan& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
207  TimeSpan result(lhs);
208  result -= rhs;
209  return result;
210 }
211 
212 inline TimeSpan operator*(int i, const TimeSpan& rhs) NLIB_NOEXCEPT {
213  TimeSpan result(rhs);
214  result *= i;
215  return result;
216 }
217 
218 inline TimeSpan operator*(double d, const TimeSpan& rhs) NLIB_NOEXCEPT {
219  TimeSpan result(rhs);
220  result *= d;
221  return result;
222 }
223 
224 inline TimeSpan operator*(const TimeSpan& lhs, int i) NLIB_NOEXCEPT {
225  TimeSpan result(lhs);
226  result *= i;
227  return result;
228 }
229 
230 inline TimeSpan operator*(const TimeSpan& lhs, double d) NLIB_NOEXCEPT {
231  TimeSpan result(lhs);
232  result *= d;
233  return result;
234 }
235 
236 // has year/month/day/hour/min/sec/msec/usec
238  int year;
239  int month;
240  int day;
241  int hour;
242  int min;
243  int sec;
244  int msec;
245  int usec;
246 };
247 
249  public:
250  // WEEK_SUNDAY -> WEEK_SATURDAY
251  enum Week {
252  WEEK_SUNDAY = 0,
259  WEEK_MAX
260  };
261 
262  public:
263  NLIB_CEXPR DateTime() NLIB_NOEXCEPT : value_(INT64_MIN) {}
264  // You can omit min/sec/msec/usec.
265  errno_t Init(int year, int month, int day, int hour = 0,
266  int min = 0, int sec = 0, int msec = 0,
267  int usec = 0) NLIB_NOEXCEPT;
268  errno_t Init(const DateTimeParams& rhs) NLIB_NOEXCEPT;
269  // nlib_epochtime(&t); dt.Init(TimeValue(t)); for example
270  errno_t Init(const TimeValue& tv) NLIB_NOEXCEPT {
271  value_ = tv;
272  return IsValid() ? 0 : EINVAL;
273  }
274  // you can pass null pointers
275  errno_t GetDay(
276  int* year,
277  int* month,
278  int* day) const NLIB_NOEXCEPT;
279  // you can pass null pointers
280  errno_t GetTime(
281  int* hour,
282  int* min,
283  int* sec,
284  int* msec,
285  int* usec) const NLIB_NOEXCEPT;
286  errno_t Get(
287  DateTimeParams* rhs) const NLIB_NOEXCEPT;
288 
289  TimeValue ToTimeValue() const NLIB_NOEXCEPT { return value_; }
290  bool IsValid() const NLIB_NOEXCEPT;
291 
292  // 01-01 becomes 0.
293  errno_t GetDayOfYear(int* nth) const NLIB_NOEXCEPT;
294  // Sunday -> 0(WEEK_SUNDAY), Saturday -> 6(WEEK_SATURDAY)
295  errno_t GetDayOfWeek(Week* week) const NLIB_NOEXCEPT;
296  // returns EINVAL on failure
297  errno_t Add(const TimeSpan& rhs) NLIB_NOEXCEPT;
298  // returns EINVAL on failure
299  errno_t AddYears(int value) NLIB_NOEXCEPT;
300  // returns EINVAL on failure
301  errno_t AddMonths(int value) NLIB_NOEXCEPT;
302  // returns EINVAL on failure
303  errno_t AddDays(double value) NLIB_NOEXCEPT;
304  // returns EINVAL on failure
305  errno_t AddHours(double value) NLIB_NOEXCEPT;
306  // returns EINVAL on failure
307  errno_t AddMinutes(double value) NLIB_NOEXCEPT;
308  // returns EINVAL on failure
309  errno_t AddSeconds(double value) NLIB_NOEXCEPT;
310  // returns EINVAL on failure
311  errno_t AddMilliSeconds(double value) NLIB_NOEXCEPT;
312  // returns EINVAL on failure
313  errno_t AddMicroSeconds(double value) NLIB_NOEXCEPT;
314 
315  // "1994-11-05T13:15:30Z" for example
316  errno_t ToW3cDtf(
317  char (&str)[32],
318  const TimeSpan& zone) const NLIB_NOEXCEPT;
320  char (&str)[32]) const NLIB_NOEXCEPT {
321  return ToW3cDtf(str, TimeSpan());
322  }
323 
324  // "Tue, 02 Sep 2014 10:51:34 +0900" for example
325  errno_t ToRfc2822(
326  char(&str) [32],
327  const TimeSpan& zone) const NLIB_NOEXCEPT;
329  char (&str)[32]) const NLIB_NOEXCEPT {
330  return ToRfc2822(str, TimeSpan());
331  }
332 
333  // "Wed Jan 02 02:03:45 1980\n" for example
334  errno_t ToAscTime(
335  char (&str)[26]) const NLIB_NOEXCEPT;
336 
337  NLIB_SAFE_BOOL(DateTime, IsValid())
338 
339  public:
340  DateTime& operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT;
341  DateTime& operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT;
342  bool operator==(const DateTime& rhs) const NLIB_NOEXCEPT {
343  return value_ == rhs.value_;
344  }
345  bool operator!=(const DateTime& rhs) const NLIB_NOEXCEPT {
346  return value_ != rhs.value_;
347  }
348  bool operator<(const DateTime& rhs) const NLIB_NOEXCEPT {
349  return value_ < rhs.value_;
350  }
351  bool operator>(const DateTime& rhs) const NLIB_NOEXCEPT {
352  return value_ > rhs.value_;
353  }
354  bool operator<=(const DateTime& rhs) const NLIB_NOEXCEPT {
355  return value_ <= rhs.value_;
356  }
357  bool operator>=(const DateTime& rhs) const NLIB_NOEXCEPT {
358  return value_ >= rhs.value_;
359  }
360 
361  explicit DateTime(const struct timespec* tm) NLIB_NOEXCEPT {
362  NLIB_FROM_TIMESPEC(tm, value_.tick);
363  }
364  void ToTimeSpec(struct timespec* tm) const NLIB_NOEXCEPT {
365  NLIB_TO_TIMESPEC(tm, value_.tick);
366  }
367 #ifdef NLIB_CXX11_STDLIB_CHRONO
368  template <class Clock, class Duration>
369  errno_t Init(const std::chrono::time_point<Clock, Duration>& rhs) {
370  auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(rhs.time_since_epoch());
371  value_.tick = static_cast<nlib_duration>(tmp.count() * 10);
372  return 0;
373  }
374  template <class T>
375  T ToChrono() const {
376  auto tmp = std::chrono::microseconds(value_.tick / 10);
377  return T(tmp);
378  }
379 #endif
380 
381  public:
382  static bool IsLeapYear(int year) NLIB_NOEXCEPT {
383  return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
384  }
385  static errno_t GetNow(DateTime* p) NLIB_NOEXCEPT;
386  // January has 31 days for example
387  static int GetDaysInMonth(int year, int month) NLIB_NOEXCEPT;
388  // can parse W3CDTF, RFC2822, or ASCTIME
389  static errno_t Parse(
390  const char* str,
391  DateTime* dt,
392  TimeSpan* delta) NLIB_NOEXCEPT NLIB_NONNULL_1;
393 
394  private:
395  TimeValue value_;
396 };
397 
398 inline errno_t DateTime::Init(const DateTimeParams& rhs) NLIB_NOEXCEPT {
399  return this->Init(rhs.year, rhs.month, rhs.day, rhs.hour, rhs.min, rhs.sec, rhs.msec, rhs.usec);
400 }
401 
402 inline errno_t DateTime::Add(const TimeSpan& rhs) NLIB_NOEXCEPT {
403  value_ += rhs.ToTimeValue();
404  return IsValid() ? 0 : ERANGE;
405 }
406 
407 inline errno_t DateTime::AddDays(double value) NLIB_NOEXCEPT {
408  TimeSpan d(1);
409  d *= value;
410  return this->Add(d);
411 }
412 
413 inline errno_t DateTime::AddHours(double value) NLIB_NOEXCEPT {
414  TimeSpan d(0, 60 * 60);
415  d *= value;
416  return this->Add(d);
417 }
418 
419 inline errno_t DateTime::AddMinutes(double value) NLIB_NOEXCEPT {
420  TimeSpan d(0, 60);
421  d *= value;
422  return this->Add(d);
423 }
424 
425 inline errno_t DateTime::AddSeconds(double value) NLIB_NOEXCEPT {
426  TimeSpan d(0, 1);
427  d *= value;
428  return this->Add(d);
429 }
430 
431 inline errno_t DateTime::AddMilliSeconds(double value) NLIB_NOEXCEPT {
432  TimeSpan d(0, 0, 1);
433  d *= value;
434  return this->Add(d);
435 }
436 
437 inline errno_t DateTime::AddMicroSeconds(double value) NLIB_NOEXCEPT {
438  TimeSpan d(0, 0, 0, 1);
439  d *= value;
440  return this->Add(d);
441 }
442 
443 inline DateTime& DateTime::operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT {
444  this->Add(rhs);
445  return *this;
446 }
447 
448 inline DateTime& DateTime::operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT {
449  *this += (-rhs);
450  return *this;
451 }
452 
453 inline DateTime operator+(const DateTime& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
454  DateTime tmp(lhs);
455  tmp += rhs;
456  return tmp;
457 }
458 
459 inline DateTime operator-(const DateTime& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
460  DateTime tmp(lhs);
461  tmp -= rhs;
462  return tmp;
463 }
464 
465 inline TimeSpan operator-(const DateTime& lhs, const DateTime& rhs) NLIB_NOEXCEPT {
466  return TimeSpan(lhs.ToTimeValue() - rhs.ToTimeValue());
467 }
468 
469 NLIB_NAMESPACE_END
470 
471 #endif // INCLUDE_NN_NLIB_DATETIME_H_
bool operator<(const TimeValue &lhs, const TimeValue &rhs) noexcept
A relational operator.
Definition: DateTime.h:62
int64_t tick
These can be used for nlib_time and nlib_duration.
Definition: DateTime.h:56
TimeSpan & operator*=(int i) noexcept
Multiplies the time by i.
Definition: DateTime.h:166
TimeValue ToTimeValue() const noexcept
Converts to a TimeValue object.
Definition: DateTime.h:112
bool operator>(const DateTime &rhs) const noexcept
Returns true if further in the future than rhs.
Definition: DateTime.h:351
bool operator==(const TimeSpan &rhs) const noexcept
Returns true if the time is the same.
Definition: DateTime.h:177
int64_t ToMilliSeconds() const noexcept
Returns the time in terms of a number of milliseconds. Fractions are truncated.
Definition: DateTime.h:125
int min
The minute (0-59).
Definition: DateTime.h:242
TimeSpan & operator-=(const TimeSpan &rhs) noexcept
Subtracts time.
Definition: DateTime.h:162
static bool IsLeapYear(int year) noexcept
Checks whether the specified year is a leap year.
Definition: DateTime.h:382
int year
The year (1-9999).
Definition: DateTime.h:238
bool operator<=(const TimeSpan &rhs) const noexcept
Returns true if equal to or smaller than rhs.
Definition: DateTime.h:189
errno_t ToW3cDtf(char(&str)[32]) const noexcept
Calls ToW3cDtf(str, TimeSpan()).
Definition: DateTime.h:319
errno_t nlib_ticktime(nlib_duration *t)
Gets the elapsed time since the system was last started.
#define NLIB_SAFE_BOOL(class_name, exp)
Defines a safe operator bool function in the class. Uses the C++11 explicit bool if it is available f...
Definition: Config.h:160
#define NLIB_NONNULL_1
Indicates that you cannot specify NULL for the first argument.
Definition: Platform_unix.h:77
int64_t ToSeconds() const noexcept
Returns the time in terms of a number of seconds. Fractions are truncated.
Definition: DateTime.h:122
TimeSpan & operator+=(const TimeSpan &rhs) noexcept
Adds time.
Definition: DateTime.h:158
TimeSpan operator*(const TimeSpan &lhs, double d) noexcept
Increases rhs by a factor of d.
Definition: DateTime.h:230
int ToHours() const noexcept
Returns the time span as a number of hours. Fractions are truncated.
Definition: DateTime.h:116
int msec
The millisecond (0-999).
Definition: DateTime.h:244
bool operator<=(const TimeValue &lhs, const TimeValue &rhs) noexcept
A relational operator.
Definition: DateTime.h:71
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are equal.
Definition: NMalloc.h:110
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are not equal.
Definition: NMalloc.h:115
int64_t nlib_time
The type expressing the time in increments of 100 ns from the zero starting point of 1970-01-01...
Definition: Platform.h:744
bool operator>=(const TimeSpan &rhs) const noexcept
Returns true if equal to or larger than rhs.
Definition: DateTime.h:192
errno_t ToRfc2822(char(&str)[32]) const noexcept
Calls ToRfc2822(str, TimeSpan()).
Definition: DateTime.h:328
DateTime operator+(const DateTime &lhs, const TimeSpan &rhs) noexcept
Returns the time that is the rhs amount of time into the future from lhs.
Definition: DateTime.h:453
The class for representing the date and time.
Definition: DateTime.h:248
#define NLIB_VIS_PUBLIC
Symbols for functions and classes are made available outside of the library.
Definition: Platform_unix.h:61
void ToTimeSpec(struct timespec *tm) const noexcept
Converts to a value of the timespec structure.
Definition: DateTime.h:141
uint64_t GetTickTime() noexcept
Returns the time in units of milliseconds that has elapsed since the system started.
Definition: DateTime.h:28
TimeSpan(const struct timespec *tm) noexcept
Instantiates the object from the timespec structure.
Definition: DateTime.h:138
bool operator>=(const DateTime &rhs) const noexcept
Returns true if the same or further in the future than rhs.
Definition: DateTime.h:357
TimeValue operator+() const noexcept
A unary operator.
Definition: DateTime.h:53
bool operator!=(const TimeSpan &rhs) const noexcept
Returns true if the time is different.
Definition: DateTime.h:180
int hour
The hour (0-23).
Definition: DateTime.h:241
bool operator>(const TimeSpan &rhs) const noexcept
Returns true if larger than rhs.
Definition: DateTime.h:186
int sec
The second (0-59).
Definition: DateTime.h:243
TimeValue operator-() const noexcept
A unary operator.
Definition: DateTime.h:52
constexpr TimeSpan() noexcept
Instantiates the object and initializes the time to 0.
Definition: DateTime.h:95
int ToDays() const noexcept
Returns the time in terms of a number of days. Fractions are truncated.
Definition: DateTime.h:113
Week
Constants representing the days of the week.
Definition: DateTime.h:251
void ToTimeSpec(struct timespec *tm) const noexcept
Converts to a value of the timespec structure.
Definition: DateTime.h:364
The structure for setting date and time information in DateTime and for getting that information from...
Definition: DateTime.h:237
TimeSpan operator-(const DateTime &lhs, const DateTime &rhs) noexcept
Returns the duration between the times of rhs and lhs.
Definition: DateTime.h:465
errno_t GetNintendoTime(int64_t *t) noexcept
Returns the amount of time that has elapsed, in units of milliseconds, starting from 2000-01-01...
Definition: DateTime.h:17
bool operator>=(const TimeValue &lhs, const TimeValue &rhs) noexcept
A relational operator.
Definition: DateTime.h:74
TimeSpan operator+() const noexcept
A unary operator.
Definition: DateTime.h:176
errno_t nlib_epochtime(nlib_time *t)
Gets the current time.
bool operator<=(const DateTime &rhs) const noexcept
Returns true if the same or further in the past than rhs.
Definition: DateTime.h:354
#define NLIB_NOEXCEPT
Defines noexcept geared to the environment, or the equivalent.
Definition: Config.h:86
#define NLIB_CEXPR
Defines constexpr if it is available for use. If not, holds an empty string.
Definition: Config.h:80
A file that contains the configuration information for each development environment.
int usec
The microsecond (0-999).
Definition: DateTime.h:245
TimeSpan operator-() const noexcept
A unary operator.
Definition: DateTime.h:175
bool operator==(const DateTime &rhs) const noexcept
Returns true if the time is equal to rhs.
Definition: DateTime.h:342
bool operator>(const TimeValue &lhs, const TimeValue &rhs) noexcept
A relational operator.
Definition: DateTime.h:68
constexpr TimeSpan(int days) noexcept
Initializes the object with a number of days specified for the period of time.
Definition: DateTime.h:97
int month
The month (1-12).
Definition: DateTime.h:239
bool operator<(const TimeSpan &rhs) const noexcept
Returns true if smaller than rhs.
Definition: DateTime.h:183
TimeSpan(const TimeValue &rhs) noexcept
Initializes using a TimeValue object.
Definition: DateTime.h:96
TimeValue ToTimeValue() const noexcept
Returns a TimeValue object.
Definition: DateTime.h:289
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:211
The class for representing the time.
Definition: DateTime.h:93
constexpr DateTime() noexcept
Instantiates the object with default parameters (default constructor). Initializes with an invalid ti...
Definition: DateTime.h:263
bool operator!=(const DateTime &rhs) const noexcept
Returns true if the time is not equal to rhs.
Definition: DateTime.h:345
constexpr TimeSpan(int days, int seconds) noexcept
Initializes the object with a number of days and a number of seconds specified for the period of time...
Definition: DateTime.h:99
constexpr TimeValue() noexcept
Instantiates the object with default parameters (default constructor).
Definition: DateTime.h:38
int64_t ToMicroSeconds() const noexcept
Returns the time in terms of a number of microseconds. Fractions are truncated.
Definition: DateTime.h:128
constexpr TimeValue(int64_t tick_) noexcept
Initializes with the values of nlib_time and nlib_duration taken as the arguments.
Definition: DateTime.h:39
TimeSpan & operator*=(double d) noexcept
Multiplies the time by d.
Definition: DateTime.h:170
constexpr TimeSpan(int days, int seconds, int milliseconds, int microseconds=0) noexcept
Initializes the object with a number of days, seconds, milliseconds, and microseconds specified for t...
Definition: DateTime.h:102
The class that wraps 64-bit signed integers.
Definition: DateTime.h:37
bool operator<(const DateTime &rhs) const noexcept
Returns true if further in the past than rhs.
Definition: DateTime.h:348
#define NLIB_NONNULL
Indicates that you cannot specify NULL for all arguments.
Definition: Platform_unix.h:76
TimeValue & operator-=(const TimeValue &rhs) noexcept
Subtracts.
Definition: DateTime.h:45
DateTime(const struct timespec *tm) noexcept
Instantiates the object from the timespec structure.
Definition: DateTime.h:361
int64_t nlib_duration
The type expressing the time in increments of 100 ns. A 64-bit signed integer.
Definition: Platform.h:746
int64_t ToMinutes() const noexcept
Returns the time as a number of minutes. Fractions are truncated.
Definition: DateTime.h:119
TimeValue & operator+=(const TimeValue &rhs) noexcept
Adds.
Definition: DateTime.h:41
int day
The day (1-).
Definition: DateTime.h:240
errno_t Init(const TimeValue &tv) noexcept
Initializes the date and time using the TimeValue structure. Returns EINVAL if given an invalid date...
Definition: DateTime.h:270
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:24