-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASSTime.cpp
197 lines (155 loc) · 2.9 KB
/
ASSTime.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
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "ASSTime.h"
#include <sstream>
ASSTime::ASSTime()
{
this->hour = 0;
this->min = 0;
this->sec = 0;
this->cs = 0;
}
ASSTime::ASSTime(std::string input)
{
std::istringstream iss(input);
std::string temp;
getline(iss, temp, ':');
this->hour = stoi(temp);
getline(iss, temp, ':');
this->min = stoi(temp);
getline(iss, temp, '.');
this->sec = stoi(temp);
getline(iss, temp);
this->cs = stoi(temp);
}
ASSTime::ASSTime(int input)
{
this->cs = input % 100;
input /= 100;
this->sec = input % 60;
input /= 60;
this->min = input % 60;
input /= 60;
this->hour = input;
}
std::string ASSTime::printASSTime()
{
std::ostringstream sout;
sout << hour << ':';
if (min < 10) sout << '0';
sout << min << ':';
if (sec < 10) sout << '0';
sout << sec << '.';
if (cs < 10) sout << '0';
sout << cs;
return sout.str();
}
void ASSTime::operator=(ASSTime input)
{
this->hour = input.hour;
this->min = input.min;
this->sec = input.sec;
this->cs = input.cs;
}
void ASSTime::operator=(std::string input)
{
ASSTime temp(input);
*this = temp;
}
ASSTime ASSTime::operator+(ASSTime toAdd)
{
ASSTime result;
result.hour = this->hour + toAdd.hour;
result.min = this->min + toAdd.min;
result.sec = this->sec + toAdd.sec;
result.cs = this->cs + toAdd.cs;
result.round();
return result;
}
void ASSTime::operator+=(ASSTime toAdd)
{
*this = *this + toAdd;
}
ASSTime ASSTime::operator-(ASSTime toSubtract)
{
ASSTime result;
result.hour = this->hour - toSubtract.hour;
result.min = this->min - toSubtract.min;
result.sec = this->sec - toSubtract.sec;
result.cs = this->cs - toSubtract.cs;
result.round();
return result;
}
void ASSTime::operator-=(ASSTime toSubtract)
{
*this = *this + toSubtract;
}
bool ASSTime::operator==(ASSTime toCompare)
{
return (*this <= toCompare) && (*this >= toCompare);
}
bool ASSTime::operator!=(ASSTime toCompare)
{
return !(*this == toCompare);
}
bool ASSTime::operator<(ASSTime toCompare)
{
return this->getDurationCS() < toCompare.getDurationCS();
}
bool ASSTime::operator>(ASSTime toCompare)
{
return this->getDurationCS() > toCompare.getDurationCS();
}
bool ASSTime::operator<=(ASSTime toCompare)
{
return !(*this > toCompare);
}
bool ASSTime::operator>=(ASSTime toCompare)
{
return !(*this < toCompare);
}
void ASSTime::round()
{
if (this->cs >= 100)
{
this->sec += 1;
this->cs -= 100;
}
if (this->sec >= 60)
{
this->min += 1;
this->sec -= 60;
}
if (this->min >= 60)
{
this->hour += 1;
this->min -= 60;
}
if (this->cs < 0)
{
this->sec -= 1;
this->cs += 100;
}
if (this->sec < 0)
{
this->min -= 1;
this->sec += 60;
}
if (this->min < 0)
{
this->hour -= 1;
this->min += 60;
}
if (this->hour < 0)
{
ASSTime blank;
*this = blank;
}
}
int ASSTime::getDurationCS()
{
int output = 0;
output += this->cs;
output += this->sec * 100;
output += this->min * 100 * 60;
output += this->hour * 100 * 60 * 60;
return output;
}