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 <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
nlib_time, nlib_durationとして利用することができます。
Definition: DateTime.h:70
TimeSpan & operator*=(int i) noexcept
時間をi で乗算します。
Definition: DateTime.h:170
TimeValue ToTimeValue() const noexcept
TimeValueオブジェクトに変換します。
Definition: DateTime.h:116
int64_t ToMilliSeconds() const noexcept
時間をミリ秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:129
int min
分(0-59)
Definition: DateTime.h:240
TimeSpan & operator-=(const TimeSpan &rhs) noexcept
時間を減算します。
Definition: DateTime.h:166
static constexpr bool IsLeapYear(int year) noexcept
閏年かどうかをチェックします。
Definition: DateTime.h:369
int year
年(1-9999)
Definition: DateTime.h:236
errno_t ToW3cDtf(char(&str)[32]) const noexcept
ToW3cDtf(str, TimeSpan()) を呼び出します。
Definition: DateTime.h:325
errno_t nlib_ticktime(nlib_duration *t)
ブートからの経過時間を取得します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:194
#define NLIB_NONNULL_1
1番目の引数にNULLを指定することができないことを示します。
int64_t ToSeconds() const noexcept
時間を秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:126
TimeSpan & operator+=(const TimeSpan &rhs) noexcept
時間を加算します。
Definition: DateTime.h:162
TimeSpan operator*(const TimeSpan &lhs, double d) noexcept
rhs を d 倍します。
Definition: DateTime.h:228
int ToHours() const noexcept
時間を一時間単位の値として返します。端数は切り捨てられます。
Definition: DateTime.h:120
int msec
ミリ秒(0-999)
Definition: DateTime.h:242
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価ならば、trueを返します。
Definition: NMalloc.h:149
int64_t nlib_time
1970/01/01を起点(0)としてから100ns刻みで時刻を表現する型です。64bit符号付き整数です。 ...
Definition: Platform.h:457
errno_t ToRfc2822(char(&str)[32]) const noexcept
ToRfc2822(str, TimeSpan()) を呼び出します。
Definition: DateTime.h:334
DateTime operator+(const DateTime &lhs, const TimeSpan &rhs) noexcept
lhs から rhs だけ未来の時刻を返します。
Definition: DateTime.h:461
日時を表すクラスです。
Definition: DateTime.h:246
static bool IsRfc3339(const nlib_utf8_t *str) noexcept
IsRfc3339(str, str + strlen(str))を実行します。
Definition: DateTime.h:387
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:89
void ToTimeSpec(struct timespec *tm) const noexcept
timespec構造体の値に変換します。
Definition: DateTime.h:145
uint64_t GetTickTime() noexcept
システムを起動した後の経過時間をミリ秒単位で返します。
Definition: DateTime.h:42
TimeSpan(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:142
TimeValue operator+() const noexcept
単項演算子です。
Definition: DateTime.h:67
int hour
時(0-23)
Definition: DateTime.h:239
int sec
秒(0-59)
Definition: DateTime.h:241
#define NLIB_NONNULL_2
2番目の引数にNULLを指定することができないことを示します。
TimeValue operator-() const noexcept
単項演算子です。
Definition: DateTime.h:66
constexpr TimeSpan() noexcept
時間を 0 で初期化するコンストラクタです。
Definition: DateTime.h:99
int ToDays() const noexcept
時間を日数にして返します。端数は切り捨てられます。
Definition: DateTime.h:117
Week
曜日を表す定数です。
Definition: DateTime.h:249
void ToTimeSpec(struct timespec *tm) const noexcept
timespec構造体の値に変換します。
Definition: DateTime.h:351
日時情報をDateTimeに設定したりDateTimeから取得するための構造体です。
Definition: DateTime.h:235
TimeSpan operator-(const DateTime &lhs, const DateTime &rhs) noexcept
時刻rhs から時刻lhs までの時間を返します。
Definition: DateTime.h:473
errno_t GetNintendoTime(int64_t *t) noexcept
2000/01/01を起点とした経過時間をミリ秒単位で返します。
Definition: DateTime.h:31
TimeSpan operator+() const noexcept
単項演算子です。
Definition: DateTime.h:180
errno_t nlib_epochtime(nlib_time *t)
現在時刻を取得します。
bool operator<(const DateTime &lhs, const DateTime &rhs) noexcept
lhsがrhsより過去の時刻ならtrueを返します。
Definition: DateTime.h:401
static errno_t Parse(const char *str, DateTime *dt, TimeSpan *delta)
ヌル終端する文字列をパースします。ヌル終端する前にパースされない文字に到達した場合へエラーになります...
Definition: DateTime.h:381
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:105
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:107
開発環境別の設定が書かれるファイルです。
int usec
マイクロ秒(0-999)
Definition: DateTime.h:243
TimeSpan operator-() const noexcept
単項演算子です。
Definition: DateTime.h:179
constexpr TimeSpan(int days) noexcept
期間として日数を指定して初期化します。
Definition: DateTime.h:101
size_t nlib_strlen(const char *s)
内部でstrlen()を呼び出します。独自の実装が動作する場合もあります。
int month
月(1-12)
Definition: DateTime.h:237
TimeSpan(const TimeValue &rhs) noexcept
TimeValue オブジェクトを用いて初期化します。
Definition: DateTime.h:100
TimeValue ToTimeValue() const noexcept
TimeValueオブジェクトを返します。
Definition: DateTime.h:295
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:245
時間を表すクラスです。
Definition: DateTime.h:97
constexpr DateTime() noexcept
デフォルトコンストラクタです。無効な時刻で初期化します。
Definition: DateTime.h:269
constexpr TimeSpan(int days, int seconds) noexcept
期間として日数と秒を指定して初期化します。
Definition: DateTime.h:103
constexpr TimeValue() noexcept
デフォルトコンストラクタです。
Definition: DateTime.h:52
int64_t ToMicroSeconds() const noexcept
時間をマイクロ秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:132
constexpr TimeValue(int64_t tick_) noexcept
nlib_time, nlib_durationの値を引数にして初期化します。
Definition: DateTime.h:53
TimeSpan & operator*=(double d) noexcept
時間をd で乗算します。
Definition: DateTime.h:174
constexpr TimeSpan(int days, int seconds, int milliseconds, int microseconds=0) noexcept
期間として日数,秒,ミリ秒,マイクロ秒を指定して初期化します。
Definition: DateTime.h:106
64bitの符号付き整数をラップするクラスです。
Definition: DateTime.h:51
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
TimeValue & operator-=(const TimeValue &rhs) noexcept
減算します。
Definition: DateTime.h:59
DateTime(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:348
int64_t nlib_duration
100ns刻みで時間を表現する型です。64bit符号付き整数です。
Definition: Platform.h:459
int64_t ToMinutes() const noexcept
時間を分数にして返します。端数は切り捨てられます。
Definition: DateTime.h:123
TimeValue & operator+=(const TimeValue &rhs) noexcept
加算します。
Definition: DateTime.h:55
char nlib_utf8_t
charのtypedefです。文字列がUTF-8であることを示します。
Definition: Platform.h:308
errno_t Init(const TimeValue &tv) noexcept
TimeValue構造体を用いて日時を初期化します。無効な日時が与えられた場合はEINVALを返します。 ...
Definition: DateTime.h:276
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:37