Kiwano Engine v1.3.x
Time.h
1// Copyright (c) 2016-2018 Kiwano - Nomango
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21#pragma once
22#include <kiwano/core/Duration.h>
23#include <ctime>
24
25namespace kiwano
26{
27
41struct KGE_API Time
42{
43 Time();
44
48 bool IsZero() const;
49
52 static Time Now() noexcept;
53
54 const Duration operator-(const Time&) const;
55
56 const Time operator+(const Duration&) const;
57 const Time operator-(const Duration&) const;
58
59 Time& operator+=(const Duration&);
60 Time& operator-=(const Duration&);
61
62private:
63 Time(int64_t ms);
64
65private:
66 int64_t dur_;
67};
68
73struct KGE_API ClockTime
74{
75 ClockTime();
76
80 bool IsZero() const;
81
84 int64_t GetTimeStamp() const;
85
88 int64_t GetMillisecondsSinceEpoch() const;
89
92 std::time_t GetCTime() const;
93
96 static ClockTime Now() noexcept;
97
100 static ClockTime FromTimeStamp(int64_t timestamp) noexcept;
101
102 const Duration operator-(const ClockTime&) const;
103
104 const ClockTime operator+(const Duration&) const;
105 const ClockTime operator-(const Duration&) const;
106
107 ClockTime& operator+=(const Duration&);
108 ClockTime& operator-=(const Duration&);
109
110private:
111 ClockTime(int64_t ms_since_epoch);
112
113private:
114 int64_t ms_since_epoch_;
115};
116
117inline bool Time::IsZero() const
118{
119 return dur_ == 0;
120}
121
122inline bool ClockTime::IsZero() const
123{
124 return ms_since_epoch_ == 0;
125}
126
127} // namespace kiwano
时钟时间
Definition: Time.h:74
bool IsZero() const
是否是零时
Definition: Time.h:122
时间段
Definition: Duration.h:48
时间
Definition: Time.h:42
bool IsZero() const
是否是零时
Definition: Time.h:117