This repository was archived by the owner on Feb 3, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimer.cpp
More file actions
84 lines (69 loc) · 1.6 KB
/
Timer.cpp
File metadata and controls
84 lines (69 loc) · 1.6 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include "Timer.h"
#include <windows.h>
#include <time.h>
#include <cstdio>
#include <iostream>
///Helpers///
int Timer::getCurrentTime()const{
SYSTEMTIME st;
GetSystemTime(&st);
return ((st.wHour + 2) * 3600) + (st.wMinute * 60) + st.wSecond;
}
int converTime(char from, char to, int time){
if(from == 's'){
switch(to){
case 'h':
return time / 3600;
case 'm':
return time % 3600 / 60;
case 's':
return time % 3600 % 60;
default: std::cout << "Not a Valid Operator";
}
}
if(from == 'h'){
switch(to){
case 'h':
return time;
case 'm':
return time * 60;
case 's':
return time * 3600;
default: std::cout << "Not a Valid Operator";
}
}
return -1;
}
Timer::Timer(){
this->time = 0;
this->startTime = this->getCurrentTime();
this->endTime = -1;
this->state = tr::PAUSE;
}
void Timer::updateTime(){
this->time++;
}
void Timer::start(){
this->state = tr::START;
}
void Timer::stop(){
this->state = tr::STOP;
this->endTime = this->getCurrentTime();
}
void Timer::pause(){
this->state = tr::PAUSE;
}
int Timer::getTime() const{
return this->time;
}
int Timer::getStartTime() const{
return this->startTime;
}
int Timer::getEndTime() const{
return this->endTime;
}
std::string Timer::toString() const{
char str[100];
sprintf(str, "%dh %dm %ds", converTime('s', 'h', this->time), converTime('s', 'm', this->time), converTime('s', 's', this->time));
return std::string(str);
}