summaryrefslogtreecommitdiff
path: root/xfa/fgas/localization/fgas_datetime.cpp
diff options
context:
space:
mode:
authorDan Sinclair <dsinclair@chromium.org>2017-03-20 15:04:16 -0400
committerChromium commit bot <commit-bot@chromium.org>2017-03-20 20:21:31 +0000
commitcf2d0ca3d5ba890dca4e2735915739430a43cfa0 (patch)
tree3045ca50e2305ea348eb743576e04bdf8ce144f1 /xfa/fgas/localization/fgas_datetime.cpp
parent2a6482c19c5577924f73d100431acceb8c874e04 (diff)
downloadpdfium-cf2d0ca3d5ba890dca4e2735915739430a43cfa0.tar.xz
Simplify date time code
This CL removes the CFX_DateTime class and moves the one used method into the CFX_Unitime class. Change-Id: I89f6d099b2c436d8f12b9dc2c5f10ac236ad56ef Reviewed-on: https://pdfium-review.googlesource.com/3104 Reviewed-by: Nicolás Peña <npm@chromium.org> Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'xfa/fgas/localization/fgas_datetime.cpp')
-rw-r--r--xfa/fgas/localization/fgas_datetime.cpp182
1 files changed, 11 insertions, 171 deletions
diff --git a/xfa/fgas/localization/fgas_datetime.cpp b/xfa/fgas/localization/fgas_datetime.cpp
index 0d5b2b9b45..973fb3b5e3 100644
--- a/xfa/fgas/localization/fgas_datetime.cpp
+++ b/xfa/fgas/localization/fgas_datetime.cpp
@@ -25,22 +25,6 @@ const int32_t g_FXDaysBeforeLeapMonth[12] = {0, 31, 60, 91, 121, 152,
182, 213, 244, 274, 305, 335};
const int32_t g_FXDaysPerYear = 365;
const int32_t g_FXDaysPerLeapYear = 366;
-const int32_t g_FXDaysPer4Years = 1461;
-const int32_t g_FXDaysPer100Years = 36524;
-const int32_t g_FXDaysPer400Years = 146097;
-const int64_t g_FXMillisecondsPerSecond = 1000;
-const int64_t g_FXMillisecondsPerMinute = 60000;
-const int64_t g_FXMillisecondsPerHour = 3600000;
-const int64_t g_FXMillisecondsPerDay = 86400000;
-
-int64_t GetDayOfAD(int64_t unitime) {
- bool bBC = unitime < 0;
- int64_t iDays = unitime / g_FXMillisecondsPerDay;
- iDays += bBC ? -1 : 0;
- if (bBC && (unitime % g_FXMillisecondsPerDay) == 0)
- iDays++;
- return iDays;
-}
int32_t DaysBeforeMonthInYear(int32_t iYear, uint8_t iMonth) {
ASSERT(iYear != 0);
@@ -79,64 +63,6 @@ int64_t DateToDays(int32_t iYear,
iYear / 400;
}
-void DaysToDate(int64_t iDays,
- int32_t* retYear,
- uint8_t* retMonth,
- uint8_t* retDay) {
- bool bBC = iDays < 0;
- if (bBC)
- iDays = -iDays;
-
- int32_t iYear = 1;
- uint8_t iMonth = 1;
- uint8_t iDay = 1;
- if (iDays >= g_FXDaysPer400Years) {
- iYear += static_cast<int32_t>(iDays / g_FXDaysPer400Years * 400);
- iDays %= g_FXDaysPer400Years;
- }
-
- if (iDays >= g_FXDaysPer100Years) {
- if (iDays == g_FXDaysPer100Years * 4) {
- iYear += 300;
- iDays -= g_FXDaysPer100Years * 3;
- } else {
- iYear += static_cast<int32_t>(iDays / g_FXDaysPer100Years * 100);
- iDays %= g_FXDaysPer100Years;
- }
- }
-
- if (iDays >= g_FXDaysPer4Years) {
- iYear += static_cast<int32_t>(iDays / g_FXDaysPer4Years * 4);
- iDays %= g_FXDaysPer4Years;
- }
-
- while (true) {
- int32_t iYearDays = DaysInYear(iYear);
- if (iDays < iYearDays) {
- if (bBC) {
- iYear = -iYear;
- iDays = iYearDays - iDays;
- }
- break;
- }
- iYear++;
- iDays -= iYearDays;
- }
- while (true) {
- int32_t iMonthDays = FX_DaysInMonth(iYear, iMonth);
- if (iDays < iMonthDays)
- break;
-
- iMonth++;
- iDays -= iMonthDays;
- }
- iDay += static_cast<uint8_t>(iDays);
-
- *retYear = iYear;
- *retMonth = iMonth;
- *retDay = iDay;
-}
-
struct FXUT_SYSTEMTIME {
uint16_t wYear;
uint16_t wMonth;
@@ -145,7 +71,7 @@ struct FXUT_SYSTEMTIME {
uint16_t wHour;
uint16_t wMinute;
uint16_t wSecond;
- uint16_t wMilliseconds;
+ uint16_t wMillisecond;
};
} // namespace
@@ -182,107 +108,21 @@ void CFX_Unitime::Now() {
utLocal.wHour = st.tm_hour;
utLocal.wMinute = st.tm_min;
utLocal.wSecond = st.tm_sec;
- utLocal.wMilliseconds = curTime.tv_usec / 1000;
+ utLocal.wMillisecond = curTime.tv_usec / 1000;
#endif // _FX_OS_ == _FX_WIN32_DESKTOP_ || _FX_OS_ == _FX_WIN32_MOBILE_ || \
// _FX_OS_ == _FX_WIN64_
- Set(utLocal.wYear, static_cast<uint8_t>(utLocal.wMonth),
- static_cast<uint8_t>(utLocal.wDay), static_cast<uint8_t>(utLocal.wHour),
- static_cast<uint8_t>(utLocal.wMinute),
- static_cast<uint8_t>(utLocal.wSecond),
- static_cast<uint16_t>(utLocal.wMilliseconds));
-}
-
-void CFX_Unitime::Set(int32_t year,
- uint8_t month,
- uint8_t day,
- uint8_t hour,
- uint8_t minute,
- uint8_t second,
- uint16_t millisecond) {
- ASSERT(hour <= 23);
- ASSERT(minute <= 59);
- ASSERT(second <= 59);
- ASSERT(millisecond <= 999);
-
- m_iUnitime = static_cast<int64_t>(hour) * g_FXMillisecondsPerHour +
- static_cast<int64_t>(minute) * g_FXMillisecondsPerMinute +
- static_cast<int64_t>(second) * g_FXMillisecondsPerSecond +
- millisecond;
- if (year <= 0)
- return;
-
- m_iUnitime += DateToDays(year, month, day, false) * g_FXMillisecondsPerDay;
-}
-
-int32_t CFX_Unitime::GetYear() const {
- int32_t iYear;
- uint8_t iMonth, iDay;
- DaysToDate(GetDayOfAD(m_iUnitime), &iYear, &iMonth, &iDay);
- return iYear;
-}
-
-uint8_t CFX_Unitime::GetMonth() const {
- int32_t iYear;
- uint8_t iMonth, iDay;
- DaysToDate(GetDayOfAD(m_iUnitime), &iYear, &iMonth, &iDay);
- return iMonth;
-}
-
-uint8_t CFX_Unitime::GetDay() const {
- int32_t iYear;
- uint8_t iMonth, iDay;
- DaysToDate(GetDayOfAD(m_iUnitime), &iYear, &iMonth, &iDay);
- return iDay;
-}
-
-uint8_t CFX_Unitime::GetHour() const {
- int32_t v = static_cast<int32_t>(m_iUnitime % g_FXMillisecondsPerDay);
- if (v < 0)
- v += g_FXMillisecondsPerDay;
- return static_cast<uint8_t>(v / g_FXMillisecondsPerHour);
-}
-
-uint8_t CFX_Unitime::GetMinute() const {
- int32_t v = static_cast<int32_t>(m_iUnitime % g_FXMillisecondsPerHour);
- if (v < 0)
- v += g_FXMillisecondsPerHour;
- return static_cast<uint8_t>(v / g_FXMillisecondsPerMinute);
-}
-
-uint8_t CFX_Unitime::GetSecond() const {
- int32_t v = static_cast<int32_t>(m_iUnitime % g_FXMillisecondsPerMinute);
- if (v < 0)
- v += g_FXMillisecondsPerMinute;
- return static_cast<uint8_t>(v / g_FXMillisecondsPerSecond);
-}
-
-uint16_t CFX_Unitime::GetMillisecond() const {
- int32_t v = static_cast<int32_t>(m_iUnitime % g_FXMillisecondsPerSecond);
- if (v < 0)
- v += g_FXMillisecondsPerSecond;
- return static_cast<uint16_t>(v);
-}
-
-bool CFX_DateTime::Set(int32_t year, uint8_t month, uint8_t day) {
- ASSERT(year != 0);
- ASSERT(month >= 1 && month <= 12);
- ASSERT(day >= 1 && day <= FX_DaysInMonth(year, month));
- m_DateTime.Date.sDate.year = year;
- m_DateTime.Date.sDate.month = month;
- m_DateTime.Date.sDate.day = day;
- m_DateTime.Time.sTime.hour = 0;
- m_DateTime.Time.sTime.minute = 0;
- m_DateTime.Time.sTime.second = 0;
- m_DateTime.Time.sTime.millisecond = 0;
- return true;
+ year_ = utLocal.wYear;
+ month_ = static_cast<uint8_t>(utLocal.wMonth);
+ day_ = static_cast<uint8_t>(utLocal.wDay);
+ hour_ = static_cast<uint8_t>(utLocal.wHour);
+ minute_ = static_cast<uint8_t>(utLocal.wMinute);
+ second_ = static_cast<uint8_t>(utLocal.wSecond);
+ millisecond_ = static_cast<uint16_t>(utLocal.wMillisecond);
}
-int32_t CFX_DateTime::GetDayOfWeek() const {
- int32_t v = static_cast<int32_t>(DateToDays(m_DateTime.Date.sDate.year,
- m_DateTime.Date.sDate.month,
- m_DateTime.Date.sDate.day, true) %
- 7);
+int32_t CFX_Unitime::GetDayOfWeek() const {
+ int32_t v = static_cast<int32_t>(DateToDays(year_, month_, day_, true) % 7);
if (v < 0)
v += 7;
return v;