summaryrefslogtreecommitdiff
path: root/xfa/fxfa
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/fxfa
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/fxfa')
-rw-r--r--xfa/fxfa/app/xfa_ffnotify.cpp1
-rw-r--r--xfa/fxfa/app/xfa_fftextedit.cpp11
-rw-r--r--xfa/fxfa/parser/xfa_localevalue.cpp77
-rw-r--r--xfa/fxfa/parser/xfa_localevalue.h2
4 files changed, 45 insertions, 46 deletions
diff --git a/xfa/fxfa/app/xfa_ffnotify.cpp b/xfa/fxfa/app/xfa_ffnotify.cpp
index ce6d7db4e2..fb154d8a9a 100644
--- a/xfa/fxfa/app/xfa_ffnotify.cpp
+++ b/xfa/fxfa/app/xfa_ffnotify.cpp
@@ -264,6 +264,7 @@ void CXFA_FFNotify::OpenDropDownList(CXFA_FFWidget* hWidget) {
CFX_WideString CXFA_FFNotify::GetCurrentDateTime() {
CFX_Unitime dataTime;
dataTime.Now();
+
CFX_WideString wsDateTime;
wsDateTime.Format(L"%d%02d%02dT%02d%02d%02d", dataTime.GetYear(),
dataTime.GetMonth(), dataTime.GetDay(), dataTime.GetHour(),
diff --git a/xfa/fxfa/app/xfa_fftextedit.cpp b/xfa/fxfa/app/xfa_fftextedit.cpp
index 50685c7e40..b4560c88ed 100644
--- a/xfa/fxfa/app/xfa_fftextedit.cpp
+++ b/xfa/fxfa/app/xfa_fftextedit.cpp
@@ -522,7 +522,7 @@ bool CXFA_FFDateTimeEdit::LoadWidget() {
if (!wsText.IsEmpty()) {
CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);
CFX_Unitime date = lcValue.GetDate();
- if (date.ToInt64() != 0)
+ if (date.IsSet())
pWidget->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
}
} break;
@@ -619,8 +619,8 @@ bool CXFA_FFDateTimeEdit::UpdateFWLData() {
CXFA_LocaleValue lcValue = XFA_GetLocaleValue(m_pDataAcc);
CFX_Unitime date = lcValue.GetDate();
if (lcValue.IsValid()) {
- if (date.ToInt64() != 0) {
- ((CFWL_DateTimePicker*)m_pNormalWidget)
+ if (date.IsSet()) {
+ static_cast<CFWL_DateTimePicker*>(m_pNormalWidget)
->SetCurSel(date.GetYear(), date.GetMonth(), date.GetDay());
}
}
@@ -646,9 +646,8 @@ void CXFA_FFDateTimeEdit::OnSelectChanged(CFWL_Widget* pWidget,
CFX_WideString wsPicture;
m_pDataAcc->GetPictureContent(wsPicture, XFA_VALUEPICTURE_Edit);
CXFA_LocaleValue date(XFA_VT_DATE, GetDoc()->GetXFADoc()->GetLocalMgr());
- CFX_Unitime dt;
- dt.Set(iYear, iMonth, iDay, 0, 0, 0, 0);
- date.SetDate(dt);
+ date.SetDate(CFX_Unitime(iYear, iMonth, iDay, 0, 0, 0, 0));
+
CFX_WideString wsDate;
date.FormatPatterns(wsDate, wsPicture, m_pDataAcc->GetLocal(),
XFA_VALUEPICTURE_Edit);
diff --git a/xfa/fxfa/parser/xfa_localevalue.cpp b/xfa/fxfa/parser/xfa_localevalue.cpp
index cddfff3134..770b87ee14 100644
--- a/xfa/fxfa/parser/xfa_localevalue.cpp
+++ b/xfa/fxfa/parser/xfa_localevalue.cpp
@@ -132,10 +132,10 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
break;
case FX_LOCALECATEGORY_Date: {
CFX_Unitime dt;
- bRet = ValidateCanonicalDate(wsValue, dt);
+ bRet = ValidateCanonicalDate(wsValue, &dt);
if (!bRet) {
bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Date,
- dt);
+ &dt);
if (!bRet) {
bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput,
FX_DATETIMETYPE_Date);
@@ -145,8 +145,8 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
}
case FX_LOCALECATEGORY_Time: {
CFX_Unitime dt;
- bRet =
- pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, dt);
+ bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time,
+ &dt);
if (!bRet) {
bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput,
FX_DATETIMETYPE_Time);
@@ -156,7 +156,7 @@ bool CXFA_LocaleValue::ValidateValue(const CFX_WideString& wsValue,
case FX_LOCALECATEGORY_DateTime: {
CFX_Unitime dt;
bRet = pFormat->ParseDateTime(wsValue, wsFormat,
- FX_DATETIMETYPE_DateTime, dt);
+ FX_DATETIMETYPE_DateTime, &dt);
if (!bRet) {
bRet = pFormat->FormatDateTime(wsValue, wsFormat, wsOutput,
FX_DATETIMETYPE_DateTime);
@@ -351,7 +351,7 @@ double CXFA_LocaleValue::GetDoubleNum() const {
CFX_Unitime CXFA_LocaleValue::GetDate() const {
if (m_bValid && m_dwType == XFA_VT_DATE) {
CFX_Unitime dt;
- FX_DateFromCanonical(m_wsValue, dt);
+ FX_DateFromCanonical(m_wsValue, &dt);
return dt;
}
return CFX_Unitime();
@@ -359,9 +359,10 @@ CFX_Unitime CXFA_LocaleValue::GetDate() const {
CFX_Unitime CXFA_LocaleValue::GetTime() const {
if (m_bValid && m_dwType == XFA_VT_TIME) {
- CFX_Unitime dt(0);
ASSERT(m_pLocaleMgr);
- FX_TimeFromCanonical(m_wsValue.AsStringC(), dt,
+
+ CFX_Unitime dt;
+ FX_TimeFromCanonical(m_wsValue.AsStringC(), &dt,
m_pLocaleMgr->GetDefLocale());
return dt;
}
@@ -372,10 +373,10 @@ CFX_Unitime CXFA_LocaleValue::GetDateTime() const {
if (m_bValid && m_dwType == XFA_VT_DATETIME) {
int32_t index = m_wsValue.Find('T');
CFX_Unitime dt;
- FX_DateFromCanonical(m_wsValue.Left(index), dt);
+ FX_DateFromCanonical(m_wsValue.Left(index), &dt);
ASSERT(m_pLocaleMgr);
FX_TimeFromCanonical(
- m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), dt,
+ m_wsValue.Right(m_wsValue.GetLength() - index - 1).AsStringC(), &dt,
m_pLocaleMgr->GetDefLocale());
return dt;
}
@@ -560,20 +561,20 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
CFX_Unitime dt;
switch (dwVType) {
case XFA_VT_DATE: {
- if (ValidateCanonicalDate(wsValue, dt)) {
+ if (ValidateCanonicalDate(wsValue, &dt))
return true;
- }
+
CFX_WideString wsDate, wsTime;
if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) &&
- ValidateCanonicalDate(wsDate, dt)) {
+ ValidateCanonicalDate(wsDate, &dt)) {
return true;
}
return false;
}
case XFA_VT_TIME: {
- if (ValidateCanonicalTime(wsValue)) {
+ if (ValidateCanonicalTime(wsValue))
return true;
- }
+
CFX_WideString wsDate, wsTime;
if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) &&
ValidateCanonicalTime(wsTime)) {
@@ -584,7 +585,7 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
case XFA_VT_DATETIME: {
CFX_WideString wsDate, wsTime;
if (XFA_ValueSplitDateTime(wsValue, wsDate, wsTime) &&
- ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime)) {
+ ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime)) {
return true;
}
} break;
@@ -592,7 +593,7 @@ bool CXFA_LocaleValue::ValidateCanonicalValue(const CFX_WideString& wsValue,
return true;
}
bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate,
- CFX_Unitime& unDate) {
+ CFX_Unitime* unDate) {
const uint16_t LastDay[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
const uint16_t wCountY = 4, wCountM = 2, wCountD = 2;
int nLen = wsDate.GetLength();
@@ -671,12 +672,12 @@ bool CXFA_LocaleValue::ValidateCanonicalDate(const CFX_WideString& wsDate,
} else if (wDay > LastDay[wMonth - 1]) {
return false;
}
- CFX_Unitime ut;
- ut.Set(wYear, static_cast<uint8_t>(wMonth), static_cast<uint8_t>(wDay), 0, 0,
- 0, 0);
- unDate = unDate + ut;
+
+ unDate->SetDate(wYear, static_cast<uint8_t>(wMonth),
+ static_cast<uint8_t>(wDay));
return true;
}
+
bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
int nLen = wsTime.GetLength();
if (nLen < 2)
@@ -768,25 +769,26 @@ bool CXFA_LocaleValue::ValidateCanonicalTime(const CFX_WideString& wsTime) {
return nIndex == nLen && wHour < 24 && wMinute < 60 && wSecond < 60 &&
wFraction <= 999;
}
+
bool CXFA_LocaleValue::ValidateCanonicalDateTime(
const CFX_WideString& wsDateTime) {
CFX_WideString wsDate, wsTime;
- if (wsDateTime.IsEmpty()) {
+ if (wsDateTime.IsEmpty())
return false;
- }
+
int nSplitIndex = -1;
nSplitIndex = wsDateTime.Find('T');
- if (nSplitIndex < 0) {
+ if (nSplitIndex < 0)
nSplitIndex = wsDateTime.Find(' ');
- }
- if (nSplitIndex < 0) {
+ if (nSplitIndex < 0)
return false;
- }
+
wsDate = wsDateTime.Left(nSplitIndex);
wsTime = wsDateTime.Right(wsDateTime.GetLength() - nSplitIndex - 1);
CFX_Unitime dt;
- return ValidateCanonicalDate(wsDate, dt) && ValidateCanonicalTime(wsTime);
+ return ValidateCanonicalDate(wsDate, &dt) && ValidateCanonicalTime(wsTime);
}
+
bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue,
const CFX_WideString& wsPattern,
IFX_Locale* pLocale) {
@@ -828,32 +830,29 @@ bool CXFA_LocaleValue::ParsePatternValue(const CFX_WideString& wsValue,
break;
case FX_LOCALECATEGORY_Date: {
CFX_Unitime dt;
- bRet = ValidateCanonicalDate(wsValue, dt);
+ bRet = ValidateCanonicalDate(wsValue, &dt);
if (!bRet) {
bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Date,
- dt);
+ &dt);
}
- if (bRet) {
+ if (bRet)
SetDate(dt);
- }
break;
}
case FX_LOCALECATEGORY_Time: {
CFX_Unitime dt;
- bRet =
- pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time, dt);
- if (bRet) {
+ bRet = pFormat->ParseDateTime(wsValue, wsFormat, FX_DATETIMETYPE_Time,
+ &dt);
+ if (bRet)
SetTime(dt);
- }
break;
}
case FX_LOCALECATEGORY_DateTime: {
CFX_Unitime dt;
bRet = pFormat->ParseDateTime(wsValue, wsFormat,
- FX_DATETIMETYPE_DateTime, dt);
- if (bRet) {
+ FX_DATETIMETYPE_DateTime, &dt);
+ if (bRet)
SetDateTime(dt);
- }
break;
}
default:
diff --git a/xfa/fxfa/parser/xfa_localevalue.h b/xfa/fxfa/parser/xfa_localevalue.h
index a239fa7609..cea5eb1dc5 100644
--- a/xfa/fxfa/parser/xfa_localevalue.h
+++ b/xfa/fxfa/parser/xfa_localevalue.h
@@ -54,7 +54,7 @@ class CXFA_LocaleValue {
IFX_Locale* pLocale,
XFA_VALUEPICTURE eValueType) const;
bool ValidateCanonicalValue(const CFX_WideString& wsValue, uint32_t dwVType);
- bool ValidateCanonicalDate(const CFX_WideString& wsDate, CFX_Unitime& unDate);
+ bool ValidateCanonicalDate(const CFX_WideString& wsDate, CFX_Unitime* unDate);
bool ValidateCanonicalTime(const CFX_WideString& wsTime);
bool ValidateCanonicalDateTime(const CFX_WideString& wsDateTime);
void GetNumbericFormat(CFX_WideString& wsFormat,