nlib
DateTime.h
[詳解]
1 
2 #pragma once
3 #ifndef INCLUDE_NN_NLIB_DATETIME_H_
4 #define INCLUDE_NN_NLIB_DATETIME_H_
5 
6 #include "nn/nlib/Config.h"
7 
8 #ifdef NLIB_CXX11_STDLIB_CHRONO
9 #include <chrono> // NOLINT
10 #endif
11 
12 NLIB_NAMESPACE_BEGIN
13 
14 // writes the duration in milliseconds from 2000/01/01.
16 
18  NLIB_EINVAL_IFNULL(t);
19  nlib_time time;
20  errno_t e = nlib_epochtime(&time);
21  if (e != 0) return e;
22  // 1970/01/01 -> 2000/01/01(in milliseconds)
23  *t = time / 10000 - (10957LL * 24LL * 60LL * 60LL * 1000LL);
24  return 0;
25 }
26 
27 // returns in milliseconds after the system boot.
28 inline uint64_t GetTickTime() NLIB_NOEXCEPT {
29  nlib_time t;
30  (void)nlib_ticktime(&t);
31  return static_cast<uint64_t>(t / 10000);
32 }
33 
34 // NOTE:
35 // TimeValue has a 64bit value, and 1 represents 100ns, 1ms is 10000.
36 // We can represent the time from A.D 1 to 9999 within 64bits.
39  NLIB_CEXPR explicit TimeValue(int64_t tick_) NLIB_NOEXCEPT : tick(tick_) {}
40 
42  tick += rhs.tick;
43  return *this;
44  }
46  tick -= rhs.tick;
47  return *this;
48  }
49  void Abs() NLIB_NOEXCEPT {
50  if (tick < 0) tick = -tick;
51  }
52  TimeValue operator-() const NLIB_NOEXCEPT { return TimeValue(-tick); }
53  TimeValue operator+() const NLIB_NOEXCEPT { return *this; }
54 
55  public:
56  int64_t tick; // nlib_time, nlib_duration
57 };
58 
59 inline bool operator==(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
60  return lhs.tick == rhs.tick;
61 }
62 inline bool operator<(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
63  return lhs.tick < rhs.tick;
64 }
65 inline bool operator!=(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
66  return !(lhs == rhs);
67 }
68 inline bool operator>(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
69  return rhs < lhs;
70 }
71 inline bool operator<=(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
72  return !(lhs > rhs);
73 }
74 inline bool operator>=(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
75  return !(lhs < rhs);
76 }
77 
78 inline TimeValue operator+(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
79  TimeValue result(lhs);
80  result += rhs;
81  return result;
82 }
83 
84 inline TimeValue operator-(const TimeValue& lhs, const TimeValue& rhs) NLIB_NOEXCEPT {
85  TimeValue result(lhs);
86  result -= rhs;
87  return result;
88 }
89 
90 // TimeValue(tick_1d) is 1 day
91 NLIB_CEXPR const int64_t tick_1d = (10LL * 1000 * 1000 * 60 * 60 * 24);
92 
94  public:
96  explicit TimeSpan(const TimeValue& rhs) NLIB_NOEXCEPT : value_(rhs) {}
97  NLIB_CEXPR explicit TimeSpan(int days) NLIB_NOEXCEPT
98  : value_(static_cast<int64_t>(days) * tick_1d) {}
99  NLIB_CEXPR TimeSpan(int days, int seconds) NLIB_NOEXCEPT
100  : value_(days* tick_1d + seconds*(10LL * 1000 * 1000)) {}
101  // TimeSpan(0, 0, 1) for 1msec
102  NLIB_CEXPR TimeSpan(int days, int seconds,
103  int milliseconds, int microseconds = 0) NLIB_NOEXCEPT
104  : value_(days* tick_1d + seconds*(10LL * 1000 * 1000) + milliseconds*(10LL * 1000) +
105  microseconds * 10LL) {}
106 
107  void Get(int* days,
108  int* seconds,
109  int* milliseconds,
110  int* microseconds) NLIB_NOEXCEPT;
111 
112  TimeValue ToTimeValue() const NLIB_NOEXCEPT { return value_; }
113  int ToDays() const NLIB_NOEXCEPT {
114  return static_cast<int>(value_.tick / (10LL * 1000 * 1000 * 60 * 60 * 24));
115  }
116  int ToHours() const NLIB_NOEXCEPT {
117  return static_cast<int>(value_.tick / (10LL * 1000 * 1000 * 60 * 60));
118  }
119  int64_t ToMinutes() const NLIB_NOEXCEPT {
120  return value_.tick / (10 * 1000 * 1000 * 60);
121  }
122  int64_t ToSeconds() const NLIB_NOEXCEPT {
123  return value_.tick / (10 * 1000 * 1000);
124  }
125  int64_t ToMilliSeconds() const NLIB_NOEXCEPT {
126  return value_.tick / (10 * 1000);
127  }
128  int64_t ToMicroSeconds() const NLIB_NOEXCEPT {
129  return value_.tick / (10);
130  }
131  template <class TIMEVAL>
132  void ToTimeVal(TIMEVAL* tv) const NLIB_NOEXCEPT {
133  int64_t usec = ToMicroSeconds();
134  int64_t sec = usec / (1000 * 1000);
135  tv->tv_sec = static_cast<time_t>(sec);
136  tv->tv_usec = static_cast<int32_t>(usec - sec * (1000 * 1000));
137  }
138  explicit TimeSpan(const struct timespec* tm) NLIB_NOEXCEPT {
139  NLIB_FROM_TIMESPEC(tm, value_.tick);
140  }
141  void ToTimeSpec(struct timespec* tm) const NLIB_NOEXCEPT {
142  NLIB_TO_TIMESPEC(tm, value_.tick);
143  }
144 #ifdef NLIB_CXX11_STDLIB_CHRONO
145  template <class Rep, class Period>
146  TimeSpan(const std::chrono::duration<Rep, Period>& rhs) { // NOLINT
147  auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(rhs);
148  value_.tick = static_cast<nlib_duration>(tmp.count() * 10);
149  }
150  template <class T>
151  T ToChrono() const {
152  auto tmp = std::chrono::microseconds(value_.tick / 10);
153  return std::chrono::duration_cast<T>(tmp);
154  }
155 #endif
156 
157  public:
158  TimeSpan& operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT {
159  value_ += rhs.value_;
160  return *this;
161  }
162  TimeSpan& operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT {
163  value_ -= rhs.value_;
164  return *this;
165  }
166  TimeSpan& operator*=(int i) NLIB_NOEXCEPT {
167  value_.tick *= i;
168  return *this;
169  }
170  TimeSpan& operator*=(double d) NLIB_NOEXCEPT {
171  value_.tick = static_cast<int64_t>(value_.tick * d);
172  return *this;
173  }
174  void Abs() NLIB_NOEXCEPT { value_.Abs(); }
175  TimeSpan operator-() const NLIB_NOEXCEPT { return TimeSpan(-value_); }
176  TimeSpan operator+() const NLIB_NOEXCEPT { return *this; }
177  bool operator==(const TimeSpan& rhs) const NLIB_NOEXCEPT {
178  return value_ == rhs.value_;
179  }
180  bool operator!=(const TimeSpan& rhs) const NLIB_NOEXCEPT {
181  return value_ != rhs.value_;
182  }
183  bool operator<(const TimeSpan& rhs) const NLIB_NOEXCEPT {
184  return value_ < rhs.value_;
185  }
186  bool operator>(const TimeSpan& rhs) const NLIB_NOEXCEPT {
187  return value_ > rhs.value_;
188  }
189  bool operator<=(const TimeSpan& rhs) const NLIB_NOEXCEPT {
190  return value_ <= rhs.value_;
191  }
192  bool operator>=(const TimeSpan& rhs) const NLIB_NOEXCEPT {
193  return value_ >= rhs.value_;
194  }
195 
196  private:
197  TimeValue value_;
198 };
199 
200 inline TimeSpan operator+(const TimeSpan& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
201  TimeSpan result(lhs);
202  result += rhs;
203  return result;
204 }
205 
206 inline TimeSpan operator-(const TimeSpan& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
207  TimeSpan result(lhs);
208  result -= rhs;
209  return result;
210 }
211 
212 inline TimeSpan operator*(int i, const TimeSpan& rhs) NLIB_NOEXCEPT {
213  TimeSpan result(rhs);
214  result *= i;
215  return result;
216 }
217 
218 inline TimeSpan operator*(double d, const TimeSpan& rhs) NLIB_NOEXCEPT {
219  TimeSpan result(rhs);
220  result *= d;
221  return result;
222 }
223 
224 inline TimeSpan operator*(const TimeSpan& lhs, int i) NLIB_NOEXCEPT {
225  TimeSpan result(lhs);
226  result *= i;
227  return result;
228 }
229 
230 inline TimeSpan operator*(const TimeSpan& lhs, double d) NLIB_NOEXCEPT {
231  TimeSpan result(lhs);
232  result *= d;
233  return result;
234 }
235 
236 // has year/month/day/hour/min/sec/msec/usec
238  int year;
239  int month;
240  int day;
241  int hour;
242  int min;
243  int sec;
244  int msec;
245  int usec;
246 };
247 
249  public:
250  // WEEK_SUNDAY -> WEEK_SATURDAY
251  enum Week {
252  WEEK_SUNDAY = 0,
259  WEEK_MAX
260  };
261 
262  public:
263  NLIB_CEXPR DateTime() NLIB_NOEXCEPT : value_(INT64_MIN) {}
264  // You can omit min/sec/msec/usec.
265  errno_t Init(int year, int month, int day, int hour = 0,
266  int min = 0, int sec = 0, int msec = 0,
267  int usec = 0) NLIB_NOEXCEPT;
268  errno_t Init(const DateTimeParams& rhs) NLIB_NOEXCEPT;
269  // nlib_epochtime(&t); dt.Init(TimeValue(t)); for example
270  errno_t Init(const TimeValue& tv) NLIB_NOEXCEPT {
271  value_ = tv;
272  return IsValid() ? 0 : EINVAL;
273  }
274  // you can pass null pointers
275  errno_t GetDay(
276  int* year,
277  int* month,
278  int* day) const NLIB_NOEXCEPT;
279  // you can pass null pointers
280  errno_t GetTime(
281  int* hour,
282  int* min,
283  int* sec,
284  int* msec,
285  int* usec) const NLIB_NOEXCEPT;
286  errno_t Get(
287  DateTimeParams* rhs) const NLIB_NOEXCEPT;
288 
289  TimeValue ToTimeValue() const NLIB_NOEXCEPT { return value_; }
290  bool IsValid() const NLIB_NOEXCEPT;
291 
292  // 01-01 becomes 0.
293  errno_t GetDayOfYear(int* nth) const NLIB_NOEXCEPT;
294  // Sunday -> 0(WEEK_SUNDAY), Saturday -> 6(WEEK_SATURDAY)
295  errno_t GetDayOfWeek(Week* week) const NLIB_NOEXCEPT;
296  // returns EINVAL on failure
297  errno_t Add(const TimeSpan& rhs) NLIB_NOEXCEPT;
298  // returns EINVAL on failure
299  errno_t AddYears(int value) NLIB_NOEXCEPT;
300  // returns EINVAL on failure
301  errno_t AddMonths(int value) NLIB_NOEXCEPT;
302  // returns EINVAL on failure
303  errno_t AddDays(double value) NLIB_NOEXCEPT;
304  // returns EINVAL on failure
305  errno_t AddHours(double value) NLIB_NOEXCEPT;
306  // returns EINVAL on failure
307  errno_t AddMinutes(double value) NLIB_NOEXCEPT;
308  // returns EINVAL on failure
309  errno_t AddSeconds(double value) NLIB_NOEXCEPT;
310  // returns EINVAL on failure
311  errno_t AddMilliSeconds(double value) NLIB_NOEXCEPT;
312  // returns EINVAL on failure
313  errno_t AddMicroSeconds(double value) NLIB_NOEXCEPT;
314 
315  // "1994-11-05T13:15:30Z" for example
316  errno_t ToW3cDtf(
317  char (&str)[32],
318  const TimeSpan& zone) const NLIB_NOEXCEPT;
320  char (&str)[32]) const NLIB_NOEXCEPT {
321  return ToW3cDtf(str, TimeSpan());
322  }
323 
324  // "Tue, 02 Sep 2014 10:51:34 +0900" for example
325  errno_t ToRfc2822(
326  char(&str) [32],
327  const TimeSpan& zone) const NLIB_NOEXCEPT;
329  char (&str)[32]) const NLIB_NOEXCEPT {
330  return ToRfc2822(str, TimeSpan());
331  }
332 
333  // "Wed Jan 02 02:03:45 1980\n" for example
334  errno_t ToAscTime(
335  char (&str)[26]) const NLIB_NOEXCEPT;
336 
337  NLIB_SAFE_BOOL(DateTime, IsValid())
338 
339  public:
340  DateTime& operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT;
341  DateTime& operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT;
342  bool operator==(const DateTime& rhs) const NLIB_NOEXCEPT {
343  return value_ == rhs.value_;
344  }
345  bool operator!=(const DateTime& rhs) const NLIB_NOEXCEPT {
346  return value_ != rhs.value_;
347  }
348  bool operator<(const DateTime& rhs) const NLIB_NOEXCEPT {
349  return value_ < rhs.value_;
350  }
351  bool operator>(const DateTime& rhs) const NLIB_NOEXCEPT {
352  return value_ > rhs.value_;
353  }
354  bool operator<=(const DateTime& rhs) const NLIB_NOEXCEPT {
355  return value_ <= rhs.value_;
356  }
357  bool operator>=(const DateTime& rhs) const NLIB_NOEXCEPT {
358  return value_ >= rhs.value_;
359  }
360 
361  explicit DateTime(const struct timespec* tm) NLIB_NOEXCEPT {
362  NLIB_FROM_TIMESPEC(tm, value_.tick);
363  }
364  void ToTimeSpec(struct timespec* tm) const NLIB_NOEXCEPT {
365  NLIB_TO_TIMESPEC(tm, value_.tick);
366  }
367 #ifdef NLIB_CXX11_STDLIB_CHRONO
368  template <class Clock, class Duration>
369  errno_t Init(const std::chrono::time_point<Clock, Duration>& rhs) {
370  auto tmp = std::chrono::duration_cast<std::chrono::microseconds>(rhs.time_since_epoch());
371  value_.tick = static_cast<nlib_duration>(tmp.count() * 10);
372  return 0;
373  }
374  template <class T>
375  T ToChrono() const {
376  auto tmp = std::chrono::microseconds(value_.tick / 10);
377  return T(tmp);
378  }
379 #endif
380 
381  public:
382  static bool IsLeapYear(int year) NLIB_NOEXCEPT {
383  return ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0);
384  }
385  static errno_t GetNow(DateTime* p) NLIB_NOEXCEPT;
386  // January has 31 days for example
387  static int GetDaysInMonth(int year, int month) NLIB_NOEXCEPT;
388  // can parse W3CDTF, RFC2822, or ASCTIME
389  static errno_t Parse(
390  const char* str,
391  DateTime* dt,
392  TimeSpan* delta) NLIB_NOEXCEPT NLIB_NONNULL_1;
393 
394  private:
395  TimeValue value_;
396 };
397 
398 inline errno_t DateTime::Init(const DateTimeParams& rhs) NLIB_NOEXCEPT {
399  return this->Init(rhs.year, rhs.month, rhs.day, rhs.hour, rhs.min, rhs.sec, rhs.msec, rhs.usec);
400 }
401 
402 inline errno_t DateTime::Add(const TimeSpan& rhs) NLIB_NOEXCEPT {
403  value_ += rhs.ToTimeValue();
404  return IsValid() ? 0 : ERANGE;
405 }
406 
407 inline errno_t DateTime::AddDays(double value) NLIB_NOEXCEPT {
408  TimeSpan d(1);
409  d *= value;
410  return this->Add(d);
411 }
412 
413 inline errno_t DateTime::AddHours(double value) NLIB_NOEXCEPT {
414  TimeSpan d(0, 60 * 60);
415  d *= value;
416  return this->Add(d);
417 }
418 
419 inline errno_t DateTime::AddMinutes(double value) NLIB_NOEXCEPT {
420  TimeSpan d(0, 60);
421  d *= value;
422  return this->Add(d);
423 }
424 
425 inline errno_t DateTime::AddSeconds(double value) NLIB_NOEXCEPT {
426  TimeSpan d(0, 1);
427  d *= value;
428  return this->Add(d);
429 }
430 
431 inline errno_t DateTime::AddMilliSeconds(double value) NLIB_NOEXCEPT {
432  TimeSpan d(0, 0, 1);
433  d *= value;
434  return this->Add(d);
435 }
436 
437 inline errno_t DateTime::AddMicroSeconds(double value) NLIB_NOEXCEPT {
438  TimeSpan d(0, 0, 0, 1);
439  d *= value;
440  return this->Add(d);
441 }
442 
443 inline DateTime& DateTime::operator+=(const TimeSpan& rhs) NLIB_NOEXCEPT {
444  this->Add(rhs);
445  return *this;
446 }
447 
448 inline DateTime& DateTime::operator-=(const TimeSpan& rhs) NLIB_NOEXCEPT {
449  *this += (-rhs);
450  return *this;
451 }
452 
453 inline DateTime operator+(const DateTime& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
454  DateTime tmp(lhs);
455  tmp += rhs;
456  return tmp;
457 }
458 
459 inline DateTime operator-(const DateTime& lhs, const TimeSpan& rhs) NLIB_NOEXCEPT {
460  DateTime tmp(lhs);
461  tmp -= rhs;
462  return tmp;
463 }
464 
465 inline TimeSpan operator-(const DateTime& lhs, const DateTime& rhs) NLIB_NOEXCEPT {
466  return TimeSpan(lhs.ToTimeValue() - rhs.ToTimeValue());
467 }
468 
469 NLIB_NAMESPACE_END
470 
471 #endif // INCLUDE_NN_NLIB_DATETIME_H_
bool operator<(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:62
int64_t tick
nlib_time, nlib_durationとして利用することができます。
Definition: DateTime.h:56
TimeSpan & operator*=(int i) noexcept
時間をi で乗算します。
Definition: DateTime.h:166
TimeValue ToTimeValue() const noexcept
TimeValueオブジェクトに変換します。
Definition: DateTime.h:112
bool operator>(const DateTime &rhs) const noexcept
rhs より未来の時刻ならtrueを返します。
Definition: DateTime.h:351
bool operator==(const TimeSpan &rhs) const noexcept
同じ時間ならばtrueを返します。
Definition: DateTime.h:177
int64_t ToMilliSeconds() const noexcept
時間をミリ秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:125
int min
分(0-59)
Definition: DateTime.h:242
TimeSpan & operator-=(const TimeSpan &rhs) noexcept
時間を減算します。
Definition: DateTime.h:162
static bool IsLeapYear(int year) noexcept
閏年かどうかをチェックします。
Definition: DateTime.h:382
int year
年(1-9999)
Definition: DateTime.h:238
bool operator<=(const TimeSpan &rhs) const noexcept
rhs と同じかより小さければtrueを返します。
Definition: DateTime.h:189
errno_t ToW3cDtf(char(&str)[32]) const noexcept
ToW3cDtf(str, TimeSpan()) を呼び出します。
Definition: DateTime.h:319
errno_t nlib_ticktime(nlib_duration *t)
ブートからの経過時間を取得します。
#define NLIB_SAFE_BOOL(class_name, exp)
クラス内に安全なoperator bool()を定義します。 可能であればC++11のexplicit boolを利用します。 ...
Definition: Config.h:160
#define NLIB_NONNULL_1
1番目の引数にNULLを指定することができないことを示します。
Definition: Platform_unix.h:77
int64_t ToSeconds() const noexcept
時間を秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:122
TimeSpan & operator+=(const TimeSpan &rhs) noexcept
時間を加算します。
Definition: DateTime.h:158
TimeSpan operator*(const TimeSpan &lhs, double d) noexcept
rhs を d 倍します。
Definition: DateTime.h:230
int ToHours() const noexcept
時間を一時間単位の値として返します。端数は切り捨てられます。
Definition: DateTime.h:116
int msec
ミリ秒(0-999)
Definition: DateTime.h:244
bool operator<=(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:71
bool operator==(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価ならば、trueを返します。
Definition: NMalloc.h:110
bool operator!=(const HeapHash &rhs, const HeapHash &lhs)
2つのサマリを比較して等価でなければ、trueを返します。
Definition: NMalloc.h:115
int64_t nlib_time
1970/01/01を起点(0)としてから100ns刻みで時刻を表現する型です。64bit符号付き整数です。 ...
Definition: Platform.h:744
bool operator>=(const TimeSpan &rhs) const noexcept
rhs と同じかより大きければtrueを返します。
Definition: DateTime.h:192
errno_t ToRfc2822(char(&str)[32]) const noexcept
ToRfc2822(str, TimeSpan()) を呼び出します。
Definition: DateTime.h:328
DateTime operator+(const DateTime &lhs, const TimeSpan &rhs) noexcept
lhs から rhs だけ未来の時刻を返します。
Definition: DateTime.h:453
日時を表すクラスです。
Definition: DateTime.h:248
#define NLIB_VIS_PUBLIC
関数やクラス等のシンボルをライブラリの外部に公開します。
Definition: Platform_unix.h:61
void ToTimeSpec(struct timespec *tm) const noexcept
timespec構造体の値に変換します。
Definition: DateTime.h:141
uint64_t GetTickTime() noexcept
システムを起動した後の経過時間をミリ秒単位で返します。
Definition: DateTime.h:28
TimeSpan(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:138
bool operator>=(const DateTime &rhs) const noexcept
rhs と同じかより未来の時刻ならtrueを返します。
Definition: DateTime.h:357
TimeValue operator+() const noexcept
単項演算子です。
Definition: DateTime.h:53
bool operator!=(const TimeSpan &rhs) const noexcept
異なる時間ならばtrueを返します。
Definition: DateTime.h:180
int hour
時(0-23)
Definition: DateTime.h:241
bool operator>(const TimeSpan &rhs) const noexcept
rhs より大きければtrueを返します。
Definition: DateTime.h:186
int sec
秒(0-59)
Definition: DateTime.h:243
TimeValue operator-() const noexcept
単項演算子です。
Definition: DateTime.h:52
constexpr TimeSpan() noexcept
時間を 0 で初期化するコンストラクタです。
Definition: DateTime.h:95
int ToDays() const noexcept
時間を日数にして返します。端数は切り捨てられます。
Definition: DateTime.h:113
Week
曜日を表す定数です。
Definition: DateTime.h:251
void ToTimeSpec(struct timespec *tm) const noexcept
timespec構造体の値に変換します。
Definition: DateTime.h:364
日時情報をDateTimeに設定したりDateTimeから取得するための構造体です。
Definition: DateTime.h:237
TimeSpan operator-(const DateTime &lhs, const DateTime &rhs) noexcept
時刻rhs から時刻lhs までの時間を返します。
Definition: DateTime.h:465
errno_t GetNintendoTime(int64_t *t) noexcept
2000/01/01を起点とした経過時間をミリ秒単位で返します。
Definition: DateTime.h:17
bool operator>=(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:74
TimeSpan operator+() const noexcept
単項演算子です。
Definition: DateTime.h:176
errno_t nlib_epochtime(nlib_time *t)
現在時刻を取得します。
bool operator<=(const DateTime &rhs) const noexcept
rhs と同じかより過去の時刻ならtrueを返します。
Definition: DateTime.h:354
#define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。
Definition: Config.h:86
#define NLIB_CEXPR
利用可能であればconstexprが定義されます。そうでない場合は空文字列です。
Definition: Config.h:80
開発環境別の設定が書かれるファイルです。
int usec
マイクロ秒(0-999)
Definition: DateTime.h:245
TimeSpan operator-() const noexcept
単項演算子です。
Definition: DateTime.h:175
bool operator==(const DateTime &rhs) const noexcept
rhs と同一時刻ならばtrueを返します。
Definition: DateTime.h:342
bool operator>(const TimeValue &lhs, const TimeValue &rhs) noexcept
比較演算子です。
Definition: DateTime.h:68
constexpr TimeSpan(int days) noexcept
期間として日数を指定して初期化します。
Definition: DateTime.h:97
int month
月(1-12)
Definition: DateTime.h:239
bool operator<(const TimeSpan &rhs) const noexcept
rhs より小さければtrueを返します。
Definition: DateTime.h:183
TimeSpan(const TimeValue &rhs) noexcept
TimeValue オブジェクトを用いて初期化します。
Definition: DateTime.h:96
TimeValue ToTimeValue() const noexcept
TimeValueオブジェクトを返します。
Definition: DateTime.h:289
#define NLIB_FINAL
利用可能であればfinalが定義されます。そうでない場合は空文字列です。
Definition: Config.h:211
時間を表すクラスです。
Definition: DateTime.h:93
constexpr DateTime() noexcept
デフォルトコンストラクタです。無効な時刻で初期化します。
Definition: DateTime.h:263
bool operator!=(const DateTime &rhs) const noexcept
rhs と同一時刻でないならtrueを返します。
Definition: DateTime.h:345
constexpr TimeSpan(int days, int seconds) noexcept
期間として日数と秒を指定して初期化します。
Definition: DateTime.h:99
constexpr TimeValue() noexcept
デフォルトコンストラクタです。
Definition: DateTime.h:38
int64_t ToMicroSeconds() const noexcept
時間をマイクロ秒数にして返します。端数は切り捨てられます。
Definition: DateTime.h:128
constexpr TimeValue(int64_t tick_) noexcept
nlib_time, nlib_durationの値を引数にして初期化します。
Definition: DateTime.h:39
TimeSpan & operator*=(double d) noexcept
時間をd で乗算します。
Definition: DateTime.h:170
constexpr TimeSpan(int days, int seconds, int milliseconds, int microseconds=0) noexcept
期間として日数,秒,ミリ秒,マイクロ秒を指定して初期化します。
Definition: DateTime.h:102
64bitの符号付き整数をラップするクラスです。
Definition: DateTime.h:37
bool operator<(const DateTime &rhs) const noexcept
rhs より過去の時刻ならtrueを返します。
Definition: DateTime.h:348
#define NLIB_NONNULL
全ての引数にNULLを指定することができないことを示します。
Definition: Platform_unix.h:76
TimeValue & operator-=(const TimeValue &rhs) noexcept
減算します。
Definition: DateTime.h:45
DateTime(const struct timespec *tm) noexcept
timespec構造体からオブジェクトを構築します。
Definition: DateTime.h:361
int64_t nlib_duration
100ns刻みで時間を表現する型です。64bit符号付き整数です。
Definition: Platform.h:746
int64_t ToMinutes() const noexcept
時間を分数にして返します。端数は切り捨てられます。
Definition: DateTime.h:119
TimeValue & operator+=(const TimeValue &rhs) noexcept
加算します。
Definition: DateTime.h:41
errno_t Init(const TimeValue &tv) noexcept
TimeValue構造体を用いて日時を初期化します。無効な日時が与えられた場合はEINVALを返します。 ...
Definition: DateTime.h:270
int errno_t
intのtypedefで、戻り値としてPOSIXのエラー値を返すことを示します。
Definition: NMalloc.h:24