blob: e319e223058a5017e1f38dfe8db7cc1fbb4c46a1 (
plain)
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
|
#include "StdAfx.h"
#include "T2Archive.h"
#include "T2DateTime.h"
#include "../T2TowerDoc.h"
#include "T2WorldPlugin.h"
T2DateTime::T2DateTime() {
mYear = 0;
mMonth = 0;
mRawMinutes = 0;
mSeconds = 0;
}
T2DateTime::T2DateTime(int year, int month, int hours, int minutes, int seconds) {
mYear = year;
mMonth = month;
mRawMinutes = hours * 60 + minutes;
mSeconds = seconds;
}
T2DateTime::T2DateTime(T2Archive& archive) {
unsigned short v;
archive >> v;
mYear = v;
archive >> v;
mMonth = v;
archive >> v;
mRawMinutes = v;
archive >> v;
mSeconds = v;
}
/*virtual*/ T2DateTime::~T2DateTime() {
}
int T2DateTime::GetTimeZone() {
int h = Get24Hour();
if (h < 2) return 0;
if (h < 6) return 1;
if (h < 9) return 2;
if (h < 10) return 3;
if (h < 12) return 4;
if (h < 13) return 5;
if (h < 15) return 6;
if (h < 18) return 7;
if (h < 22) return 8;
return 9;
}
/*static*/ BOOL T2DateTime::IsEqualDate(T2DateTime* a, T2DateTime* b) {
return (a->mYear == b->mYear) && (a->mMonth == b->mMonth);
}
/*static*/ BOOL T2DateTime::IsEqualDateTime(T2DateTime* a, T2DateTime* b) {
return IsEqualDate(a, b) && (a->mRawMinutes == b->mRawMinutes);
}
void T2DateTime::AddMinutes(unsigned int m) {
mRawMinutes += m;
Validate();
}
BOOL T2DateTime::IsIncDateTime() {
BOOL result = false;
mSeconds++;
if (mSeconds >= 4) {
result = true;
mSeconds = 0;
mRawMinutes++;
if (mRawMinutes >= 1440) {
mMonth++;
mRawMinutes -= 1440;
}
if (mMonth >= 12) {
mYear++;
mMonth -= 12;
}
}
return result;
}
void T2DateTime::IncDate() {
mMonth++;
if (mMonth >= 12) {
mYear++;
mMonth -= 12;
}
}
unsigned int T2DateTime::CalcLapseDays(unsigned int d) const {
return CalcTotalDays() - d;
}
unsigned int T2DateTime::CalcLapseYears(unsigned int d) const {
return (CalcTotalDays() - d) / 12;
}
BOOL T2DateTime::WithinHour(int a, int b) const {
return WithinMinutes(a * 60, b * 60);
}
BOOL T2DateTime::WithinMinutes(int a, int b) const {
BOOL isWithin = true;
int minL = AdjustMinutes(a);
int minR = AdjustMinutes(b);
if (minL < minR) {
if ((mRawMinutes < minL) || (mRawMinutes >= minR))
isWithin = false;
} else if (minL > minR) {
if ((mRawMinutes >= minR) && (mRawMinutes < minL))
isWithin = false;
}
return isWithin;
}
int T2DateTime::AdjustMinutes(int m) const {
int result = m;
if (result < 0)
result += 1440;
else if (result >= 1440)
result -= 1440;
return result;
}
/*virtual*/ void T2DateTime::Write(T2Archive& archive) {
unsigned short v = mYear;
archive << v;
v = mMonth;
archive << v;
v = mRawMinutes;
archive << v;
v = mSeconds;
archive << v;
}
BOOL T2DateTime::IsHoliday(T2TowerDoc* doc) {
T2WorldPlugin *thePlugin = doc->mWorldPlugin;
return thePlugin->IsHoliday(this);
}
void T2DateTime::Validate() {
mRawMinutes += (mSeconds / 4);
mSeconds = mSeconds % 4;
mMonth += (mRawMinutes / 1440);
mRawMinutes %= 1440;
mYear += (mMonth / 12);
mMonth %= 12;
}
|