nlib
DateTime.h
[詳解]
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,
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
比較演算子です。
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:372
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:403
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:340
errno_t nlib_ticktime(nlib_duration *t)
ブートからの経過時間を取得します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:178
#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:145
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価でなければ、trueを返します。
Definition: NMalloc.h:150
int64_t nlib_time
1970/01/01を起点(0)としてから100ns刻みで時刻を表現する型です。64bit符号付き整数です。 ...
Definition: Platform.h:450
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:349
DateTime operator+(const DateTime &lhs, const TimeSpan &rhs) noexcept
lhs から rhs だけ未来の時刻を返します。
Definition: DateTime.h:474
日時を表すクラスです。
Definition: DateTime.h:261
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
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:378
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:385
日時情報をDateTimeに設定したりDateTimeから取得するための構造体です。
Definition: DateTime.h:250
TimeSpan operator-(const DateTime &lhs, const DateTime &rhs) noexcept
時刻rhs から時刻lhs までの時間を返します。
Definition: DateTime.h:486
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:375
#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:363
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:310
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:229
時間を表すクラスです。
Definition: DateTime.h:106
constexpr DateTime() noexcept
デフォルトコンストラクタです。無効な時刻で初期化します。
Definition: DateTime.h:284
bool operator!=(const DateTime &rhs) const noexcept
rhs と同一時刻でないならtrueを返します。
Definition: DateTime.h:366
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:369
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
TimeValue & operator-=(const TimeValue &rhs) noexcept
減算します。
Definition: DateTime.h:58
DateTime(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:382
int64_t nlib_duration
100ns刻みで時間を表現する型です。64bit符号付き整数です。
Definition: Platform.h:452
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:291
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37