MGL(Win32)
読み取り中…
検索中…
一致する文字列を見つけられません
mgl_chrono_defs.h
[詳解]
1// SPDX-License-Identifier: Zlib
2/* ------------------------------------------------------------------------- */
9/* ------------------------------------------------------------------------- */
10
11#ifndef INCGUARD_MGL_CHRONO_DEFS_H_1614107959
12#define INCGUARD_MGL_CHRONO_DEFS_H_1614107959
13
14#include <cstdint>
15#include <ctime>
16
17#include <mgl/mgl_environment.h>
18
19namespace MGL::System
20{
22using EpochTime = time_t;
23static_assert(sizeof(EpochTime) >= 8); // 64ビット以上を必須にする
24
27{
28 uint16_t year;
29 uint8_t month;
30 uint8_t day;
31 uint8_t hour;
32 uint8_t minute;
33 uint8_t second;
35
37 constexpr DateTime() noexcept
38 : year(1970)
39 , month(1)
40 , day(1)
41 , hour(0)
42 , minute(0)
43 , second(0)
45 {}
46
47 /* ------------------------------------------------------------------------- */
53 /* ------------------------------------------------------------------------- */
54 DateTime(EpochTime epochTime, int32_t inTimeDifference = 0) noexcept
55 : timeDifference(inTimeDifference)
56 {
57 epochTime += inTimeDifference;
58
59 // TODO:
60#if defined(MGL_TARGET_WIN32)
61 struct tm temp;
62 gmtime_s(&temp, &epochTime);
63 struct tm *time = &temp;
64#else
65 struct tm *time = gmtime(&epochTime);
66#endif
67
68 year = static_cast<uint16_t>(time->tm_year + 1900);
69 month = static_cast<uint8_t>(time->tm_mon + 1);
70 day = static_cast<uint8_t>(time->tm_mday);
71 hour = static_cast<uint8_t>(time->tm_hour);
72 minute = static_cast<uint8_t>(time->tm_min);
73 second = static_cast<uint8_t>(time->tm_sec);
74 }
75};
76
78using TickTime = uint64_t;
79
80} // namespace MGL::System
81
82#endif // INCGUARD_MGL_CHRONO_DEFS_H_1614107959
83
84// vim: et ts=4 sw=4 sts=4
time_t EpochTime
UNIXエポック時間を表す型
Definition mgl_chrono_defs.h:22
uint64_t TickTime
Tickタイムを表す型
Definition mgl_chrono_defs.h:78
MGL 環境定義
日付と時刻
Definition mgl_chrono_defs.h:27
DateTime(EpochTime epochTime, int32_t inTimeDifference=0) noexcept
エポック時間から初期化
Definition mgl_chrono_defs.h:54
uint8_t day
Definition mgl_chrono_defs.h:30
int32_t timeDifference
時差(秒)
Definition mgl_chrono_defs.h:34
uint8_t second
Definition mgl_chrono_defs.h:33
uint16_t year
Definition mgl_chrono_defs.h:28
uint8_t hour
時間
Definition mgl_chrono_defs.h:31
uint8_t month
Definition mgl_chrono_defs.h:29
constexpr DateTime() noexcept
コンストラクタ
Definition mgl_chrono_defs.h:37
uint8_t minute
Definition mgl_chrono_defs.h:32