nlib
DateTime.h
[詳解]
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
比較演算子です。
Definition: DateTime.h:75
int64_t tick
nlib_time, nlib_durationとして利用することができます。
Definition: DateTime.h:69
TimeSpan & operator*=(int i) noexcept
時間をi で乗算します。
Definition: DateTime.h:179
TimeValue ToTimeValue() const noexcept
TimeValueオブジェクトに変換します。
Definition: DateTime.h:125
bool operator>(const DateTime &rhs) const noexcept
rhs より未来の時刻ならtrueを返します。
Definition: DateTime.h:364
bool operator==(const TimeSpan &rhs) const noexcept
同じ時間ならばtrueを返します。
Definition: DateTime.h:190
int64_t ToMilliSeconds() const noexcept
時間をミリ秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:138
int min
分(0-59)
Definition: DateTime.h:255
TimeSpan & operator-=(const TimeSpan &rhs) noexcept
時間を減算します。
Definition: DateTime.h:175
static bool IsLeapYear(int year) noexcept
閏年かどうかをチェックします。
Definition: DateTime.h:395
int year
年(1-9999)
Definition: DateTime.h:251
bool operator<=(const TimeSpan &rhs) const noexcept
rhs と同じかより小さければtrueを返します。
Definition: DateTime.h:202
errno_t ToW3cDtf(char(&str)[32]) const noexcept
ToW3cDtf(str, TimeSpan()) を呼び出します。
Definition: DateTime.h:332
errno_t nlib_ticktime(nlib_duration *t)
ブートからの経過時間を取得します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:173
#define NLIB_NONNULL_1
1番目の引数にNULLを指定することができないことを示します。
int64_t ToSeconds() const noexcept
時間を秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:135
TimeSpan & operator+=(const TimeSpan &rhs) noexcept
時間を加算します。
Definition: DateTime.h:171
TimeSpan operator*(const TimeSpan &lhs, double d) noexcept
rhs を d 倍します。
Definition: DateTime.h:243
int ToHours() const noexcept
時間を一時間単位の値として返します。端数は切り捨てられます。
Definition: DateTime.h:129
int msec
ミリ秒(0-999)
Definition: DateTime.h:257
bool operator<=(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:84
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価ならば、trueを返します。
Definition: NMalloc.h:123
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価でなければ、trueを返します。
Definition: NMalloc.h:128
int64_t nlib_time
1970/01/01を起点(0)としてから100ns刻みで時刻を表現する型です。64bit符号付き整数です。 ...
Definition: Platform.h:755
bool operator>=(const TimeSpan &rhs) const noexcept
rhs と同じかより大きければtrueを返します。
Definition: DateTime.h:205
errno_t ToRfc2822(char(&str)[32]) const noexcept
ToRfc2822(str, TimeSpan()) を呼び出します。
Definition: DateTime.h:341
DateTime operator+(const DateTime &lhs, const TimeSpan &rhs) noexcept
lhs から rhs だけ未来の時刻を返します。
Definition: DateTime.h:466
日時を表すクラスです。
Definition: DateTime.h:261
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:87
void ToTimeSpec(struct timespec *tm) const noexcept
timespec構造体の値に変換します。
Definition: DateTime.h:154
uint64_t GetTickTime() noexcept
システムを起動した後の経過時間をミリ秒単位で返します。
Definition: DateTime.h:41
TimeSpan(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:151
bool operator>=(const DateTime &rhs) const noexcept
rhs と同じかより未来の時刻ならtrueを返します。
Definition: DateTime.h:370
TimeValue operator+() const noexcept
単項演算子です。
Definition: DateTime.h:66
bool operator!=(const TimeSpan &rhs) const noexcept
異なる時間ならばtrueを返します。
Definition: DateTime.h:193
int hour
時(0-23)
Definition: DateTime.h:254
bool operator>(const TimeSpan &rhs) const noexcept
rhs より大きければtrueを返します。
Definition: DateTime.h:199
int sec
秒(0-59)
Definition: DateTime.h:256
TimeValue operator-() const noexcept
単項演算子です。
Definition: DateTime.h:65
constexpr TimeSpan() noexcept
時間を 0 で初期化するコンストラクタです。
Definition: DateTime.h:108
int ToDays() const noexcept
時間を日数にして返します。端数は切り捨てられます。
Definition: DateTime.h:126
Week
曜日を表す定数です。
Definition: DateTime.h:264
void ToTimeSpec(struct timespec *tm) const noexcept
timespec構造体の値に変換します。
Definition: DateTime.h:377
日時情報をDateTimeに設定したりDateTimeから取得するための構造体です。
Definition: DateTime.h:250
TimeSpan operator-(const DateTime &lhs, const DateTime &rhs) noexcept
時刻rhs から時刻lhs までの時間を返します。
Definition: DateTime.h:478
errno_t GetNintendoTime(int64_t *t) noexcept
2000/01/01を起点とした経過時間をミリ秒単位で返します。
Definition: DateTime.h:30
bool operator>=(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:87
TimeSpan operator+() const noexcept
単項演算子です。
Definition: DateTime.h:189
errno_t nlib_epochtime(nlib_time *t)
現在時刻を取得します。
bool operator<=(const DateTime &rhs) const noexcept
rhs と同じかより過去の時刻ならtrueを返します。
Definition: DateTime.h:367
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:99
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:93
開発環境別の設定が書かれるファイルです。
int usec
マイクロ秒(0-999)
Definition: DateTime.h:258
TimeSpan operator-() const noexcept
単項演算子です。
Definition: DateTime.h:188
bool operator==(const DateTime &rhs) const noexcept
rhs と同一時刻ならばtrueを返します。
Definition: DateTime.h:355
bool operator>(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:81
constexpr TimeSpan(int days) noexcept
期間として日数を指定して初期化します。
Definition: DateTime.h:110
int month
月(1-12)
Definition: DateTime.h:252
bool operator<(const TimeSpan &rhs) const noexcept
rhs より小さければtrueを返します。
Definition: DateTime.h:196
TimeSpan(const TimeValue &rhs) noexcept
TimeValue オブジェクトを用いて初期化します。
Definition: DateTime.h:109
TimeValue ToTimeValue() const noexcept
TimeValueオブジェクトを返します。
Definition: DateTime.h:302
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:224
時間を表すクラスです。
Definition: DateTime.h:106
constexpr DateTime() noexcept
デフォルトコンストラクタです。無効な時刻で初期化します。
Definition: DateTime.h:276
bool operator!=(const DateTime &rhs) const noexcept
rhs と同一時刻でないならtrueを返します。
Definition: DateTime.h:358
constexpr TimeSpan(int days, int seconds) noexcept
期間として日数と秒を指定して初期化します。
Definition: DateTime.h:112
constexpr TimeValue() noexcept
デフォルトコンストラクタです。
Definition: DateTime.h:51
int64_t ToMicroSeconds() const noexcept
時間をマイクロ秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:141
constexpr TimeValue(int64_t tick_) noexcept
nlib_time, nlib_durationの値を引数にして初期化します。
Definition: DateTime.h:52
TimeSpan & operator*=(double d) noexcept
時間をd で乗算します。
Definition: DateTime.h:183
constexpr TimeSpan(int days, int seconds, int milliseconds, int microseconds=0) noexcept
期間として日数,秒,ミリ秒,マイクロ秒を指定して初期化します。
Definition: DateTime.h:115
64bitの符号付き整数をラップするクラスです。
Definition: DateTime.h:50
bool operator<(const DateTime &rhs) const noexcept
rhs より過去の時刻ならtrueを返します。
Definition: DateTime.h:361
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
TimeValue & operator-=(const TimeValue &rhs) noexcept
減算します。
Definition: DateTime.h:58
DateTime(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:374
int64_t nlib_duration
100ns刻みで時間を表現する型です。64bit符号付き整数です。
Definition: Platform.h:757
int64_t ToMinutes() const noexcept
時間を分数にして返します。端数は切り捨てられます。
Definition: DateTime.h:132
TimeValue & operator+=(const TimeValue &rhs) noexcept
加算します。
Definition: DateTime.h:54
errno_t Init(const TimeValue &tv) noexcept
TimeValue構造体を用いて日時を初期化します。無効な日時が与えられた場合はEINVALを返します。 ...
Definition: DateTime.h:283
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37