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