OLD | NEW |
| (Empty) |
1 // Copyright 2014 PDFium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
6 | |
7 #ifndef XFA_SRC_FGAS_LOCALIZATION_FGAS_DATETIME_H_ | |
8 #define XFA_SRC_FGAS_LOCALIZATION_FGAS_DATETIME_H_ | |
9 | |
10 #include "core/include/fxcrt/fx_system.h" | |
11 | |
12 class CFX_Unitime; | |
13 class CFX_DateTime; | |
14 | |
15 typedef int64_t FX_UNITIME; | |
16 enum FX_WEEKDAY { | |
17 FX_Sunday = 0, | |
18 FX_Monday, | |
19 FX_Tuesday, | |
20 FX_Wednesday, | |
21 FX_Thursday, | |
22 FX_Friday, | |
23 FX_Saturday, | |
24 }; | |
25 | |
26 FX_BOOL FX_IsLeapYear(int32_t iYear); | |
27 int32_t FX_DaysInYear(int32_t iYear); | |
28 uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth); | |
29 | |
30 class CFX_Unitime { | |
31 public: | |
32 CFX_Unitime() { m_iUnitime = 0; } | |
33 CFX_Unitime(FX_UNITIME iUnitime) { m_iUnitime = iUnitime; } | |
34 CFX_Unitime(const CFX_Unitime& unitime) { m_iUnitime = unitime.m_iUnitime; } | |
35 operator FX_UNITIME*() { return &m_iUnitime; } | |
36 operator FX_UNITIME const*() const { return &m_iUnitime; } | |
37 operator FX_UNITIME&() { return m_iUnitime; } | |
38 operator const FX_UNITIME&() const { return m_iUnitime; } | |
39 CFX_Unitime& operator=(const CFX_Unitime& t) { | |
40 m_iUnitime = t.m_iUnitime; | |
41 return *this; | |
42 } | |
43 CFX_Unitime& operator=(FX_UNITIME t) { | |
44 m_iUnitime = t; | |
45 return *this; | |
46 } | |
47 CFX_Unitime& operator+=(const CFX_Unitime& t) { | |
48 m_iUnitime += t.m_iUnitime; | |
49 return *this; | |
50 } | |
51 CFX_Unitime& operator+=(FX_UNITIME t) { | |
52 m_iUnitime += t; | |
53 return *this; | |
54 } | |
55 CFX_Unitime& operator-=(const CFX_Unitime& t) { | |
56 m_iUnitime -= t.m_iUnitime; | |
57 return *this; | |
58 } | |
59 CFX_Unitime& operator-=(FX_UNITIME t) { | |
60 m_iUnitime -= t; | |
61 return *this; | |
62 } | |
63 void Now(); | |
64 void SetGMTime(); | |
65 void Set(int32_t year, | |
66 uint8_t month, | |
67 uint8_t day, | |
68 uint8_t hour = 0, | |
69 uint8_t minute = 0, | |
70 uint8_t second = 0, | |
71 FX_WORD millisecond = 0); | |
72 void Set(FX_UNITIME t); | |
73 int32_t GetYear() const; | |
74 uint8_t GetMonth() const; | |
75 uint8_t GetDay() const; | |
76 FX_WEEKDAY GetDayOfWeek() const; | |
77 FX_WORD GetDayOfYear() const; | |
78 int64_t GetDayOfAD() const; | |
79 uint8_t GetHour() const; | |
80 uint8_t GetMinute() const; | |
81 uint8_t GetSecond() const; | |
82 FX_WORD GetMillisecond() const; | |
83 FX_BOOL AddYears(int32_t iYears); | |
84 FX_BOOL AddMonths(int32_t iMonths); | |
85 FX_BOOL AddDays(int32_t iDays); | |
86 FX_BOOL AddHours(int32_t iHours); | |
87 FX_BOOL AddMinutes(int32_t iMinutes); | |
88 FX_BOOL AddSeconds(int32_t iSeconds); | |
89 FX_BOOL AddMilliseconds(int32_t iMilliseconds); | |
90 friend CFX_Unitime operator+(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
91 return CFX_Unitime(t1.m_iUnitime + t2.m_iUnitime); | |
92 } | |
93 friend CFX_Unitime operator+(const CFX_Unitime& t1, FX_UNITIME t2) { | |
94 return CFX_Unitime(t1.m_iUnitime + t2); | |
95 } | |
96 friend CFX_Unitime operator+(FX_UNITIME t1, const CFX_Unitime& t2) { | |
97 return CFX_Unitime(t1 + t2.m_iUnitime); | |
98 } | |
99 friend CFX_Unitime operator-(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
100 return CFX_Unitime(t1.m_iUnitime + t2.m_iUnitime); | |
101 } | |
102 friend CFX_Unitime operator-(const CFX_Unitime& t1, FX_UNITIME t2) { | |
103 return CFX_Unitime(t1.m_iUnitime + t2); | |
104 } | |
105 friend CFX_Unitime operator-(FX_UNITIME t1, const CFX_Unitime& t2) { | |
106 return CFX_Unitime(t1 + t2.m_iUnitime); | |
107 } | |
108 friend bool operator==(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
109 return t1.m_iUnitime == t2.m_iUnitime; | |
110 } | |
111 friend bool operator==(const CFX_Unitime& t1, FX_UNITIME t2) { | |
112 return t1.m_iUnitime == t2; | |
113 } | |
114 friend bool operator==(FX_UNITIME t1, const CFX_Unitime& t2) { | |
115 return t1 == t2.m_iUnitime; | |
116 } | |
117 friend bool operator!=(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
118 return t1.m_iUnitime != t2.m_iUnitime; | |
119 } | |
120 friend bool operator!=(const CFX_Unitime& t1, FX_UNITIME t2) { | |
121 return t1.m_iUnitime != t2; | |
122 } | |
123 friend bool operator!=(FX_UNITIME t1, const CFX_Unitime& t2) { | |
124 return t1 != t2.m_iUnitime; | |
125 } | |
126 friend bool operator>(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
127 return t1.m_iUnitime > t2.m_iUnitime; | |
128 } | |
129 friend bool operator>(const CFX_Unitime& t1, FX_UNITIME t2) { | |
130 return t1.m_iUnitime > t2; | |
131 } | |
132 friend bool operator>(FX_UNITIME t1, const CFX_Unitime& t2) { | |
133 return t1 > t2.m_iUnitime; | |
134 } | |
135 friend bool operator>=(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
136 return t1.m_iUnitime >= t2.m_iUnitime; | |
137 } | |
138 friend bool operator>=(const CFX_Unitime& t1, FX_UNITIME t2) { | |
139 return t1.m_iUnitime >= t2; | |
140 } | |
141 friend bool operator>=(FX_UNITIME t1, const CFX_Unitime& t2) { | |
142 return t1 >= t2.m_iUnitime; | |
143 } | |
144 friend bool operator<(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
145 return t1.m_iUnitime < t2.m_iUnitime; | |
146 } | |
147 friend bool operator<(const CFX_Unitime& t1, FX_UNITIME t2) { | |
148 return t1.m_iUnitime < t2; | |
149 } | |
150 friend bool operator<(FX_UNITIME t1, const CFX_Unitime& t2) { | |
151 return t1 < t2.m_iUnitime; | |
152 } | |
153 friend bool operator<=(const CFX_Unitime& t1, const CFX_Unitime& t2) { | |
154 return t1.m_iUnitime <= t2.m_iUnitime; | |
155 } | |
156 friend bool operator<=(const CFX_Unitime& t1, FX_UNITIME t2) { | |
157 return t1.m_iUnitime <= t2; | |
158 } | |
159 friend bool operator<=(FX_UNITIME t1, const CFX_Unitime& t2) { | |
160 return t1 <= t2.m_iUnitime; | |
161 } | |
162 | |
163 private: | |
164 FX_UNITIME m_iUnitime; | |
165 }; | |
166 | |
167 #if _FX_OS_ != _FX_ANDROID_ | |
168 #pragma pack(push, 1) | |
169 #endif | |
170 struct FX_DATE { | |
171 int32_t year; | |
172 uint8_t month; | |
173 uint8_t day; | |
174 }; | |
175 | |
176 struct FX_TIME { | |
177 uint8_t hour; | |
178 uint8_t minute; | |
179 uint8_t second; | |
180 FX_WORD millisecond; | |
181 }; | |
182 | |
183 struct FX_TIMEZONE { | |
184 int8_t tzHour; | |
185 uint8_t tzMinute; | |
186 }; | |
187 | |
188 struct FX_DATETIME { | |
189 union { | |
190 struct { | |
191 int32_t year; | |
192 uint8_t month; | |
193 uint8_t day; | |
194 } sDate; | |
195 FX_DATE aDate; | |
196 } Date; | |
197 union { | |
198 struct { | |
199 uint8_t hour; | |
200 uint8_t minute; | |
201 uint8_t second; | |
202 FX_WORD millisecond; | |
203 } sTime; | |
204 FX_TIME aTime; | |
205 } Time; | |
206 }; | |
207 | |
208 struct FX_DATETIMEZONE { | |
209 union { | |
210 struct { | |
211 union { | |
212 struct { | |
213 int32_t year; | |
214 uint8_t month; | |
215 uint8_t day; | |
216 }; | |
217 FX_DATE date; | |
218 }; | |
219 union { | |
220 struct { | |
221 uint8_t hour; | |
222 uint8_t minute; | |
223 uint8_t second; | |
224 FX_WORD millisecond; | |
225 }; | |
226 FX_TIME time; | |
227 }; | |
228 }; | |
229 FX_DATETIME dt; | |
230 }; | |
231 union { | |
232 struct { | |
233 int8_t tzHour; | |
234 uint8_t tzMinute; | |
235 }; | |
236 FX_TIMEZONE tz; | |
237 }; | |
238 }; | |
239 #if _FX_OS_ != _FX_ANDROID_ | |
240 #pragma pack(pop) | |
241 #endif | |
242 | |
243 class CFX_DateTime { | |
244 public: | |
245 CFX_DateTime() {} | |
246 CFX_DateTime(const FX_DATETIME& dt) { m_DateTime = dt; } | |
247 CFX_DateTime(const CFX_DateTime& dt) { m_DateTime = dt.m_DateTime; } | |
248 virtual ~CFX_DateTime() {} | |
249 operator FX_DATETIME*() { return &m_DateTime; } | |
250 operator const FX_DATETIME*() const { return &m_DateTime; } | |
251 operator FX_DATETIME&() { return m_DateTime; } | |
252 operator const FX_DATETIME&() const { return m_DateTime; } | |
253 CFX_DateTime& operator=(const CFX_DateTime& dt) { | |
254 m_DateTime = dt.m_DateTime; | |
255 return *this; | |
256 } | |
257 CFX_DateTime& operator=(const FX_DATETIME& dt) { | |
258 m_DateTime = dt; | |
259 return *this; | |
260 } | |
261 CFX_DateTime& operator+=(const CFX_DateTime& dt) { | |
262 FromUnitime(ToUnitime() + dt.ToUnitime()); | |
263 return *this; | |
264 } | |
265 CFX_DateTime& operator+=(const FX_DATETIME& dt) { | |
266 FromUnitime(ToUnitime() + ((const CFX_DateTime&)dt).ToUnitime()); | |
267 return *this; | |
268 } | |
269 CFX_DateTime& operator-=(const CFX_DateTime& dt) { | |
270 FromUnitime(ToUnitime() - dt.ToUnitime()); | |
271 return *this; | |
272 } | |
273 CFX_DateTime& operator-=(const FX_DATETIME& dt) { | |
274 FromUnitime(ToUnitime() - ((const CFX_DateTime&)dt).ToUnitime()); | |
275 return *this; | |
276 } | |
277 virtual FX_BOOL Set(int32_t year, | |
278 uint8_t month, | |
279 uint8_t day, | |
280 uint8_t hour = 0, | |
281 uint8_t minute = 0, | |
282 uint8_t second = 0, | |
283 FX_WORD millisecond = 0); | |
284 virtual FX_BOOL FromUnitime(FX_UNITIME t); | |
285 virtual FX_UNITIME ToUnitime() const; | |
286 virtual int32_t GetYear() const; | |
287 virtual uint8_t GetMonth() const; | |
288 virtual uint8_t GetDay() const; | |
289 virtual FX_WEEKDAY GetDayOfWeek() const; | |
290 virtual FX_WORD GetDayOfYear() const; | |
291 virtual int64_t GetDayOfAD() const; | |
292 virtual uint8_t GetHour() const; | |
293 virtual uint8_t GetMinute() const; | |
294 virtual uint8_t GetSecond() const; | |
295 virtual FX_WORD GetMillisecond() const; | |
296 virtual FX_BOOL AddYears(int32_t iYears); | |
297 virtual FX_BOOL AddMonths(int32_t iMonths); | |
298 virtual FX_BOOL AddDays(int32_t iDays); | |
299 virtual FX_BOOL AddHours(int32_t iHours); | |
300 virtual FX_BOOL AddMinutes(int32_t iMinutes); | |
301 virtual FX_BOOL AddSeconds(int32_t iSeconds); | |
302 virtual FX_BOOL AddMilliseconds(int32_t iMilliseconds); | |
303 friend CFX_DateTime operator+(const CFX_DateTime& dt1, | |
304 const CFX_DateTime& dt2) { | |
305 CFX_DateTime dt; | |
306 dt.FromUnitime(dt1.ToUnitime() + dt2.ToUnitime()); | |
307 return dt; | |
308 } | |
309 friend CFX_DateTime operator+(const CFX_DateTime& dt1, | |
310 const FX_DATETIME& dt2) { | |
311 CFX_DateTime dt; | |
312 dt.FromUnitime(dt1.ToUnitime() + ((const CFX_DateTime&)dt2).ToUnitime()); | |
313 return dt; | |
314 } | |
315 friend CFX_DateTime operator+(const FX_DATETIME& dt1, | |
316 const CFX_DateTime& dt2) { | |
317 CFX_DateTime dt; | |
318 dt.FromUnitime(((const CFX_DateTime&)dt1).ToUnitime() + dt2.ToUnitime()); | |
319 return dt; | |
320 } | |
321 friend CFX_DateTime operator-(const CFX_DateTime& dt1, | |
322 const CFX_DateTime& dt2) { | |
323 CFX_DateTime dt; | |
324 dt.FromUnitime(dt1.ToUnitime() - dt2.ToUnitime()); | |
325 return dt; | |
326 } | |
327 friend CFX_DateTime operator-(const CFX_DateTime& dt1, | |
328 const FX_DATETIME& dt2) { | |
329 CFX_DateTime dt; | |
330 dt.FromUnitime(dt1.ToUnitime() - ((const CFX_DateTime&)dt2).ToUnitime()); | |
331 return dt; | |
332 } | |
333 friend CFX_DateTime operator-(const FX_DATETIME& dt1, | |
334 const CFX_DateTime& dt2) { | |
335 CFX_DateTime dt; | |
336 dt.FromUnitime(((const CFX_DateTime&)dt1).ToUnitime() - dt2.ToUnitime()); | |
337 return dt; | |
338 } | |
339 friend FX_BOOL operator==(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | |
340 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), | |
341 static_cast<const FX_DATETIME*>(dt2), | |
342 sizeof(FX_DATETIME)) == 0; | |
343 } | |
344 friend FX_BOOL operator==(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | |
345 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), &dt2, | |
346 sizeof(FX_DATETIME)) == 0; | |
347 } | |
348 friend FX_BOOL operator==(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | |
349 return FXSYS_memcmp(&dt1, static_cast<const FX_DATETIME*>(dt2), | |
350 sizeof(FX_DATETIME)) == 0; | |
351 } | |
352 friend FX_BOOL operator!=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | |
353 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), | |
354 static_cast<const FX_DATETIME*>(dt2), | |
355 sizeof(FX_DATETIME)) != 0; | |
356 } | |
357 friend FX_BOOL operator!=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | |
358 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), &dt2, | |
359 sizeof(FX_DATETIME)) != 0; | |
360 } | |
361 friend FX_BOOL operator!=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | |
362 return FXSYS_memcmp(&dt1, static_cast<const FX_DATETIME*>(dt2), | |
363 sizeof(FX_DATETIME)) != 0; | |
364 } | |
365 friend FX_BOOL operator>(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | |
366 return dt1.ToUnitime() > dt2.ToUnitime(); | |
367 } | |
368 friend FX_BOOL operator>(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | |
369 return dt1.ToUnitime() > ((const CFX_DateTime&)dt2).ToUnitime(); | |
370 } | |
371 friend FX_BOOL operator>(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | |
372 return ((const CFX_DateTime&)dt1).ToUnitime() > dt2.ToUnitime(); | |
373 } | |
374 friend FX_BOOL operator>=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | |
375 return dt1.ToUnitime() >= dt2.ToUnitime(); | |
376 } | |
377 friend FX_BOOL operator>=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | |
378 return dt1.ToUnitime() >= ((const CFX_DateTime&)dt2).ToUnitime(); | |
379 } | |
380 friend FX_BOOL operator>=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | |
381 return ((const CFX_DateTime&)dt1).ToUnitime() >= dt2.ToUnitime(); | |
382 } | |
383 friend FX_BOOL operator<(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | |
384 return dt1.ToUnitime() < dt2.ToUnitime(); | |
385 } | |
386 friend FX_BOOL operator<(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | |
387 return dt1.ToUnitime() < ((const CFX_DateTime&)dt2).ToUnitime(); | |
388 } | |
389 friend FX_BOOL operator<(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | |
390 return ((const CFX_DateTime&)dt1).ToUnitime() < dt2.ToUnitime(); | |
391 } | |
392 friend FX_BOOL operator<=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | |
393 return dt1.ToUnitime() <= dt2.ToUnitime(); | |
394 } | |
395 friend FX_BOOL operator<=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | |
396 return dt1.ToUnitime() <= ((const CFX_DateTime&)dt2).ToUnitime(); | |
397 } | |
398 friend FX_BOOL operator<=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | |
399 return ((const CFX_DateTime&)dt1).ToUnitime() <= dt2.ToUnitime(); | |
400 } | |
401 | |
402 private: | |
403 FX_DATETIME m_DateTime; | |
404 }; | |
405 | |
406 #endif // XFA_SRC_FGAS_LOCALIZATION_FGAS_DATETIME_H_ | |
OLD | NEW |