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 #include "core/fxcrt/fx_system.h" | 7 #include "core/fxcrt/fx_system.h" |
8 #include "xfa/fgas/localization/fgas_datetime.h" | 8 #include "xfa/fgas/localization/fgas_datetime.h" |
9 | 9 |
10 #if _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_ || \ | 10 #if _FX_OS_ == _FX_LINUX_DESKTOP_ || _FX_OS_ == _FX_ANDROID_ || \ |
(...skipping 12 matching lines...) Expand all Loading... |
23 182, 213, 244, 274, 305, 335}; | 23 182, 213, 244, 274, 305, 335}; |
24 const int32_t g_FXDaysPerYear = 365; | 24 const int32_t g_FXDaysPerYear = 365; |
25 const int32_t g_FXDaysPerLeapYear = 366; | 25 const int32_t g_FXDaysPerLeapYear = 366; |
26 const int32_t g_FXDaysPer4Years = 1461; | 26 const int32_t g_FXDaysPer4Years = 1461; |
27 const int32_t g_FXDaysPer100Years = 36524; | 27 const int32_t g_FXDaysPer100Years = 36524; |
28 const int32_t g_FXDaysPer400Years = 146097; | 28 const int32_t g_FXDaysPer400Years = 146097; |
29 const int64_t g_FXMillisecondsPerSecond = 1000; | 29 const int64_t g_FXMillisecondsPerSecond = 1000; |
30 const int64_t g_FXMillisecondsPerMinute = 60000; | 30 const int64_t g_FXMillisecondsPerMinute = 60000; |
31 const int64_t g_FXMillisecondsPerHour = 3600000; | 31 const int64_t g_FXMillisecondsPerHour = 3600000; |
32 const int64_t g_FXMillisecondsPerDay = 86400000; | 32 const int64_t g_FXMillisecondsPerDay = 86400000; |
33 FX_BOOL FX_IsLeapYear(int32_t iYear) { | 33 bool FX_IsLeapYear(int32_t iYear) { |
34 ASSERT(iYear != 0); | 34 ASSERT(iYear != 0); |
35 return ((iYear % 4) == 0 && (iYear % 100) != 0) || (iYear % 400) == 0; | 35 return ((iYear % 4) == 0 && (iYear % 100) != 0) || (iYear % 400) == 0; |
36 } | 36 } |
37 int32_t FX_DaysInYear(int32_t iYear) { | 37 int32_t FX_DaysInYear(int32_t iYear) { |
38 ASSERT(iYear != 0); | 38 ASSERT(iYear != 0); |
39 return FX_IsLeapYear(iYear) ? g_FXDaysPerLeapYear : g_FXDaysPerYear; | 39 return FX_IsLeapYear(iYear) ? g_FXDaysPerLeapYear : g_FXDaysPerYear; |
40 } | 40 } |
41 uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth) { | 41 uint8_t FX_DaysInMonth(int32_t iYear, uint8_t iMonth) { |
42 ASSERT(iYear != 0); | 42 ASSERT(iYear != 0); |
43 ASSERT(iMonth >= 1 && iMonth <= 12); | 43 ASSERT(iMonth >= 1 && iMonth <= 12); |
44 const uint8_t* p = | 44 const uint8_t* p = |
45 FX_IsLeapYear(iYear) ? g_FXDaysPerLeapMonth : g_FXDaysPerMonth; | 45 FX_IsLeapYear(iYear) ? g_FXDaysPerLeapMonth : g_FXDaysPerMonth; |
46 return p[iMonth - 1]; | 46 return p[iMonth - 1]; |
47 } | 47 } |
48 static int32_t FX_DaysBeforeMonthInYear(int32_t iYear, uint8_t iMonth) { | 48 static int32_t FX_DaysBeforeMonthInYear(int32_t iYear, uint8_t iMonth) { |
49 ASSERT(iYear != 0); | 49 ASSERT(iYear != 0); |
50 ASSERT(iMonth >= 1 && iMonth <= 12); | 50 ASSERT(iMonth >= 1 && iMonth <= 12); |
51 const int32_t* p = | 51 const int32_t* p = |
52 FX_IsLeapYear(iYear) ? g_FXDaysBeforeLeapMonth : g_FXDaysBeforeMonth; | 52 FX_IsLeapYear(iYear) ? g_FXDaysBeforeLeapMonth : g_FXDaysBeforeMonth; |
53 return p[iMonth - 1]; | 53 return p[iMonth - 1]; |
54 } | 54 } |
55 static int64_t FX_DateToDays(int32_t iYear, | 55 static int64_t FX_DateToDays(int32_t iYear, |
56 uint8_t iMonth, | 56 uint8_t iMonth, |
57 uint8_t iDay, | 57 uint8_t iDay, |
58 FX_BOOL bIncludeThisDay = FALSE) { | 58 bool bIncludeThisDay = false) { |
59 ASSERT(iYear != 0); | 59 ASSERT(iYear != 0); |
60 ASSERT(iMonth >= 1 && iMonth <= 12); | 60 ASSERT(iMonth >= 1 && iMonth <= 12); |
61 ASSERT(iDay >= 1 && iDay <= FX_DaysInMonth(iYear, iMonth)); | 61 ASSERT(iDay >= 1 && iDay <= FX_DaysInMonth(iYear, iMonth)); |
62 int64_t iDays = FX_DaysBeforeMonthInYear(iYear, iMonth); | 62 int64_t iDays = FX_DaysBeforeMonthInYear(iYear, iMonth); |
63 iDays += iDay; | 63 iDays += iDay; |
64 if (!bIncludeThisDay) { | 64 if (!bIncludeThisDay) { |
65 iDays--; | 65 iDays--; |
66 } | 66 } |
67 if (iYear > 0) { | 67 if (iYear > 0) { |
68 iYear--; | 68 iYear--; |
69 } else { | 69 } else { |
70 iDays -= FX_DaysInYear(iYear); | 70 iDays -= FX_DaysInYear(iYear); |
71 iYear++; | 71 iYear++; |
72 } | 72 } |
73 return iDays + (int64_t)iYear * 365 + iYear / 4 - iYear / 100 + iYear / 400; | 73 return iDays + (int64_t)iYear * 365 + iYear / 4 - iYear / 100 + iYear / 400; |
74 } | 74 } |
75 static void FX_DaysToDate(int64_t iDays, | 75 static void FX_DaysToDate(int64_t iDays, |
76 int32_t& iYear, | 76 int32_t& iYear, |
77 uint8_t& iMonth, | 77 uint8_t& iMonth, |
78 uint8_t& iDay) { | 78 uint8_t& iDay) { |
79 FX_BOOL bBC = iDays < 0; | 79 bool bBC = iDays < 0; |
80 if (bBC) { | 80 if (bBC) { |
81 iDays = -iDays; | 81 iDays = -iDays; |
82 } | 82 } |
83 iYear = 1; | 83 iYear = 1; |
84 iMonth = 1; | 84 iMonth = 1; |
85 iDay = 1; | 85 iDay = 1; |
86 if (iDays >= g_FXDaysPer400Years) { | 86 if (iDays >= g_FXDaysPer400Years) { |
87 iYear += (int32_t)(iDays / g_FXDaysPer400Years * 400); | 87 iYear += (int32_t)(iDays / g_FXDaysPer400Years * 400); |
88 iDays %= g_FXDaysPer400Years; | 88 iDays %= g_FXDaysPer400Years; |
89 } | 89 } |
90 if (iDays >= g_FXDaysPer100Years) { | 90 if (iDays >= g_FXDaysPer100Years) { |
91 if (iDays == g_FXDaysPer100Years * 4) { | 91 if (iDays == g_FXDaysPer100Years * 4) { |
92 iYear += 300; | 92 iYear += 300; |
93 iDays -= g_FXDaysPer100Years * 3; | 93 iDays -= g_FXDaysPer100Years * 3; |
94 } else { | 94 } else { |
95 iYear += (int32_t)(iDays / g_FXDaysPer100Years * 100); | 95 iYear += (int32_t)(iDays / g_FXDaysPer100Years * 100); |
96 iDays %= g_FXDaysPer100Years; | 96 iDays %= g_FXDaysPer100Years; |
97 } | 97 } |
98 } | 98 } |
99 if (iDays >= g_FXDaysPer4Years) { | 99 if (iDays >= g_FXDaysPer4Years) { |
100 iYear += (int32_t)(iDays / g_FXDaysPer4Years * 4); | 100 iYear += (int32_t)(iDays / g_FXDaysPer4Years * 4); |
101 iDays %= g_FXDaysPer4Years; | 101 iDays %= g_FXDaysPer4Years; |
102 } | 102 } |
103 while (TRUE) { | 103 while (true) { |
104 int32_t iYearDays = FX_DaysInYear(iYear); | 104 int32_t iYearDays = FX_DaysInYear(iYear); |
105 if (iDays < iYearDays) { | 105 if (iDays < iYearDays) { |
106 if (bBC) { | 106 if (bBC) { |
107 iYear = -iYear; | 107 iYear = -iYear; |
108 iDays = iYearDays - iDays; | 108 iDays = iYearDays - iDays; |
109 } | 109 } |
110 break; | 110 break; |
111 } | 111 } |
112 iYear++; | 112 iYear++; |
113 iDays -= iYearDays; | 113 iDays -= iYearDays; |
114 } | 114 } |
115 while (TRUE) { | 115 while (true) { |
116 int32_t iMonthDays = FX_DaysInMonth(iYear, iMonth); | 116 int32_t iMonthDays = FX_DaysInMonth(iYear, iMonth); |
117 if (iDays < iMonthDays) { | 117 if (iDays < iMonthDays) { |
118 break; | 118 break; |
119 } | 119 } |
120 iMonth++; | 120 iMonth++; |
121 iDays -= iMonthDays; | 121 iDays -= iMonthDays; |
122 } | 122 } |
123 iDay += (uint8_t)iDays; | 123 iDay += (uint8_t)iDays; |
124 } | 124 } |
125 | 125 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 ASSERT(hour <= 23); | 200 ASSERT(hour <= 23); |
201 ASSERT(minute <= 59); | 201 ASSERT(minute <= 59); |
202 ASSERT(second <= 59); | 202 ASSERT(second <= 59); |
203 ASSERT(millisecond <= 999); | 203 ASSERT(millisecond <= 999); |
204 m_iUnitime = (int64_t)hour * g_FXMillisecondsPerHour + | 204 m_iUnitime = (int64_t)hour * g_FXMillisecondsPerHour + |
205 (int64_t)minute * g_FXMillisecondsPerMinute + | 205 (int64_t)minute * g_FXMillisecondsPerMinute + |
206 (int64_t)second * g_FXMillisecondsPerSecond + millisecond; | 206 (int64_t)second * g_FXMillisecondsPerSecond + millisecond; |
207 if (year > 0) { | 207 if (year > 0) { |
208 m_iUnitime = | 208 m_iUnitime = |
209 m_iUnitime + | 209 m_iUnitime + |
210 FX_DateToDays(year, month, day, FALSE) * g_FXMillisecondsPerDay; | 210 FX_DateToDays(year, month, day, false) * g_FXMillisecondsPerDay; |
211 } | 211 } |
212 } | 212 } |
213 void CFX_Unitime::Set(FX_UNITIME t) { | 213 void CFX_Unitime::Set(FX_UNITIME t) { |
214 m_iUnitime = t; | 214 m_iUnitime = t; |
215 } | 215 } |
216 int32_t CFX_Unitime::GetYear() const { | 216 int32_t CFX_Unitime::GetYear() const { |
217 int32_t iYear; | 217 int32_t iYear; |
218 uint8_t iMonth, iDay; | 218 uint8_t iMonth, iDay; |
219 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); | 219 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); |
220 return iYear; | 220 return iYear; |
(...skipping 17 matching lines...) Expand all Loading... |
238 } | 238 } |
239 return (FX_WEEKDAY)v; | 239 return (FX_WEEKDAY)v; |
240 } | 240 } |
241 uint16_t CFX_Unitime::GetDayOfYear() const { | 241 uint16_t CFX_Unitime::GetDayOfYear() const { |
242 int32_t iYear; | 242 int32_t iYear; |
243 uint8_t iMonth, iDay; | 243 uint8_t iMonth, iDay; |
244 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); | 244 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); |
245 return FX_DaysBeforeMonthInYear(iYear, iMonth) + iDay; | 245 return FX_DaysBeforeMonthInYear(iYear, iMonth) + iDay; |
246 } | 246 } |
247 int64_t CFX_Unitime::GetDayOfAD() const { | 247 int64_t CFX_Unitime::GetDayOfAD() const { |
248 FX_BOOL bBC = m_iUnitime < 0; | 248 bool bBC = m_iUnitime < 0; |
249 int64_t iDays = m_iUnitime / g_FXMillisecondsPerDay; | 249 int64_t iDays = m_iUnitime / g_FXMillisecondsPerDay; |
250 iDays += bBC ? -1 : 0; | 250 iDays += bBC ? -1 : 0; |
251 if (bBC && (m_iUnitime % g_FXMillisecondsPerDay) == 0) { | 251 if (bBC && (m_iUnitime % g_FXMillisecondsPerDay) == 0) { |
252 iDays++; | 252 iDays++; |
253 } | 253 } |
254 return iDays; | 254 return iDays; |
255 } | 255 } |
256 uint8_t CFX_Unitime::GetHour() const { | 256 uint8_t CFX_Unitime::GetHour() const { |
257 int32_t v = (int32_t)(m_iUnitime % g_FXMillisecondsPerDay); | 257 int32_t v = (int32_t)(m_iUnitime % g_FXMillisecondsPerDay); |
258 if (v < 0) { | 258 if (v < 0) { |
(...skipping 15 matching lines...) Expand all Loading... |
274 } | 274 } |
275 return (uint8_t)(v / g_FXMillisecondsPerSecond); | 275 return (uint8_t)(v / g_FXMillisecondsPerSecond); |
276 } | 276 } |
277 uint16_t CFX_Unitime::GetMillisecond() const { | 277 uint16_t CFX_Unitime::GetMillisecond() const { |
278 int32_t v = (int32_t)(m_iUnitime % g_FXMillisecondsPerSecond); | 278 int32_t v = (int32_t)(m_iUnitime % g_FXMillisecondsPerSecond); |
279 if (v < 0) { | 279 if (v < 0) { |
280 v += g_FXMillisecondsPerSecond; | 280 v += g_FXMillisecondsPerSecond; |
281 } | 281 } |
282 return (uint16_t)v; | 282 return (uint16_t)v; |
283 } | 283 } |
284 FX_BOOL CFX_Unitime::AddYears(int32_t iYears) { | 284 bool CFX_Unitime::AddYears(int32_t iYears) { |
285 FX_UNITIME ut = m_iUnitime; | 285 FX_UNITIME ut = m_iUnitime; |
286 if (ut < 0) { | 286 if (ut < 0) { |
287 ut = -ut; | 287 ut = -ut; |
288 } | 288 } |
289 FX_UNITIME r = ut % g_FXMillisecondsPerDay; | 289 FX_UNITIME r = ut % g_FXMillisecondsPerDay; |
290 int32_t iYear; | 290 int32_t iYear; |
291 uint8_t iMonth, iDay; | 291 uint8_t iMonth, iDay; |
292 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); | 292 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); |
293 iYear += iYears; | 293 iYear += iYears; |
294 if (iYear == 0) { | 294 if (iYear == 0) { |
295 iYear = iYears > 0 ? 1 : -1; | 295 iYear = iYears > 0 ? 1 : -1; |
296 } | 296 } |
297 m_iUnitime = | 297 m_iUnitime = |
298 FX_DateToDays(iYear, iMonth, iDay, FALSE) * g_FXMillisecondsPerDay; | 298 FX_DateToDays(iYear, iMonth, iDay, false) * g_FXMillisecondsPerDay; |
299 m_iUnitime += (iYear < 0) ? -r : r; | 299 m_iUnitime += (iYear < 0) ? -r : r; |
300 return TRUE; | 300 return true; |
301 } | 301 } |
302 FX_BOOL CFX_Unitime::AddMonths(int32_t iMonths) { | 302 bool CFX_Unitime::AddMonths(int32_t iMonths) { |
303 FX_BOOL b = iMonths > 0; | 303 bool b = iMonths > 0; |
304 FX_UNITIME ut = m_iUnitime; | 304 FX_UNITIME ut = m_iUnitime; |
305 if (ut < 0) { | 305 if (ut < 0) { |
306 ut = -ut; | 306 ut = -ut; |
307 } | 307 } |
308 FX_UNITIME r = ut % g_FXMillisecondsPerDay; | 308 FX_UNITIME r = ut % g_FXMillisecondsPerDay; |
309 int32_t iYear; | 309 int32_t iYear; |
310 uint8_t iMonth, iDay; | 310 uint8_t iMonth, iDay; |
311 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); | 311 FX_DaysToDate(GetDayOfAD(), iYear, iMonth, iDay); |
312 iMonths += iMonth; | 312 iMonths += iMonth; |
313 while (iMonths < 1) { | 313 while (iMonths < 1) { |
314 iYear--, iMonths += 12; | 314 iYear--, iMonths += 12; |
315 } | 315 } |
316 while (iMonths > 12) { | 316 while (iMonths > 12) { |
317 iYear++, iMonths -= 12; | 317 iYear++, iMonths -= 12; |
318 } | 318 } |
319 if (iYear == 0) { | 319 if (iYear == 0) { |
320 iYear = b ? 1 : -1; | 320 iYear = b ? 1 : -1; |
321 } | 321 } |
322 m_iUnitime = FX_DateToDays(iYear, (uint8_t)iMonths, iDay, FALSE) * | 322 m_iUnitime = FX_DateToDays(iYear, (uint8_t)iMonths, iDay, false) * |
323 g_FXMillisecondsPerDay; | 323 g_FXMillisecondsPerDay; |
324 m_iUnitime += (iYear < 0) ? -r : r; | 324 m_iUnitime += (iYear < 0) ? -r : r; |
325 return TRUE; | 325 return true; |
326 } | 326 } |
327 FX_BOOL CFX_Unitime::AddDays(int32_t iDays) { | 327 bool CFX_Unitime::AddDays(int32_t iDays) { |
328 m_iUnitime += (int64_t)iDays * g_FXMillisecondsPerDay; | 328 m_iUnitime += (int64_t)iDays * g_FXMillisecondsPerDay; |
329 return TRUE; | 329 return true; |
330 } | 330 } |
331 FX_BOOL CFX_Unitime::AddHours(int32_t iHours) { | 331 bool CFX_Unitime::AddHours(int32_t iHours) { |
332 m_iUnitime += (int64_t)iHours * g_FXMillisecondsPerHour; | 332 m_iUnitime += (int64_t)iHours * g_FXMillisecondsPerHour; |
333 return TRUE; | 333 return true; |
334 } | 334 } |
335 FX_BOOL CFX_Unitime::AddMinutes(int32_t iMinutes) { | 335 bool CFX_Unitime::AddMinutes(int32_t iMinutes) { |
336 m_iUnitime += (int64_t)iMinutes * g_FXMillisecondsPerMinute; | 336 m_iUnitime += (int64_t)iMinutes * g_FXMillisecondsPerMinute; |
337 return TRUE; | 337 return true; |
338 } | 338 } |
339 FX_BOOL CFX_Unitime::AddSeconds(int32_t iSeconds) { | 339 bool CFX_Unitime::AddSeconds(int32_t iSeconds) { |
340 m_iUnitime += ((int64_t)iSeconds) * g_FXMillisecondsPerSecond; | 340 m_iUnitime += ((int64_t)iSeconds) * g_FXMillisecondsPerSecond; |
341 return TRUE; | 341 return true; |
342 } | 342 } |
343 FX_BOOL CFX_Unitime::AddMilliseconds(int32_t iMilliseconds) { | 343 bool CFX_Unitime::AddMilliseconds(int32_t iMilliseconds) { |
344 m_iUnitime += iMilliseconds; | 344 m_iUnitime += iMilliseconds; |
345 return TRUE; | 345 return true; |
346 } | 346 } |
347 FX_BOOL CFX_DateTime::Set(int32_t year, | 347 bool CFX_DateTime::Set(int32_t year, |
348 uint8_t month, | 348 uint8_t month, |
349 uint8_t day, | 349 uint8_t day, |
350 uint8_t hour, | 350 uint8_t hour, |
351 uint8_t minute, | 351 uint8_t minute, |
352 uint8_t second, | 352 uint8_t second, |
353 uint16_t millisecond) { | 353 uint16_t millisecond) { |
354 ASSERT(year != 0); | 354 ASSERT(year != 0); |
355 ASSERT(month >= 1 && month <= 12); | 355 ASSERT(month >= 1 && month <= 12); |
356 ASSERT(day >= 1 && day <= FX_DaysInMonth(year, month)); | 356 ASSERT(day >= 1 && day <= FX_DaysInMonth(year, month)); |
357 ASSERT(hour <= 23); | 357 ASSERT(hour <= 23); |
358 ASSERT(minute <= 59); | 358 ASSERT(minute <= 59); |
359 ASSERT(second <= 59); | 359 ASSERT(second <= 59); |
360 ASSERT(millisecond <= 999); | 360 ASSERT(millisecond <= 999); |
361 m_DateTime.Date.sDate.year = year; | 361 m_DateTime.Date.sDate.year = year; |
362 m_DateTime.Date.sDate.month = month; | 362 m_DateTime.Date.sDate.month = month; |
363 m_DateTime.Date.sDate.day = day; | 363 m_DateTime.Date.sDate.day = day; |
364 m_DateTime.Time.sTime.hour = hour; | 364 m_DateTime.Time.sTime.hour = hour; |
365 m_DateTime.Time.sTime.minute = minute; | 365 m_DateTime.Time.sTime.minute = minute; |
366 m_DateTime.Time.sTime.second = second; | 366 m_DateTime.Time.sTime.second = second; |
367 m_DateTime.Time.sTime.millisecond = millisecond; | 367 m_DateTime.Time.sTime.millisecond = millisecond; |
368 return TRUE; | 368 return true; |
369 } | 369 } |
370 FX_BOOL CFX_DateTime::FromUnitime(FX_UNITIME t) { | 370 bool CFX_DateTime::FromUnitime(FX_UNITIME t) { |
371 CFX_Unitime ut(t); | 371 CFX_Unitime ut(t); |
372 FX_DaysToDate(ut.GetDayOfAD(), m_DateTime.Date.sDate.year, | 372 FX_DaysToDate(ut.GetDayOfAD(), m_DateTime.Date.sDate.year, |
373 m_DateTime.Date.sDate.month, m_DateTime.Date.sDate.day); | 373 m_DateTime.Date.sDate.month, m_DateTime.Date.sDate.day); |
374 m_DateTime.Date.sDate.day = ut.GetHour(); | 374 m_DateTime.Date.sDate.day = ut.GetHour(); |
375 m_DateTime.Time.sTime.minute = ut.GetMinute(); | 375 m_DateTime.Time.sTime.minute = ut.GetMinute(); |
376 m_DateTime.Time.sTime.second = ut.GetSecond(); | 376 m_DateTime.Time.sTime.second = ut.GetSecond(); |
377 m_DateTime.Time.sTime.millisecond = ut.GetMillisecond(); | 377 m_DateTime.Time.sTime.millisecond = ut.GetMillisecond(); |
378 return TRUE; | 378 return true; |
379 } | 379 } |
380 FX_UNITIME CFX_DateTime::ToUnitime() const { | 380 FX_UNITIME CFX_DateTime::ToUnitime() const { |
381 FX_UNITIME v = | 381 FX_UNITIME v = |
382 (int64_t)m_DateTime.Date.sDate.day * g_FXMillisecondsPerHour + | 382 (int64_t)m_DateTime.Date.sDate.day * g_FXMillisecondsPerHour + |
383 (int64_t)m_DateTime.Time.sTime.minute * g_FXMillisecondsPerMinute + | 383 (int64_t)m_DateTime.Time.sTime.minute * g_FXMillisecondsPerMinute + |
384 (int64_t)m_DateTime.Time.sTime.second * g_FXMillisecondsPerSecond + | 384 (int64_t)m_DateTime.Time.sTime.second * g_FXMillisecondsPerSecond + |
385 m_DateTime.Time.sTime.millisecond; | 385 m_DateTime.Time.sTime.millisecond; |
386 v += FX_DateToDays(m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, | 386 v += FX_DateToDays(m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, |
387 m_DateTime.Date.sDate.day, FALSE) * | 387 m_DateTime.Date.sDate.day, false) * |
388 g_FXMillisecondsPerDay; | 388 g_FXMillisecondsPerDay; |
389 return v; | 389 return v; |
390 } | 390 } |
391 int32_t CFX_DateTime::GetYear() const { | 391 int32_t CFX_DateTime::GetYear() const { |
392 return m_DateTime.Date.sDate.year; | 392 return m_DateTime.Date.sDate.year; |
393 } | 393 } |
394 uint8_t CFX_DateTime::GetMonth() const { | 394 uint8_t CFX_DateTime::GetMonth() const { |
395 return m_DateTime.Date.sDate.month; | 395 return m_DateTime.Date.sDate.month; |
396 } | 396 } |
397 uint8_t CFX_DateTime::GetDay() const { | 397 uint8_t CFX_DateTime::GetDay() const { |
398 return m_DateTime.Date.sDate.day; | 398 return m_DateTime.Date.sDate.day; |
399 } | 399 } |
400 FX_WEEKDAY CFX_DateTime::GetDayOfWeek() const { | 400 FX_WEEKDAY CFX_DateTime::GetDayOfWeek() const { |
401 int32_t v = (int32_t)(FX_DateToDays(m_DateTime.Date.sDate.year, | 401 int32_t v = (int32_t)(FX_DateToDays(m_DateTime.Date.sDate.year, |
402 m_DateTime.Date.sDate.month, | 402 m_DateTime.Date.sDate.month, |
403 m_DateTime.Date.sDate.day, TRUE) % | 403 m_DateTime.Date.sDate.day, true) % |
404 7); | 404 7); |
405 if (v < 0) { | 405 if (v < 0) { |
406 v += 7; | 406 v += 7; |
407 } | 407 } |
408 return (FX_WEEKDAY)v; | 408 return (FX_WEEKDAY)v; |
409 } | 409 } |
410 uint16_t CFX_DateTime::GetDayOfYear() const { | 410 uint16_t CFX_DateTime::GetDayOfYear() const { |
411 return FX_DaysBeforeMonthInYear(m_DateTime.Date.sDate.year, | 411 return FX_DaysBeforeMonthInYear(m_DateTime.Date.sDate.year, |
412 m_DateTime.Date.sDate.month) + | 412 m_DateTime.Date.sDate.month) + |
413 m_DateTime.Date.sDate.day; | 413 m_DateTime.Date.sDate.day; |
414 } | 414 } |
415 int64_t CFX_DateTime::GetDayOfAD() const { | 415 int64_t CFX_DateTime::GetDayOfAD() const { |
416 return FX_DateToDays(m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, | 416 return FX_DateToDays(m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, |
417 m_DateTime.Date.sDate.day, TRUE); | 417 m_DateTime.Date.sDate.day, true); |
418 } | 418 } |
419 uint8_t CFX_DateTime::GetHour() const { | 419 uint8_t CFX_DateTime::GetHour() const { |
420 return m_DateTime.Date.sDate.day; | 420 return m_DateTime.Date.sDate.day; |
421 } | 421 } |
422 uint8_t CFX_DateTime::GetMinute() const { | 422 uint8_t CFX_DateTime::GetMinute() const { |
423 return m_DateTime.Time.sTime.minute; | 423 return m_DateTime.Time.sTime.minute; |
424 } | 424 } |
425 uint8_t CFX_DateTime::GetSecond() const { | 425 uint8_t CFX_DateTime::GetSecond() const { |
426 return m_DateTime.Time.sTime.second; | 426 return m_DateTime.Time.sTime.second; |
427 } | 427 } |
428 uint16_t CFX_DateTime::GetMillisecond() const { | 428 uint16_t CFX_DateTime::GetMillisecond() const { |
429 return m_DateTime.Time.sTime.millisecond; | 429 return m_DateTime.Time.sTime.millisecond; |
430 } | 430 } |
431 FX_BOOL CFX_DateTime::AddYears(int32_t iYears) { | 431 bool CFX_DateTime::AddYears(int32_t iYears) { |
432 if (iYears == 0) { | 432 if (iYears == 0) { |
433 return FALSE; | 433 return false; |
434 } | 434 } |
435 int32_t v = m_DateTime.Date.sDate.year + iYears; | 435 int32_t v = m_DateTime.Date.sDate.year + iYears; |
436 if (v >= 0 && m_DateTime.Date.sDate.year < 0) { | 436 if (v >= 0 && m_DateTime.Date.sDate.year < 0) { |
437 v++; | 437 v++; |
438 } else if (v <= 0 && m_DateTime.Date.sDate.year > 0) { | 438 } else if (v <= 0 && m_DateTime.Date.sDate.year > 0) { |
439 v--; | 439 v--; |
440 } | 440 } |
441 m_DateTime.Date.sDate.year = v; | 441 m_DateTime.Date.sDate.year = v; |
442 return TRUE; | 442 return true; |
443 } | 443 } |
444 FX_BOOL CFX_DateTime::AddMonths(int32_t iMonths) { | 444 bool CFX_DateTime::AddMonths(int32_t iMonths) { |
445 if (iMonths == 0) { | 445 if (iMonths == 0) { |
446 return FALSE; | 446 return false; |
447 } | 447 } |
448 FX_BOOL b = iMonths > 0; | 448 bool b = iMonths > 0; |
449 iMonths += m_DateTime.Date.sDate.month; | 449 iMonths += m_DateTime.Date.sDate.month; |
450 while (iMonths < 1) { | 450 while (iMonths < 1) { |
451 m_DateTime.Date.sDate.year--; | 451 m_DateTime.Date.sDate.year--; |
452 if (m_DateTime.Date.sDate.year == 0) { | 452 if (m_DateTime.Date.sDate.year == 0) { |
453 m_DateTime.Date.sDate.year = -1; | 453 m_DateTime.Date.sDate.year = -1; |
454 } | 454 } |
455 iMonths += 12; | 455 iMonths += 12; |
456 } | 456 } |
457 while (iMonths > 12) { | 457 while (iMonths > 12) { |
458 m_DateTime.Date.sDate.year++; | 458 m_DateTime.Date.sDate.year++; |
459 if (m_DateTime.Date.sDate.year == 0) { | 459 if (m_DateTime.Date.sDate.year == 0) { |
460 m_DateTime.Date.sDate.year = 1; | 460 m_DateTime.Date.sDate.year = 1; |
461 } | 461 } |
462 iMonths -= 12; | 462 iMonths -= 12; |
463 } | 463 } |
464 if (m_DateTime.Date.sDate.year == 0) { | 464 if (m_DateTime.Date.sDate.year == 0) { |
465 m_DateTime.Date.sDate.year = b ? 1 : -1; | 465 m_DateTime.Date.sDate.year = b ? 1 : -1; |
466 } | 466 } |
467 m_DateTime.Date.sDate.month = (uint8_t)iMonths; | 467 m_DateTime.Date.sDate.month = (uint8_t)iMonths; |
468 return TRUE; | 468 return true; |
469 } | 469 } |
470 FX_BOOL CFX_DateTime::AddDays(int32_t iDays) { | 470 bool CFX_DateTime::AddDays(int32_t iDays) { |
471 if (iDays == 0) { | 471 if (iDays == 0) { |
472 return FALSE; | 472 return false; |
473 } | 473 } |
474 int64_t v1 = | 474 int64_t v1 = |
475 FX_DateToDays(m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, | 475 FX_DateToDays(m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, |
476 m_DateTime.Date.sDate.day, TRUE); | 476 m_DateTime.Date.sDate.day, true); |
477 int64_t v2 = v1 + iDays; | 477 int64_t v2 = v1 + iDays; |
478 if (v2 <= 0 && v1 > 0) { | 478 if (v2 <= 0 && v1 > 0) { |
479 v2--; | 479 v2--; |
480 } else if (v2 >= 0 && v1 < 0) { | 480 } else if (v2 >= 0 && v1 < 0) { |
481 v2++; | 481 v2++; |
482 } | 482 } |
483 FX_DaysToDate(v2, m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, | 483 FX_DaysToDate(v2, m_DateTime.Date.sDate.year, m_DateTime.Date.sDate.month, |
484 m_DateTime.Date.sDate.day); | 484 m_DateTime.Date.sDate.day); |
485 return TRUE; | 485 return true; |
486 } | 486 } |
487 FX_BOOL CFX_DateTime::AddHours(int32_t iHours) { | 487 bool CFX_DateTime::AddHours(int32_t iHours) { |
488 if (iHours == 0) { | 488 if (iHours == 0) { |
489 return FALSE; | 489 return false; |
490 } | 490 } |
491 iHours += m_DateTime.Date.sDate.day; | 491 iHours += m_DateTime.Date.sDate.day; |
492 int32_t iDays = iHours / 24; | 492 int32_t iDays = iHours / 24; |
493 iHours %= 24; | 493 iHours %= 24; |
494 if (iHours < 0) { | 494 if (iHours < 0) { |
495 iDays--, iHours += 24; | 495 iDays--, iHours += 24; |
496 } | 496 } |
497 m_DateTime.Date.sDate.day = (uint8_t)iHours; | 497 m_DateTime.Date.sDate.day = (uint8_t)iHours; |
498 if (iDays != 0) { | 498 if (iDays != 0) { |
499 AddDays(iDays); | 499 AddDays(iDays); |
500 } | 500 } |
501 return TRUE; | 501 return true; |
502 } | 502 } |
503 FX_BOOL CFX_DateTime::AddMinutes(int32_t iMinutes) { | 503 bool CFX_DateTime::AddMinutes(int32_t iMinutes) { |
504 if (iMinutes == 0) { | 504 if (iMinutes == 0) { |
505 return FALSE; | 505 return false; |
506 } | 506 } |
507 iMinutes += m_DateTime.Time.sTime.minute; | 507 iMinutes += m_DateTime.Time.sTime.minute; |
508 int32_t iHours = iMinutes / 60; | 508 int32_t iHours = iMinutes / 60; |
509 iMinutes %= 60; | 509 iMinutes %= 60; |
510 if (iMinutes < 0) { | 510 if (iMinutes < 0) { |
511 iHours--, iMinutes += 60; | 511 iHours--, iMinutes += 60; |
512 } | 512 } |
513 m_DateTime.Time.sTime.minute = (uint8_t)iMinutes; | 513 m_DateTime.Time.sTime.minute = (uint8_t)iMinutes; |
514 if (iHours != 0) { | 514 if (iHours != 0) { |
515 AddHours(iHours); | 515 AddHours(iHours); |
516 } | 516 } |
517 return TRUE; | 517 return true; |
518 } | 518 } |
519 FX_BOOL CFX_DateTime::AddSeconds(int32_t iSeconds) { | 519 bool CFX_DateTime::AddSeconds(int32_t iSeconds) { |
520 if (iSeconds == 0) { | 520 if (iSeconds == 0) { |
521 return FALSE; | 521 return false; |
522 } | 522 } |
523 iSeconds += m_DateTime.Time.sTime.second; | 523 iSeconds += m_DateTime.Time.sTime.second; |
524 int32_t iMinutes = iSeconds / 60; | 524 int32_t iMinutes = iSeconds / 60; |
525 iSeconds %= 60; | 525 iSeconds %= 60; |
526 if (iSeconds < 0) { | 526 if (iSeconds < 0) { |
527 iMinutes--, iSeconds += 60; | 527 iMinutes--, iSeconds += 60; |
528 } | 528 } |
529 m_DateTime.Time.sTime.second = (uint8_t)iSeconds; | 529 m_DateTime.Time.sTime.second = (uint8_t)iSeconds; |
530 if (iMinutes != 0) { | 530 if (iMinutes != 0) { |
531 AddMinutes(iMinutes); | 531 AddMinutes(iMinutes); |
532 } | 532 } |
533 return TRUE; | 533 return true; |
534 } | 534 } |
535 FX_BOOL CFX_DateTime::AddMilliseconds(int32_t iMilliseconds) { | 535 bool CFX_DateTime::AddMilliseconds(int32_t iMilliseconds) { |
536 if (iMilliseconds == 0) { | 536 if (iMilliseconds == 0) { |
537 return FALSE; | 537 return false; |
538 } | 538 } |
539 iMilliseconds += m_DateTime.Time.sTime.millisecond; | 539 iMilliseconds += m_DateTime.Time.sTime.millisecond; |
540 int32_t iSeconds = (int32_t)(iMilliseconds / g_FXMillisecondsPerSecond); | 540 int32_t iSeconds = (int32_t)(iMilliseconds / g_FXMillisecondsPerSecond); |
541 iMilliseconds %= g_FXMillisecondsPerSecond; | 541 iMilliseconds %= g_FXMillisecondsPerSecond; |
542 if (iMilliseconds < 0) { | 542 if (iMilliseconds < 0) { |
543 iSeconds--, iMilliseconds += g_FXMillisecondsPerSecond; | 543 iSeconds--, iMilliseconds += g_FXMillisecondsPerSecond; |
544 } | 544 } |
545 m_DateTime.Time.sTime.millisecond = (uint16_t)iMilliseconds; | 545 m_DateTime.Time.sTime.millisecond = (uint16_t)iMilliseconds; |
546 if (iSeconds != 0) { | 546 if (iSeconds != 0) { |
547 AddSeconds(iSeconds); | 547 AddSeconds(iSeconds); |
548 } | 548 } |
549 return TRUE; | 549 return true; |
550 } | 550 } |
OLD | NEW |