-
Notifications
You must be signed in to change notification settings - Fork 1
/
timer.cpp
44 lines (34 loc) · 808 Bytes
/
timer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "timer.h"
#include <iostream>
Timer::Timer() {
_timeRemaining = _defaultTimeout;
}
void Timer::Start() {
_finishTime = std::chrono::system_clock::now() + _timeRemaining;
_running = true;
}
void Timer::Pause() {
_running = false;
}
void Timer::Reset() {
_timeRemaining = _defaultTimeout;
_running = false;
}
std::chrono::seconds Timer::Remaining() {
return _timeRemaining;
}
bool Timer::IsRunning() {
return _running;
}
bool Timer::CheckTimer() {
if (!_running) {
return false;
}
_timeRemaining = std::chrono::duration_cast<std::chrono::seconds>(
_finishTime - std::chrono::system_clock::now());
if (_timeRemaining <= std::chrono::seconds(0)) {
_running = false;
return true;
}
return false;
}