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