nlib
DateTime.h
Go to the documentation of this file.
1 
2 /*--------------------------------------------------------------------------------*
3  Project: CrossRoad
4  Copyright (C)Nintendo All rights reserved.
5 
6  These coded instructions, statements, and computer programs contain proprietary
7  information of Nintendo and/or its licensed developers and are protected by
8  national and international copyright laws. They may not be disclosed to third
9  parties or copied or duplicated in any form, in whole or in part, without the
10  prior written consent of Nintendo.
11 
12  The content herein is highly confidential and should be handled accordingly.
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  // kWeekSunday -> kWeekSaturday
264  enum Week {
265  kWeekSunday = 0,
271  kWeekSaturday,
272  kWeekMax,
273  WEEK_SUNDAY = kWeekSunday,
274  WEEK_MONDAY = kWeekMonday,
275  WEEK_TUESDAY = kWeekTuesday,
276  WEEK_WEDNESDAY = kWeekWednesday,
277  WEEK_THURSDAY = kWeekThursday,
278  WEEK_FRIDAY = kWeekFriday,
279  WEEK_SATURDAY = kWeekSaturday,
280  WEEK_MAX = kWeekMax
281  };
282 
283  public:
284  NLIB_CEXPR DateTime() NLIB_NOEXCEPT : value_(INT64_MIN) {}
285  // You can omit min/sec/msec/usec.
286  errno_t Init(int year, int month, int day, int hour = 0,
287  int min = 0, int sec = 0, int msec = 0,
288  int usec = 0) NLIB_NOEXCEPT;
289  errno_t Init(const DateTimeParams& rhs) NLIB_NOEXCEPT;
290  // nlib_epochtime(&t); dt.Init(TimeValue(t)); for example
291  errno_t Init(const TimeValue& tv) NLIB_NOEXCEPT {
292  value_ = tv;
293  return IsValid() ? 0 : EINVAL;
294  }
295  // you can pass null pointers
296  errno_t GetDay(
297  int* year,
298  int* month,
299  int* day) const NLIB_NOEXCEPT;
300  // you can pass null pointers
301  errno_t GetTime(
302  int* hour,
303  int* min,
304  int* sec,
305  int* msec,
306  int* usec) const NLIB_NOEXCEPT;
307  errno_t Get(
308  DateTimeParams* rhs) const NLIB_NOEXCEPT;
309 
310  TimeValue ToTimeValue() const NLIB_NOEXCEPT { return value_; }
311  bool IsValid() const NLIB_NOEXCEPT;
312 
313  // 01-01 becomes 0.
314  errno_t GetDayOfYear(int* nth) const NLIB_NOEXCEPT;
315  // Sunday -> 0(kWeekSunday), Saturday -> 6(kWeekSaturday)
316  errno_t GetDayOfWeek(Week* week) const NLIB_NOEXCEPT;
317  // returns EINVAL on failure
318  errno_t Add(const TimeSpan& rhs) NLIB_NOEXCEPT;
319  // returns EINVAL on failure
320  errno_t AddYears(int value) NLIB_NOEXCEPT;
321  // returns EINVAL on failure
322  errno_t AddMonths(int value) NLIB_NOEXCEPT;
323  // returns EINVAL on failure
324  errno_t AddDays(double value) NLIB_NOEXCEPT;
325  // returns EINVAL on failure
326  errno_t AddHours(double value) NLIB_NOEXCEPT;
327  // returns EINVAL on failure
328  errno_t AddMinutes(double value) NLIB_NOEXCEPT;
329  // returns EINVAL on failure
330  errno_t AddSeconds(double value) NLIB_NOEXCEPT;
331  // returns EINVAL on failure
332  errno_t AddMilliSeconds(double value) NLIB_NOEXCEPT;
333  // returns EINVAL on failure
334  errno_t AddMicroSeconds(double value) NLIB_NOEXCEPT;
335 
336  // "1994-11-05T13:15:30Z" for example
337  errno_t ToW3cDtf(
338  char (&str)[32],
339  const TimeSpan& zone) const NLIB_NOEXCEPT;
341  char (&str)[32]) const NLIB_NOEXCEPT {
342  return ToW3cDtf(str, TimeSpan());
343  }
344 
345  // "Tue, 02 Sep 2014 10:51:34 +0900" for example
346  errno_t ToRfc2822(
347  char(&str) [32],
348  const TimeSpan& zone) const NLIB_NOEXCEPT;
350  char (&str)[32]) const NLIB_NOEXCEPT {
351  return ToRfc2822(str, TimeSpan());
352  }
353 
354  // "Wed Jan 02 02:03:45 1980\n" for example
355  errno_t ToAscTime(
356  char (&str)[26]) const NLIB_NOEXCEPT;
357 
358  NLIB_SAFE_BOOL(DateTime, IsValid())
359 
360  public:
361  DateTime& operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT;
362  DateTime& operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT;
363  bool operator==(const DateTime& rhs) const NLIB_NOEXCEPT {
364  return value_ == rhs.value_;
365  }
366  bool operator!=(const DateTime& rhs) const NLIB_NOEXCEPT {
367  return value_ != rhs.value_;
368  }
369  bool operator<(const DateTime& rhs) const NLIB_NOEXCEPT {
370  return value_ < rhs.value_;
371  }
372  bool operator>(const DateTime& rhs) const NLIB_NOEXCEPT {
373  return value_ > rhs.value_;
374  }
375  bool operator<=(const DateTime& rhs) const NLIB_NOEXCEPT {
376  return value_ <= rhs.value_;
377  }
378  bool operator>=(const DateTime& rhs) const NLIB_NOEXCEPT {
379  return value_ >= rhs.value_;
380  }
381 
382  explicit DateTime(const struct timespec* tm) NLIB_NOEXCEPT {
383  NLIB_FROM_TIMESPEC(tm, value_.tick);
384  }
385  void ToTimeSpec(struct timespec* tm) const NLIB_NOEXCEPT {
386  NLIB_TO_TIMESPEC(tm, value_.tick);
387  }
388 #ifdef NLIB_CXX11_STDLIB_CHRONO
389  template <class Clock, class Duration>
390  errno_t Init(const std::chrono::time_point<Clock, Duration>& rhs) {
391  auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(rhs.time_since_epoch());
392  value_.tick = static_cast<nlib_duration>(tmp.count() * 10);
393  return 0;
394  }
395  template <class T>
396  T ToChrono() const {
397  auto tmp = std::chrono::microseconds(value_.tick / 10);
398  return T(tmp);
399  }
400 #endif
401 
402  public:
403  static bool IsLeapYear(int year) NLIB_NOEXCEPT {
404  return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
405  }
406  static errno_t GetNow(DateTime* p) NLIB_NOEXCEPT;
407  // January has 31 days for example
408  static int GetDaysInMonth(int year, int month) NLIB_NOEXCEPT;
409  // can parse W3CDTF, RFC2822, or ASCTIME
410  static errno_t Parse(
411  const char* str,
412  DateTime* dt,
413  TimeSpan* delta) NLIB_NOEXCEPT NLIB_NONNULL_1;
414 
415  private:
416  TimeValue value_;
417 };
418 
419 inline errno_t DateTime::Init(const DateTimeParams& rhs) NLIB_NOEXCEPT {
420  return this->Init(rhs.year, rhs.month, rhs.day, rhs.hour, rhs.min, rhs.sec, rhs.msec, rhs.usec);
421 }
422 
423 inline errno_t DateTime::Add(const TimeSpan& rhs) NLIB_NOEXCEPT {
424  value_ += rhs.ToTimeValue();
425  return IsValid() ? 0 : ERANGE;
426 }
427 
428 inline errno_t DateTime::AddDays(double value) NLIB_NOEXCEPT {
429  TimeSpan d(1);
430  d *= value;
431  return this->Add(d);
432 }
433 
434 inline errno_t DateTime::AddHours(double value) NLIB_NOEXCEPT {
435  TimeSpan d(0, 60 * 60);
436  d *= value;
437  return this->Add(d);
438 }
439 
440 inline errno_t DateTime::AddMinutes(double value) NLIB_NOEXCEPT {
441  TimeSpan d(0, 60);
442  d *= value;
443  return this->Add(d);
444 }
445 
446 inline errno_t DateTime::AddSeconds(double value) NLIB_NOEXCEPT {
447  TimeSpan d(0, 1);
448  d *= value;
449  return this->Add(d);
450 }
451 
452 inline errno_t DateTime::AddMilliSeconds(double value) NLIB_NOEXCEPT {
453  TimeSpan d(0, 0, 1);
454  d *= value;
455  return this->Add(d);
456 }
457 
458 inline errno_t DateTime::AddMicroSeconds(double value) NLIB_NOEXCEPT {
459  TimeSpan d(0, 0, 0, 1);
460  d *= value;
461  return this->Add(d);
462 }
463 
464 inline DateTime& DateTime::operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT {
465  this->Add(rhs);
466  return *this;
467 }
468 
469 inline DateTime& DateTime::operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT {
470  *this += (-rhs);
471  return *this;
472 }
473 
474 inline DateTime operator+(const DateTime& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
475  DateTime tmp(lhs);
476  tmp += rhs;
477  return tmp;
478 }
479 
480 inline DateTime operator-(const DateTime& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
481  DateTime tmp(lhs);
482  tmp -= rhs;
483  return tmp;
484 }
485 
486 inline TimeSpan operator-(const DateTime& lhs, const DateTime& rhs) NLIB_NOEXCEPT {
487  return TimeSpan(lhs.ToTimeValue() - rhs.ToTimeValue());
488 }
489 
490 NLIB_NAMESPACE_END
491 
492 #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:372
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:403
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:340
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:178
#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:145
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
Returns true if the two compared summaries are not equal.
Definition: NMalloc.h:150
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:450
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:349
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:474
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:89
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:378
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:385
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:486
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:375
#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:363
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:310
#define NLIB_FINAL
Defines final if it is available for use. If not, holds an empty string.
Definition: Config.h:229
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:284
bool operator!=(const DateTime &rhs) const noexcept
Returns true if the time is not equal to rhs.
Definition: DateTime.h:366
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:369
#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:382
int64_t nlib_duration
The type expressing the time in increments of 100 ns. A 64-bit signed integer.
Definition: Platform.h:452
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:291
int errno_t
Indicates with an int-type typedef that a POSIX error value is returned as the return value...
Definition: NMalloc.h:37