OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #ifndef XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_ | 7 #ifndef XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_ |
8 #define XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_ | 8 #define XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_ |
9 | 9 |
10 #include "core/fxcrt/fx_system.h" | 10 #include "core/fxcrt/fx_system.h" |
11 | 11 |
12 class CFX_Unitime; | 12 class CFX_Unitime; |
13 class CFX_DateTime; | 13 class CFX_DateTime; |
14 | 14 |
15 typedef int64_t FX_UNITIME; | 15 typedef int64_t FX_UNITIME; |
16 enum FX_WEEKDAY { | 16 enum FX_WEEKDAY { |
17 FX_Sunday = 0, | 17 FX_Sunday = 0, |
18 FX_Monday, | 18 FX_Monday, |
19 FX_Tuesday, | 19 FX_Tuesday, |
20 FX_Wednesday, | 20 FX_Wednesday, |
21 FX_Thursday, | 21 FX_Thursday, |
22 FX_Friday, | 22 FX_Friday, |
23 FX_Saturday, | 23 FX_Saturday, |
24 }; | 24 }; |
25 | 25 |
26 FX_BOOL FX_IsLeapYear(int32_t iYear); | 26 bool FX_IsLeapYear(int32_t iYear); |
27 int32_t FX_DaysInYear(int32_t iYear); | 27 int32_t FX_DaysInYear(int32_t iYear); |
28 uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth); | 28 uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth); |
29 | 29 |
30 class CFX_Unitime { | 30 class CFX_Unitime { |
31 public: | 31 public: |
32 CFX_Unitime() { m_iUnitime = 0; } | 32 CFX_Unitime() { m_iUnitime = 0; } |
33 CFX_Unitime(FX_UNITIME iUnitime) { m_iUnitime = iUnitime; } | 33 CFX_Unitime(FX_UNITIME iUnitime) { m_iUnitime = iUnitime; } |
34 CFX_Unitime(const CFX_Unitime& unitime) { m_iUnitime = unitime.m_iUnitime; } | 34 CFX_Unitime(const CFX_Unitime& unitime) { m_iUnitime = unitime.m_iUnitime; } |
35 operator FX_UNITIME*() { return &m_iUnitime; } | 35 operator FX_UNITIME*() { return &m_iUnitime; } |
36 operator FX_UNITIME const*() const { return &m_iUnitime; } | 36 operator FX_UNITIME const*() const { return &m_iUnitime; } |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 int32_t GetYear() const; | 73 int32_t GetYear() const; |
74 uint8_t GetMonth() const; | 74 uint8_t GetMonth() const; |
75 uint8_t GetDay() const; | 75 uint8_t GetDay() const; |
76 FX_WEEKDAY GetDayOfWeek() const; | 76 FX_WEEKDAY GetDayOfWeek() const; |
77 uint16_t GetDayOfYear() const; | 77 uint16_t GetDayOfYear() const; |
78 int64_t GetDayOfAD() const; | 78 int64_t GetDayOfAD() const; |
79 uint8_t GetHour() const; | 79 uint8_t GetHour() const; |
80 uint8_t GetMinute() const; | 80 uint8_t GetMinute() const; |
81 uint8_t GetSecond() const; | 81 uint8_t GetSecond() const; |
82 uint16_t GetMillisecond() const; | 82 uint16_t GetMillisecond() const; |
83 FX_BOOL AddYears(int32_t iYears); | 83 bool AddYears(int32_t iYears); |
84 FX_BOOL AddMonths(int32_t iMonths); | 84 bool AddMonths(int32_t iMonths); |
85 FX_BOOL AddDays(int32_t iDays); | 85 bool AddDays(int32_t iDays); |
86 FX_BOOL AddHours(int32_t iHours); | 86 bool AddHours(int32_t iHours); |
87 FX_BOOL AddMinutes(int32_t iMinutes); | 87 bool AddMinutes(int32_t iMinutes); |
88 FX_BOOL AddSeconds(int32_t iSeconds); | 88 bool AddSeconds(int32_t iSeconds); |
89 FX_BOOL AddMilliseconds(int32_t iMilliseconds); | 89 bool AddMilliseconds(int32_t iMilliseconds); |
90 friend CFX_Unitime operator+(const CFX_Unitime& t1, const CFX_Unitime& t2) { | 90 friend CFX_Unitime operator+(const CFX_Unitime& t1, const CFX_Unitime& t2) { |
91 return CFX_Unitime(t1.m_iUnitime + t2.m_iUnitime); | 91 return CFX_Unitime(t1.m_iUnitime + t2.m_iUnitime); |
92 } | 92 } |
93 friend CFX_Unitime operator+(const CFX_Unitime& t1, FX_UNITIME t2) { | 93 friend CFX_Unitime operator+(const CFX_Unitime& t1, FX_UNITIME t2) { |
94 return CFX_Unitime(t1.m_iUnitime + t2); | 94 return CFX_Unitime(t1.m_iUnitime + t2); |
95 } | 95 } |
96 friend CFX_Unitime operator+(FX_UNITIME t1, const CFX_Unitime& t2) { | 96 friend CFX_Unitime operator+(FX_UNITIME t1, const CFX_Unitime& t2) { |
97 return CFX_Unitime(t1 + t2.m_iUnitime); | 97 return CFX_Unitime(t1 + t2.m_iUnitime); |
98 } | 98 } |
99 friend CFX_Unitime operator-(const CFX_Unitime& t1, const CFX_Unitime& t2) { | 99 friend CFX_Unitime operator-(const CFX_Unitime& t1, const CFX_Unitime& t2) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
236 return *this; | 236 return *this; |
237 } | 237 } |
238 CFX_DateTime& operator-=(const CFX_DateTime& dt) { | 238 CFX_DateTime& operator-=(const CFX_DateTime& dt) { |
239 FromUnitime(ToUnitime() - dt.ToUnitime()); | 239 FromUnitime(ToUnitime() - dt.ToUnitime()); |
240 return *this; | 240 return *this; |
241 } | 241 } |
242 CFX_DateTime& operator-=(const FX_DATETIME& dt) { | 242 CFX_DateTime& operator-=(const FX_DATETIME& dt) { |
243 FromUnitime(ToUnitime() - ((const CFX_DateTime&)dt).ToUnitime()); | 243 FromUnitime(ToUnitime() - ((const CFX_DateTime&)dt).ToUnitime()); |
244 return *this; | 244 return *this; |
245 } | 245 } |
246 virtual FX_BOOL Set(int32_t year, | 246 virtual bool Set(int32_t year, |
247 uint8_t month, | 247 uint8_t month, |
248 uint8_t day, | 248 uint8_t day, |
249 uint8_t hour = 0, | 249 uint8_t hour = 0, |
250 uint8_t minute = 0, | 250 uint8_t minute = 0, |
251 uint8_t second = 0, | 251 uint8_t second = 0, |
252 uint16_t millisecond = 0); | 252 uint16_t millisecond = 0); |
253 virtual FX_BOOL FromUnitime(FX_UNITIME t); | 253 virtual bool FromUnitime(FX_UNITIME t); |
254 virtual FX_UNITIME ToUnitime() const; | 254 virtual FX_UNITIME ToUnitime() const; |
255 virtual int32_t GetYear() const; | 255 virtual int32_t GetYear() const; |
256 virtual uint8_t GetMonth() const; | 256 virtual uint8_t GetMonth() const; |
257 virtual uint8_t GetDay() const; | 257 virtual uint8_t GetDay() const; |
258 virtual FX_WEEKDAY GetDayOfWeek() const; | 258 virtual FX_WEEKDAY GetDayOfWeek() const; |
259 virtual uint16_t GetDayOfYear() const; | 259 virtual uint16_t GetDayOfYear() const; |
260 virtual int64_t GetDayOfAD() const; | 260 virtual int64_t GetDayOfAD() const; |
261 virtual uint8_t GetHour() const; | 261 virtual uint8_t GetHour() const; |
262 virtual uint8_t GetMinute() const; | 262 virtual uint8_t GetMinute() const; |
263 virtual uint8_t GetSecond() const; | 263 virtual uint8_t GetSecond() const; |
264 virtual uint16_t GetMillisecond() const; | 264 virtual uint16_t GetMillisecond() const; |
265 virtual FX_BOOL AddYears(int32_t iYears); | 265 virtual bool AddYears(int32_t iYears); |
266 virtual FX_BOOL AddMonths(int32_t iMonths); | 266 virtual bool AddMonths(int32_t iMonths); |
267 virtual FX_BOOL AddDays(int32_t iDays); | 267 virtual bool AddDays(int32_t iDays); |
268 virtual FX_BOOL AddHours(int32_t iHours); | 268 virtual bool AddHours(int32_t iHours); |
269 virtual FX_BOOL AddMinutes(int32_t iMinutes); | 269 virtual bool AddMinutes(int32_t iMinutes); |
270 virtual FX_BOOL AddSeconds(int32_t iSeconds); | 270 virtual bool AddSeconds(int32_t iSeconds); |
271 virtual FX_BOOL AddMilliseconds(int32_t iMilliseconds); | 271 virtual bool AddMilliseconds(int32_t iMilliseconds); |
272 friend CFX_DateTime operator+(const CFX_DateTime& dt1, | 272 friend CFX_DateTime operator+(const CFX_DateTime& dt1, |
273 const CFX_DateTime& dt2) { | 273 const CFX_DateTime& dt2) { |
274 CFX_DateTime dt; | 274 CFX_DateTime dt; |
275 dt.FromUnitime(dt1.ToUnitime() + dt2.ToUnitime()); | 275 dt.FromUnitime(dt1.ToUnitime() + dt2.ToUnitime()); |
276 return dt; | 276 return dt; |
277 } | 277 } |
278 friend CFX_DateTime operator+(const CFX_DateTime& dt1, | 278 friend CFX_DateTime operator+(const CFX_DateTime& dt1, |
279 const FX_DATETIME& dt2) { | 279 const FX_DATETIME& dt2) { |
280 CFX_DateTime dt; | 280 CFX_DateTime dt; |
281 dt.FromUnitime(dt1.ToUnitime() + ((const CFX_DateTime&)dt2).ToUnitime()); | 281 dt.FromUnitime(dt1.ToUnitime() + ((const CFX_DateTime&)dt2).ToUnitime()); |
(...skipping 16 matching lines...) Expand all Loading... |
298 CFX_DateTime dt; | 298 CFX_DateTime dt; |
299 dt.FromUnitime(dt1.ToUnitime() - ((const CFX_DateTime&)dt2).ToUnitime()); | 299 dt.FromUnitime(dt1.ToUnitime() - ((const CFX_DateTime&)dt2).ToUnitime()); |
300 return dt; | 300 return dt; |
301 } | 301 } |
302 friend CFX_DateTime operator-(const FX_DATETIME& dt1, | 302 friend CFX_DateTime operator-(const FX_DATETIME& dt1, |
303 const CFX_DateTime& dt2) { | 303 const CFX_DateTime& dt2) { |
304 CFX_DateTime dt; | 304 CFX_DateTime dt; |
305 dt.FromUnitime(((const CFX_DateTime&)dt1).ToUnitime() - dt2.ToUnitime()); | 305 dt.FromUnitime(((const CFX_DateTime&)dt1).ToUnitime() - dt2.ToUnitime()); |
306 return dt; | 306 return dt; |
307 } | 307 } |
308 friend FX_BOOL operator==(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | 308 friend bool operator==(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { |
309 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), | 309 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), |
310 static_cast<const FX_DATETIME*>(dt2), | 310 static_cast<const FX_DATETIME*>(dt2), |
311 sizeof(FX_DATETIME)) == 0; | 311 sizeof(FX_DATETIME)) == 0; |
312 } | 312 } |
313 friend FX_BOOL operator==(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | 313 friend bool operator==(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { |
314 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), &dt2, | 314 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), &dt2, |
315 sizeof(FX_DATETIME)) == 0; | 315 sizeof(FX_DATETIME)) == 0; |
316 } | 316 } |
317 friend FX_BOOL operator==(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | 317 friend bool operator==(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { |
318 return FXSYS_memcmp(&dt1, static_cast<const FX_DATETIME*>(dt2), | 318 return FXSYS_memcmp(&dt1, static_cast<const FX_DATETIME*>(dt2), |
319 sizeof(FX_DATETIME)) == 0; | 319 sizeof(FX_DATETIME)) == 0; |
320 } | 320 } |
321 friend FX_BOOL operator!=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | 321 friend bool operator!=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { |
322 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), | 322 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), |
323 static_cast<const FX_DATETIME*>(dt2), | 323 static_cast<const FX_DATETIME*>(dt2), |
324 sizeof(FX_DATETIME)) != 0; | 324 sizeof(FX_DATETIME)) != 0; |
325 } | 325 } |
326 friend FX_BOOL operator!=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | 326 friend bool operator!=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { |
327 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), &dt2, | 327 return FXSYS_memcmp(static_cast<const FX_DATETIME*>(dt1), &dt2, |
328 sizeof(FX_DATETIME)) != 0; | 328 sizeof(FX_DATETIME)) != 0; |
329 } | 329 } |
330 friend FX_BOOL operator!=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | 330 friend bool operator!=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { |
331 return FXSYS_memcmp(&dt1, static_cast<const FX_DATETIME*>(dt2), | 331 return FXSYS_memcmp(&dt1, static_cast<const FX_DATETIME*>(dt2), |
332 sizeof(FX_DATETIME)) != 0; | 332 sizeof(FX_DATETIME)) != 0; |
333 } | 333 } |
334 friend FX_BOOL operator>(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | 334 friend bool operator>(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { |
335 return dt1.ToUnitime() > dt2.ToUnitime(); | 335 return dt1.ToUnitime() > dt2.ToUnitime(); |
336 } | 336 } |
337 friend FX_BOOL operator>(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | 337 friend bool operator>(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { |
338 return dt1.ToUnitime() > ((const CFX_DateTime&)dt2).ToUnitime(); | 338 return dt1.ToUnitime() > ((const CFX_DateTime&)dt2).ToUnitime(); |
339 } | 339 } |
340 friend FX_BOOL operator>(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | 340 friend bool operator>(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { |
341 return ((const CFX_DateTime&)dt1).ToUnitime() > dt2.ToUnitime(); | 341 return ((const CFX_DateTime&)dt1).ToUnitime() > dt2.ToUnitime(); |
342 } | 342 } |
343 friend FX_BOOL operator>=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | 343 friend bool operator>=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { |
344 return dt1.ToUnitime() >= dt2.ToUnitime(); | 344 return dt1.ToUnitime() >= dt2.ToUnitime(); |
345 } | 345 } |
346 friend FX_BOOL operator>=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | 346 friend bool operator>=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { |
347 return dt1.ToUnitime() >= ((const CFX_DateTime&)dt2).ToUnitime(); | 347 return dt1.ToUnitime() >= ((const CFX_DateTime&)dt2).ToUnitime(); |
348 } | 348 } |
349 friend FX_BOOL operator>=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | 349 friend bool operator>=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { |
350 return ((const CFX_DateTime&)dt1).ToUnitime() >= dt2.ToUnitime(); | 350 return ((const CFX_DateTime&)dt1).ToUnitime() >= dt2.ToUnitime(); |
351 } | 351 } |
352 friend FX_BOOL operator<(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | 352 friend bool operator<(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { |
353 return dt1.ToUnitime() < dt2.ToUnitime(); | 353 return dt1.ToUnitime() < dt2.ToUnitime(); |
354 } | 354 } |
355 friend FX_BOOL operator<(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | 355 friend bool operator<(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { |
356 return dt1.ToUnitime() < ((const CFX_DateTime&)dt2).ToUnitime(); | 356 return dt1.ToUnitime() < ((const CFX_DateTime&)dt2).ToUnitime(); |
357 } | 357 } |
358 friend FX_BOOL operator<(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | 358 friend bool operator<(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { |
359 return ((const CFX_DateTime&)dt1).ToUnitime() < dt2.ToUnitime(); | 359 return ((const CFX_DateTime&)dt1).ToUnitime() < dt2.ToUnitime(); |
360 } | 360 } |
361 friend FX_BOOL operator<=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { | 361 friend bool operator<=(const CFX_DateTime& dt1, const CFX_DateTime& dt2) { |
362 return dt1.ToUnitime() <= dt2.ToUnitime(); | 362 return dt1.ToUnitime() <= dt2.ToUnitime(); |
363 } | 363 } |
364 friend FX_BOOL operator<=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { | 364 friend bool operator<=(const CFX_DateTime& dt1, const FX_DATETIME& dt2) { |
365 return dt1.ToUnitime() <= ((const CFX_DateTime&)dt2).ToUnitime(); | 365 return dt1.ToUnitime() <= ((const CFX_DateTime&)dt2).ToUnitime(); |
366 } | 366 } |
367 friend FX_BOOL operator<=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { | 367 friend bool operator<=(const FX_DATETIME& dt1, const CFX_DateTime& dt2) { |
368 return ((const CFX_DateTime&)dt1).ToUnitime() <= dt2.ToUnitime(); | 368 return ((const CFX_DateTime&)dt1).ToUnitime() <= dt2.ToUnitime(); |
369 } | 369 } |
370 | 370 |
371 private: | 371 private: |
372 FX_DATETIME m_DateTime; | 372 FX_DATETIME m_DateTime; |
373 }; | 373 }; |
374 | 374 |
375 #endif // XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_ | 375 #endif // XFA_FGAS_LOCALIZATION_FGAS_DATETIME_H_ |
OLD | NEW |