forked from gopa810/gcal-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGCDayHours.cpp
186 lines (147 loc) · 2.85 KB
/
GCDayHours.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
#include "stdafx.h"
#include "GCDayHours.h"
#include "GCMath.h"
void DAYTIME::SetDayTime(double d)
{
double time_hr = 0.0;
// hour
time_hr = d * 24;
hour = int( floor(time_hr) );
// minute
time_hr -= hour;
time_hr *= 60;
min = int( floor(time_hr) );
// second
time_hr -= min;
time_hr *= 60;
sec = int( floor(time_hr) );
// miliseconds
time_hr -= sec;
time_hr *= 1000;
mili = int( floor(time_hr) );
}
void DAYTIME::SetValue(int i)
{
hour = min = sec = mili = i;
}
void DAYTIME::Set(DAYTIME &d)
{
hour = d.hour;
min = d.min;
sec = d.sec;
mili = d.mili;
}
bool DAYTIME::IsGreaterThan(DAYTIME &dt)
{
if (hour > dt.hour)
return TRUE;
else if (hour < dt.hour)
return FALSE;
if (min > dt.min)
return TRUE;
else if (min < dt.min)
return FALSE;
if (sec > dt.sec)
return TRUE;
else if (sec < dt.sec)
return FALSE;
if (mili > dt.mili)
return TRUE;
return FALSE;
}
bool DAYTIME::IsLessThan(DAYTIME &dt)
{
if (hour < dt.hour)
return TRUE;
else if (hour > dt.hour)
return FALSE;
if (min < dt.min)
return TRUE;
else if (min > dt.min)
return FALSE;
if (sec < dt.sec)
return TRUE;
else if (sec > dt.sec)
return FALSE;
if (mili < dt.mili)
return TRUE;
return FALSE;
}
bool DAYTIME::IsGreaterOrEqualThan(DAYTIME &dt)
{
if (hour >= dt.hour)
return TRUE;
else if (hour < dt.hour)
return FALSE;
if (min >= dt.min)
return TRUE;
else if (min < dt.min)
return FALSE;
if (sec >= dt.sec)
return TRUE;
else if (sec < dt.sec)
return FALSE;
if (mili >= dt.mili)
return TRUE;
return FALSE;
}
bool DAYTIME::IsLessOrEqualThan(DAYTIME &dt)
{
if (hour <= dt.hour)
return TRUE;
else if (hour > dt.hour)
return FALSE;
if (min <= dt.min)
return TRUE;
else if (min > dt.min)
return FALSE;
if (sec <= dt.sec)
return TRUE;
else if (sec > dt.sec)
return FALSE;
if (mili <= dt.mili)
return TRUE;
return FALSE;
}
void DAYTIME::AddMinutes(int mn)
{
min += mn;
while(min < 0) { min += 60; hour--;}
while(min > 59) { min -= 60; hour++;}
}
double DAYTIME::GetDayTime()
{
return ((double(hour)*60.0 + double(min))*60.0 + double(sec)) / 86400.0;
}
////////////////////////////////////////////////////////////////
//
// Conversion time from DEGREE fromat to H:M:S:MS format
//
// time - output
// time_deg - input time in range 0 deg to 360 deg
// where 0 deg = 0:00 AM and 360 deg = 12:00 PM
//
void DAYTIME::SetDegTime(double time_deg)
{
double time_hr = 0.0;
time_deg = GCMath::putIn360(time_deg);
// hour
time_hr = time_deg / 360 * 24;
hour = int( floor(time_hr) );
// minute
time_hr -= hour;
time_hr *= 60;
min = int( floor(time_hr) );
// second
time_hr -= min;
time_hr *= 60;
sec = int( floor(time_hr) );
// miliseconds
time_hr -= sec;
time_hr *= 1000;
mili = int( floor(time_hr) );
}
void DAYTIME::ToLongTimeString(TString &str)
{
str.Format("%02d:%02d:%02d", hour, min, sec);
}