Index: xfa/fxfa/fm2js/xfa_fm2jscontext.cpp |
diff --git a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp |
index 7841c959e44057dfa4463f761ae9e63416fcd0a2..10f6add68486b0bcbfad2eb93f54ae8001ec3792 100644 |
--- a/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp |
+++ b/xfa/fxfa/fm2js/xfa_fm2jscontext.cpp |
@@ -1228,42 +1228,37 @@ void CXFA_FM2JSContext::LocalDateFmt(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if (argc < 3) { |
- FX_BOOL bFlags = FALSE; |
- int32_t iStyle = 0; |
- CFX_ByteString szLocal; |
- if (argc > 0) { |
- std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); |
- if (FXJSE_Value_IsNull(argStyle.get())) { |
- bFlags = TRUE; |
- } |
- iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); |
- if (iStyle > 4 || iStyle < 0) { |
- iStyle = 0; |
- } |
- } |
- if (argc == 2) { |
- std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); |
- if (FXJSE_Value_IsNull(argLocal.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(argLocal.get(), szLocal); |
- } |
+ if (argc >= 3) { |
Tom Sepez
2016/06/06 17:01:53
maybe should be > 2 for parallelism with line 1238
dsinclair
2016/06/06 18:07:54
Done.
|
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalDateFmt"); |
+ return; |
+ } |
+ |
+ int32_t iStyle = 0; |
+ if (argc > 0) { |
+ std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); |
+ if (FXJSE_Value_IsNull(argStyle.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (!bFlags) { |
- CFX_ByteString formatStr; |
- GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE); |
- if (formatStr.IsEmpty()) { |
- formatStr = ""; |
- } |
- FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC()); |
- } else { |
+ iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); |
+ if (iStyle > 4 || iStyle < 0) |
+ iStyle = 0; |
+ } |
+ |
+ CFX_ByteString szLocal; |
+ if (argc == 2) { |
Tom Sepez
2016/06/06 17:01:53
probably should be > 1 for parallelism with line 1
dsinclair
2016/06/06 18:07:54
Done.
|
+ std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); |
+ if (FXJSE_Value_IsNull(argLocal.get())) { |
FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- } else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalDateFmt"); |
+ ValueToUTF8String(argLocal.get(), szLocal); |
} |
+ |
+ CFX_ByteString formatStr; |
+ GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE); |
+ FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC()); |
} |
// static |
@@ -1271,42 +1266,37 @@ void CXFA_FM2JSContext::LocalTimeFmt(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if (argc < 3) { |
- FX_BOOL bFlags = FALSE; |
- int32_t iStyle = 0; |
- CFX_ByteString szLocal; |
- if (argc > 0) { |
- std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); |
- if (FXJSE_Value_IsNull(argStyle.get())) { |
- bFlags = TRUE; |
- } |
- iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); |
- if (iStyle > 4 || iStyle < 0) { |
- iStyle = 0; |
- } |
- } |
- if (argc == 2) { |
- std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); |
- if (FXJSE_Value_IsNull(argLocal.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(argLocal.get(), szLocal); |
- } |
+ if (argc >= 3) { |
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalTimeFmt"); |
+ return; |
+ } |
+ |
+ int32_t iStyle = 0; |
+ if (argc > 0) { |
+ std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); |
+ if (FXJSE_Value_IsNull(argStyle.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (!bFlags) { |
- CFX_ByteString formatStr; |
- GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE); |
- if (formatStr.IsEmpty()) { |
- formatStr = ""; |
- } |
- FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC()); |
- } else { |
+ iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); |
+ if (iStyle > 4 || iStyle < 0) |
+ iStyle = 0; |
+ } |
+ |
+ CFX_ByteString szLocal; |
+ if (argc == 2) { |
+ std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); |
+ if (FXJSE_Value_IsNull(argLocal.get())) { |
FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- } else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalTimeFmt"); |
+ ValueToUTF8String(argLocal.get(), szLocal); |
} |
+ |
+ CFX_ByteString formatStr; |
+ GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE); |
+ FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC()); |
} |
// static |
@@ -1314,146 +1304,142 @@ void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if ((argc > 0) && (argc < 4)) { |
- FX_BOOL bFlags = FALSE; |
- int32_t dDate = 0; |
- CFX_ByteString formatString; |
- CFX_ByteString localString; |
- std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0); |
- if (ValueIsNull(pThis, dateValue.get())) { |
- bFlags = TRUE; |
- } else { |
- dDate = (int32_t)ValueToFloat(pThis, dateValue.get()); |
- bFlags = dDate < 1; |
+ if (argc <= 0 || argc >= 4) { |
Tom Sepez
2016/06/06 17:01:53
argc < 0 seems impossible given getlength.
if (
dsinclair
2016/06/06 18:07:54
Done. The GetLength() method returns int, so it co
|
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Date"); |
+ return; |
+ } |
+ |
+ std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0); |
+ if (ValueIsNull(pThis, dateValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ int32_t dDate = (int32_t)ValueToFloat(pThis, dateValue.get()); |
+ if (dDate < 1) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ |
+ CFX_ByteString formatString; |
+ if (argc > 1) { |
+ std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1); |
+ if (ValueIsNull(pThis, formatValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (argc > 1) { |
- std::unique_ptr<CFXJSE_Value> formatValue = |
- GetSimpleValue(pThis, args, 1); |
- if (ValueIsNull(pThis, formatValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(formatValue.get(), formatString); |
- } |
+ ValueToUTF8String(formatValue.get(), formatString); |
+ } |
+ |
+ CFX_ByteString localString; |
+ if (argc == 3) { |
+ std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
+ if (ValueIsNull(pThis, localValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (argc == 3) { |
- std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
- if (ValueIsNull(pThis, localValue.get())) { |
- bFlags = TRUE; |
+ ValueToUTF8String(localValue.get(), localString); |
+ } |
+ |
+ int32_t iYear = 1900; |
+ int32_t iMonth = 1; |
+ int32_t iDay = 1; |
+ int32_t i = 0; |
+ while (dDate > 0) { |
+ if (iMonth == 2) { |
+ if ((!((iYear + i) % 4) && ((iYear + i) % 100)) || !((iYear + i) % 400)) { |
+ if (dDate > 29) { |
+ ++iMonth; |
+ if (iMonth > 12) { |
+ iMonth = 1; |
+ ++i; |
+ } |
+ iDay = 1; |
+ dDate -= 29; |
+ } else { |
+ iDay += static_cast<int32_t>(dDate) - 1; |
+ dDate = 0; |
+ } |
} else { |
- ValueToUTF8String(localValue.get(), localString); |
- } |
- } |
- if (!bFlags) { |
- int32_t iYear = 1900; |
- int32_t iMonth = 1; |
- int32_t iDay = 1; |
- int32_t i = 0; |
- while (dDate > 0) { |
- if (iMonth == 2) { |
- if ((!((iYear + i) % 4) && ((iYear + i) % 100)) || |
- !((iYear + i) % 400)) { |
- if (dDate > 29) { |
- ++iMonth; |
- if (iMonth > 12) { |
- iMonth = 1; |
- ++i; |
- } |
- iDay = 1; |
- dDate -= 29; |
- } else { |
- iDay += static_cast<int32_t>(dDate) - 1; |
- dDate = 0; |
- } |
- } else { |
- if (dDate > 28) { |
- ++iMonth; |
- if (iMonth > 12) { |
- iMonth = 1; |
- ++i; |
- } |
- iDay = 1; |
- dDate -= 28; |
- } else { |
- iDay += static_cast<int32_t>(dDate) - 1; |
- dDate = 0; |
- } |
+ if (dDate > 28) { |
+ ++iMonth; |
+ if (iMonth > 12) { |
+ iMonth = 1; |
+ ++i; |
} |
- } else if (iMonth < 8) { |
- if ((iMonth % 2 == 0)) { |
- if (dDate > 30) { |
- ++iMonth; |
- if (iMonth > 12) { |
- iMonth = 1; |
- ++i; |
- } |
- iDay = 1; |
- dDate -= 30; |
- } else { |
- iDay += static_cast<int32_t>(dDate) - 1; |
- dDate = 0; |
- } |
- } else { |
- if (dDate > 31) { |
- ++iMonth; |
- if (iMonth > 12) { |
- iMonth = 1; |
- ++i; |
- } |
- iDay = 1; |
- dDate -= 31; |
- } else { |
- iDay += static_cast<int32_t>(dDate) - 1; |
- dDate = 0; |
- } |
+ iDay = 1; |
+ dDate -= 28; |
+ } else { |
+ iDay += static_cast<int32_t>(dDate) - 1; |
+ dDate = 0; |
+ } |
+ } |
+ } else if (iMonth < 8) { |
+ if ((iMonth % 2 == 0)) { |
+ if (dDate > 30) { |
+ ++iMonth; |
+ if (iMonth > 12) { |
+ iMonth = 1; |
+ ++i; |
} |
+ iDay = 1; |
+ dDate -= 30; |
} else { |
- if (iMonth % 2 != 0) { |
- if (dDate > 30) { |
- ++iMonth; |
- if (iMonth > 12) { |
- iMonth = 1; |
- ++i; |
- } |
- iDay = 1; |
- dDate -= 30; |
- } else { |
- iDay += static_cast<int32_t>(dDate) - 1; |
- dDate = 0; |
- } |
- } else { |
- if (dDate > 31) { |
- ++iMonth; |
- if (iMonth > 12) { |
- iMonth = 1; |
- ++i; |
- } |
- iDay = 1; |
- dDate -= 31; |
- } else { |
- iDay += static_cast<int32_t>(dDate) - 1; |
- dDate = 0; |
- } |
+ iDay += static_cast<int32_t>(dDate) - 1; |
+ dDate = 0; |
+ } |
+ } else { |
+ if (dDate > 31) { |
+ ++iMonth; |
+ if (iMonth > 12) { |
+ iMonth = 1; |
+ ++i; |
} |
+ iDay = 1; |
+ dDate -= 31; |
+ } else { |
+ iDay += static_cast<int32_t>(dDate) - 1; |
+ dDate = 0; |
} |
} |
- CFX_ByteString szIsoDateString; |
- szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay); |
- CFX_ByteString szLocalDateString; |
- IsoDate2Local(pThis, szIsoDateString.AsStringC(), |
- formatString.AsStringC(), localString.AsStringC(), |
- szLocalDateString); |
- if (szLocalDateString.IsEmpty()) { |
- szLocalDateString = ""; |
- } |
- FXJSE_Value_SetUTF8String(args.GetReturnValue(), |
- szLocalDateString.AsStringC()); |
} else { |
- FXJSE_Value_SetNull(args.GetReturnValue()); |
+ if (iMonth % 2 != 0) { |
+ if (dDate > 30) { |
+ ++iMonth; |
+ if (iMonth > 12) { |
+ iMonth = 1; |
+ ++i; |
+ } |
+ iDay = 1; |
+ dDate -= 30; |
+ } else { |
+ iDay += static_cast<int32_t>(dDate) - 1; |
+ dDate = 0; |
+ } |
+ } else { |
+ if (dDate > 31) { |
+ ++iMonth; |
+ if (iMonth > 12) { |
+ iMonth = 1; |
+ ++i; |
+ } |
+ iDay = 1; |
+ dDate -= 31; |
+ } else { |
+ iDay += static_cast<int32_t>(dDate) - 1; |
+ dDate = 0; |
+ } |
+ } |
} |
- } else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Date"); |
} |
+ |
+ CFX_ByteString szIsoDateString; |
+ szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay); |
+ CFX_ByteString szLocalDateString; |
+ IsoDate2Local(pThis, szIsoDateString.AsStringC(), formatString.AsStringC(), |
+ localString.AsStringC(), szLocalDateString); |
+ FXJSE_Value_SetUTF8String(args.GetReturnValue(), |
+ szLocalDateString.AsStringC()); |
} |
// static |
@@ -1461,53 +1447,47 @@ void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if ((argc > 0) && (argc < 4)) { |
- FX_BOOL bFlags = FALSE; |
- int32_t iTime = 0; |
- CFX_ByteString formatString; |
- CFX_ByteString localString; |
- std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0); |
- if (FXJSE_Value_IsNull(timeValue.get())) { |
- bFlags = TRUE; |
- } else { |
- iTime = (int32_t)ValueToFloat(pThis, timeValue.get()); |
- if (FXSYS_abs(iTime) < 1.0) { |
- bFlags = TRUE; |
- } |
- } |
- if (argc > 1) { |
- std::unique_ptr<CFXJSE_Value> formatValue = |
- GetSimpleValue(pThis, args, 1); |
- if (FXJSE_Value_IsNull(formatValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(formatValue.get(), formatString); |
- } |
- } |
- if (argc == 3) { |
- std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
- if (FXJSE_Value_IsNull(localValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(localValue.get(), localString); |
- } |
+ if (argc <= 0 && argc >= 4) { |
Tom Sepez
2016/06/06 17:01:53
||
dsinclair
2016/06/06 18:07:54
Done.
|
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2GMTime"); |
+ return; |
+ } |
+ |
+ std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0); |
+ if (FXJSE_Value_IsNull(timeValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ int32_t iTime = (int32_t)ValueToFloat(pThis, timeValue.get()); |
+ if (FXSYS_abs(iTime) < 1.0) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ |
+ CFX_ByteString formatString; |
+ if (argc > 1) { |
+ std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1); |
+ if (FXJSE_Value_IsNull(formatValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (!bFlags) { |
- CFX_ByteString szGMTTimeString; |
- Num2AllTime(pThis, iTime, formatString.AsStringC(), |
- localString.AsStringC(), TRUE, szGMTTimeString); |
- if (szGMTTimeString.IsEmpty()) { |
- szGMTTimeString = ""; |
- } |
- FXJSE_Value_SetUTF8String(args.GetReturnValue(), |
- szGMTTimeString.AsStringC()); |
- } else { |
+ ValueToUTF8String(formatValue.get(), formatString); |
+ } |
+ |
+ CFX_ByteString localString; |
+ if (argc == 3) { |
+ std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
+ if (FXJSE_Value_IsNull(localValue.get())) { |
FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- } else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2GMTime"); |
+ ValueToUTF8String(localValue.get(), localString); |
} |
+ |
+ CFX_ByteString szGMTTimeString; |
+ Num2AllTime(pThis, iTime, formatString.AsStringC(), localString.AsStringC(), |
+ TRUE, szGMTTimeString); |
+ FXJSE_Value_SetUTF8String(args.GetReturnValue(), szGMTTimeString.AsStringC()); |
} |
// static |
@@ -1515,72 +1495,67 @@ void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if ((argc > 0) && (argc < 4)) { |
- FX_BOOL bFlags = FALSE; |
- FX_FLOAT fTime = 0.0f; |
- CFX_ByteString formatString; |
- CFX_ByteString localString; |
- std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0); |
- if (FXJSE_Value_IsNull(timeValue.get())) { |
- bFlags = TRUE; |
- } else { |
- fTime = ValueToFloat(pThis, timeValue.get()); |
- if (FXSYS_fabs(fTime) < 1.0) { |
- bFlags = TRUE; |
- } |
- } |
- if (argc > 1) { |
- std::unique_ptr<CFXJSE_Value> formatValue = |
- GetSimpleValue(pThis, args, 1); |
- if (FXJSE_Value_IsNull(formatValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(formatValue.get(), formatString); |
- } |
- } |
- if (argc == 3) { |
- std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
- if (FXJSE_Value_IsNull(localValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(localValue.get(), localString); |
- } |
+ if (argc <= 0 && argc >= 4) { |
Tom Sepez
2016/06/06 17:01:53
||
dsinclair
2016/06/06 18:07:54
Done.
|
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Time"); |
+ return; |
+ } |
+ |
+ std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0); |
+ if (FXJSE_Value_IsNull(timeValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ FX_FLOAT fTime = ValueToFloat(pThis, timeValue.get()); |
+ if (FXSYS_fabs(fTime) < 1.0) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ |
+ CFX_ByteString formatString; |
+ if (argc > 1) { |
+ std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1); |
+ if (FXJSE_Value_IsNull(formatValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (!bFlags) { |
- CFX_ByteString szLocalTimeString; |
- Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(), |
- localString.AsStringC(), FALSE, szLocalTimeString); |
- if (szLocalTimeString.IsEmpty()) { |
- szLocalTimeString = ""; |
- } |
- FXJSE_Value_SetUTF8String(args.GetReturnValue(), |
- szLocalTimeString.AsStringC()); |
- } else { |
+ ValueToUTF8String(formatValue.get(), formatString); |
+ } |
+ |
+ CFX_ByteString localString; |
+ if (argc == 3) { |
+ std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
+ if (FXJSE_Value_IsNull(localValue.get())) { |
FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- } else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Time"); |
+ ValueToUTF8String(localValue.get(), localString); |
} |
+ |
+ CFX_ByteString szLocalTimeString; |
+ Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(), |
+ localString.AsStringC(), FALSE, szLocalTimeString); |
+ FXJSE_Value_SetUTF8String(args.GetReturnValue(), |
+ szLocalTimeString.AsStringC()); |
} |
// static |
void CXFA_FM2JSContext::Time(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
- if (args.GetLength() == 0) { |
- time_t now; |
- time(&now); |
- struct tm* pGmt = gmtime(&now); |
- int32_t iGMHour = pGmt->tm_hour; |
- int32_t iGMMin = pGmt->tm_min; |
- int32_t iGMSec = pGmt->tm_sec; |
- FXJSE_Value_SetInteger(args.GetReturnValue(), |
- ((iGMHour * 3600 + iGMMin * 60 + iGMSec) * 1000)); |
- } else { |
+ if (args.GetLength() != 0) { |
ToJSContext(pThis, nullptr) |
->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time"); |
+ return; |
} |
+ |
+ time_t now; |
+ time(&now); |
+ |
+ struct tm* pGmt = gmtime(&now); |
+ FXJSE_Value_SetInteger( |
+ args.GetReturnValue(), |
+ ((pGmt->tm_hour * 3600 + pGmt->tm_min * 60 + pGmt->tm_sec) * 1000)); |
} |
// static |
@@ -1588,93 +1563,92 @@ void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if ((argc > 0) && (argc < 4)) { |
- FX_BOOL bFlags = FALSE; |
- CFX_ByteString timeString; |
- CFX_ByteString formatString; |
- CFX_ByteString localString; |
- std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0); |
- if (ValueIsNull(pThis, timeValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(timeValue.get(), timeString); |
- } |
- if (argc > 1) { |
- std::unique_ptr<CFXJSE_Value> formatValue = |
- GetSimpleValue(pThis, args, 1); |
- if (ValueIsNull(pThis, formatValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(formatValue.get(), formatString); |
- } |
- } |
- if (argc == 3) { |
- std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
- if (ValueIsNull(pThis, localValue.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(localValue.get(), localString); |
- } |
+ if (argc <= 0 && argc >= 4) { |
Tom Sepez
2016/06/06 17:01:53
|| (doublecheck all of these).
dsinclair
2016/06/06 18:07:54
Done.
|
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time2Num"); |
+ return; |
+ } |
+ |
+ CFX_ByteString timeString; |
+ std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0); |
+ if (ValueIsNull(pThis, timeValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
+ } |
+ ValueToUTF8String(timeValue.get(), timeString); |
+ |
+ CFX_ByteString formatString; |
+ if (argc > 1) { |
+ std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1); |
+ if (ValueIsNull(pThis, formatValue.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (!bFlags) { |
- CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
- IFX_Locale* pLocale = nullptr; |
- if (localString.IsEmpty()) { |
- CXFA_Node* pThisNode = |
- ToNode(pDoc->GetScriptContext()->GetThisObject()); |
- ASSERT(pThisNode); |
- CXFA_WidgetData widgetData(pThisNode); |
- pLocale = widgetData.GetLocal(); |
- } else { |
- pLocale = pMgr->GetLocaleByName( |
- CFX_WideString::FromUTF8(localString.AsStringC())); |
- } |
- CFX_WideString wsFormat; |
- if (formatString.IsEmpty()) { |
- pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
- } else { |
- wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC()); |
- } |
- wsFormat = FX_WSTRC(L"time{") + wsFormat; |
- wsFormat += FX_WSTRC(L"}"); |
- CXFA_LocaleValue localeValue( |
- XFA_VT_TIME, CFX_WideString::FromUTF8(timeString.AsStringC()), |
- wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); |
- if (localeValue.IsValid()) { |
- CFX_Unitime uniTime = localeValue.GetTime(); |
- int32_t hour = uniTime.GetHour(); |
- int32_t min = uniTime.GetMinute(); |
- int32_t second = uniTime.GetSecond(); |
- int32_t milSecond = uniTime.GetMillisecond(); |
- int32_t mins = hour * 60 + min; |
- CXFA_TimeZoneProvider* pProvider = CXFA_TimeZoneProvider::Get(); |
- if (pProvider) { |
- FX_TIMEZONE tz; |
- pProvider->GetTimeZone(tz); |
- mins -= (tz.tzHour * 60); |
- while (mins > 1440) { |
- mins -= 1440; |
- } |
- while (mins < 0) { |
- mins += 1440; |
- } |
- hour = mins / 60; |
- min = mins % 60; |
- } |
- int32_t iResult = |
- hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1; |
- FXJSE_Value_SetInteger(args.GetReturnValue(), iResult); |
- } else { |
- FXJSE_Value_SetInteger(args.GetReturnValue(), 0); |
- } |
- } else { |
+ ValueToUTF8String(formatValue.get(), formatString); |
+ } |
+ |
+ CFX_ByteString localString; |
+ if (argc == 3) { |
+ std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2); |
+ if (ValueIsNull(pThis, localValue.get())) { |
FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
+ ValueToUTF8String(localValue.get(), localString); |
+ } |
+ |
+ CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
+ CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); |
+ IFX_Locale* pLocale = nullptr; |
+ if (localString.IsEmpty()) { |
+ CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
+ ASSERT(pThisNode); |
+ |
+ CXFA_WidgetData widgetData(pThisNode); |
+ pLocale = widgetData.GetLocal(); |
} else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time2Num"); |
+ pLocale = pMgr->GetLocaleByName( |
+ CFX_WideString::FromUTF8(localString.AsStringC())); |
+ } |
+ |
+ CFX_WideString wsFormat; |
+ if (formatString.IsEmpty()) |
+ pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
+ else |
+ wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC()); |
+ |
+ wsFormat = FX_WSTRC(L"time{") + wsFormat; |
+ wsFormat += FX_WSTRC(L"}"); |
+ CXFA_LocaleValue localeValue(XFA_VT_TIME, |
+ CFX_WideString::FromUTF8(timeString.AsStringC()), |
+ wsFormat, pLocale, pMgr); |
+ if (!localeValue.IsValid()) { |
+ FXJSE_Value_SetInteger(args.GetReturnValue(), 0); |
+ return; |
+ } |
+ |
+ CFX_Unitime uniTime = localeValue.GetTime(); |
+ int32_t hour = uniTime.GetHour(); |
+ int32_t min = uniTime.GetMinute(); |
+ int32_t second = uniTime.GetSecond(); |
+ int32_t milSecond = uniTime.GetMillisecond(); |
+ int32_t mins = hour * 60 + min; |
+ CXFA_TimeZoneProvider* pProvider = CXFA_TimeZoneProvider::Get(); |
+ if (pProvider) { |
+ FX_TIMEZONE tz; |
+ pProvider->GetTimeZone(tz); |
+ mins -= (tz.tzHour * 60); |
+ while (mins > 1440) |
+ mins -= 1440; |
+ while (mins < 0) |
+ mins += 1440; |
+ |
+ hour = mins / 60; |
+ min = mins % 60; |
} |
+ FXJSE_Value_SetInteger( |
+ args.GetReturnValue(), |
+ hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1); |
} |
// static |
@@ -1682,42 +1656,37 @@ void CXFA_FM2JSContext::TimeFmt(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szFuncName, |
CFXJSE_Arguments& args) { |
int32_t argc = args.GetLength(); |
- if (argc < 3) { |
- FX_BOOL bFlags = FALSE; |
- int32_t iStyle = 0; |
- CFX_ByteString szLocal; |
- if (argc > 0) { |
- std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); |
- if (FXJSE_Value_IsNull(argStyle.get())) { |
- bFlags = TRUE; |
- } |
- iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); |
- if (iStyle > 4 || iStyle < 0) { |
- iStyle = 0; |
- } |
- } |
- if (argc == 2) { |
- std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); |
- if (FXJSE_Value_IsNull(argLocal.get())) { |
- bFlags = TRUE; |
- } else { |
- ValueToUTF8String(argLocal.get(), szLocal); |
- } |
+ if (argc >= 3) { |
+ ToJSContext(pThis, nullptr) |
+ ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"TimeFmt"); |
+ return; |
+ } |
+ |
+ int32_t iStyle = 0; |
+ if (argc > 0) { |
+ std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0); |
+ if (FXJSE_Value_IsNull(argStyle.get())) { |
+ FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- if (!bFlags) { |
- CFX_ByteString formatStr; |
- GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr); |
- if (formatStr.IsEmpty()) { |
- formatStr = ""; |
- } |
- FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC()); |
- } else { |
+ iStyle = (int32_t)ValueToFloat(pThis, argStyle.get()); |
+ if (iStyle > 4 || iStyle < 0) |
+ iStyle = 0; |
+ } |
+ |
+ CFX_ByteString szLocal; |
+ if (argc == 2) { |
+ std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1); |
+ if (FXJSE_Value_IsNull(argLocal.get())) { |
FXJSE_Value_SetNull(args.GetReturnValue()); |
+ return; |
} |
- } else { |
- ToJSContext(pThis, nullptr) |
- ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"TimeFmt"); |
+ ValueToUTF8String(argLocal.get(), szLocal); |
} |
+ |
+ CFX_ByteString formatStr; |
+ GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr); |
+ FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC()); |
} |
// static |
@@ -1730,115 +1699,73 @@ FX_BOOL CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, |
iYear = 0; |
iMonth = 1; |
iDay = 1; |
- FX_BOOL iRet = FALSE; |
- if (iLength < 4) { |
- return iRet; |
- } |
+ |
+ if (iLength < 4) |
+ return FALSE; |
+ |
FX_CHAR strYear[5]; |
strYear[4] = '\0'; |
for (int32_t i = 0; i < 4; ++i) { |
- if (*(pData + i) <= '9' && *(pData + i) >= '0') { |
- strYear[i] = *(pData + i); |
- } else { |
- return iRet; |
- } |
+ if (*(pData + i) > '9' || *(pData + i) < '0') |
Tom Sepez
2016/06/06 17:01:53
nit: just pData[i] (throughout) Sheesh.
dsinclair
2016/06/06 18:07:54
Done.
|
+ return FALSE; |
+ |
+ strYear[i] = *(pData + i); |
} |
iYear = FXSYS_atoi(strYear); |
iStyle = 0; |
- if (iLength > 4) { |
- if (*(pData + 4) == '-') { |
- iStyle = 1; |
- } else { |
- iStyle = 0; |
- } |
- } else { |
- iRet = TRUE; |
- return iRet; |
- } |
+ if (iLength == 4) |
+ return TRUE; |
+ |
+ iStyle = *(pData + 4) == '-' ? 1 : 0; |
+ |
FX_CHAR strTemp[3]; |
strTemp[2] = '\0'; |
- int32_t iPosOff = 0; |
- if (iStyle == 0) { |
- iPosOff = 4; |
- if (iLength == 4) { |
- iRet = TRUE; |
- return iRet; |
- } |
- } else { |
- iPosOff = 5; |
- if (iLength == 4) { |
- iRet = TRUE; |
- return iRet; |
- } |
- } |
+ int32_t iPosOff = iStyle == 0 ? 4 : 5; |
if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') || |
- (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) { |
- return iRet; |
- } |
+ (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) |
+ return FALSE; |
+ |
strTemp[0] = *(pData + iPosOff); |
strTemp[1] = *(pData + iPosOff + 1); |
iMonth = FXSYS_atoi(strTemp); |
- if (iMonth > 12 || iMonth < 1) { |
- return iRet; |
- } |
+ if (iMonth > 12 || iMonth < 1) |
+ return FALSE; |
+ |
if (iStyle == 0) { |
iPosOff += 2; |
- if (iLength == 6) { |
- iRet = 1; |
- return iRet; |
- } |
+ if (iLength == 6) |
+ return TRUE; |
} else { |
iPosOff += 3; |
- if (iLength == 7) { |
- iRet = 1; |
- return iRet; |
- } |
+ if (iLength == 7) |
+ return TRUE; |
} |
if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') || |
- (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) { |
- return iRet; |
- } |
+ (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) |
+ return FALSE; |
+ |
strTemp[0] = *(pData + iPosOff); |
strTemp[1] = *(pData + iPosOff + 1); |
iDay = FXSYS_atoi(strTemp); |
- if (iPosOff + 2 < iLength) { |
- return iRet; |
- } |
+ if (iPosOff + 2 < iLength) |
+ return FALSE; |
+ |
if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) { |
- if (iMonth == 2) { |
- if (iDay > 29) { |
- return iRet; |
- } |
- } else { |
- if (iMonth < 8) { |
- if (iDay > (iMonth % 2 == 0 ? 30 : 31)) { |
- return iRet; |
- } |
- } else { |
- if (iDay > (iMonth % 2 == 0 ? 31 : 30)) { |
- return iRet; |
- } |
- } |
- } |
+ if (iMonth == 2 && iDay > 29) |
+ return FALSE; |
} else { |
- if (iMonth == 2) { |
- if (iDay > 28) { |
- return iRet; |
- } |
- } else { |
- if (iMonth < 8) { |
- if (iDay > (iMonth % 2 == 0 ? 30 : 31)) { |
- return iRet; |
- } |
- } else { |
- if (iDay > (iMonth % 2 == 0 ? 31 : 30)) { |
- return iRet; |
- } |
- } |
+ if (iMonth == 2 && iDay > 28) |
+ return FALSE; |
+ } |
+ if (iMonth != 2) { |
+ if (iMonth < 8) { |
+ if (iDay > (iMonth % 2 == 0 ? 30 : 31)) |
+ return FALSE; |
+ } else if (iDay > (iMonth % 2 == 0 ? 31 : 30)) { |
+ return FALSE; |
} |
} |
- iRet = TRUE; |
- return iRet; |
+ return TRUE; |
} |
// static |
@@ -1856,15 +1783,13 @@ FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, |
iMilliSecond = 0; |
iZoneHour = 0; |
iZoneMinute = 0; |
- if (!pData) { |
+ if (!pData) |
return FALSE; |
- } |
- int32_t iRet = FALSE; |
+ |
FX_CHAR strTemp[3]; |
strTemp[2] = '\0'; |
- int32_t iIndex = 0; |
int32_t iZone = 0; |
- int32_t i = iIndex; |
+ int32_t i = 0; |
while (i < iLength) { |
if ((*(pData + i) > '9' || *(pData + i) < '0') && *(pData + i) != ':') { |
Tom Sepez
2016/06/06 17:01:53
same here.
dsinclair
2016/06/06 18:07:54
Done.
|
iZone = i; |
@@ -1872,25 +1797,26 @@ FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, |
} |
++i; |
} |
- if (i == iLength) { |
+ if (i == iLength) |
iZone = iLength; |
- } |
+ |
int32_t iPos = 0; |
+ int32_t iIndex = 0; |
while (iIndex < iZone) { |
- if (iIndex >= iZone) { |
+ if (iIndex >= iZone) |
break; |
- } |
- if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { |
- return iRet; |
- } |
+ |
+ if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') |
+ return FALSE; |
+ |
strTemp[0] = *(pData + iIndex); |
- if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { |
- return iRet; |
- } |
+ if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') |
+ return FALSE; |
+ |
strTemp[1] = *(pData + iIndex + 1); |
- if (FXSYS_atoi(strTemp) > 60) { |
- return iRet; |
- } |
+ if (FXSYS_atoi(strTemp) > 60) |
+ return FALSE; |
+ |
if (*(pData + 2) == ':') { |
if (iPos == 0) { |
iHour = FXSYS_atoi(strTemp); |
@@ -1920,30 +1846,30 @@ FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, |
++iIndex; |
FX_CHAR strSec[4]; |
strSec[3] = '\0'; |
- if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { |
- return iRet; |
- } |
+ if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') |
+ return FALSE; |
+ |
strSec[0] = *(pData + iIndex); |
- if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { |
- return iRet; |
- } |
+ if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') |
+ return FALSE; |
+ |
strSec[1] = *(pData + iIndex + 1); |
- if (*(pData + iIndex + 2) > '9' || *(pData + iIndex + 2) < '0') { |
- return iRet; |
- } |
+ if (*(pData + iIndex + 2) > '9' || *(pData + iIndex + 2) < '0') |
+ return FALSE; |
+ |
strSec[2] = *(pData + iIndex + 2); |
iMilliSecond = FXSYS_atoi(strSec); |
if (iMilliSecond > 100) { |
iMilliSecond = 0; |
- return iRet; |
+ return FALSE; |
} |
iIndex += 3; |
} |
+ if (*(pData + iIndex) == 'z' || *(pData + iIndex) == 'Z') |
+ return TRUE; |
+ |
int32_t iSign = 1; |
- if (*(pData + iIndex) == 'z' || *(pData + iIndex) == 'Z') { |
- iRet = 1; |
- return iRet; |
- } else if (*(pData + iIndex) == '+') { |
+ if (*(pData + iIndex) == '+') { |
++iIndex; |
} else if (*(pData + iIndex) == '-') { |
iSign = -1; |
@@ -1951,20 +1877,19 @@ FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, |
} |
iPos = 0; |
while (iIndex < iLength) { |
- if (iIndex >= iLength) { |
- return iRet; |
- } |
- if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { |
- return iRet; |
- } |
+ if (iIndex >= iLength) |
+ return FALSE; |
+ if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') |
+ return FALSE; |
+ |
strTemp[0] = *(pData + iIndex); |
- if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { |
- return iRet; |
- } |
+ if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') |
+ return FALSE; |
+ |
strTemp[1] = *(pData + iIndex + 1); |
- if (FXSYS_atoi(strTemp) > 60) { |
- return iRet; |
- } |
+ if (FXSYS_atoi(strTemp) > 60) |
+ return FALSE; |
+ |
if (*(pData + 2) == ':') { |
if (iPos == 0) { |
iZoneHour = FXSYS_atoi(strTemp); |
@@ -1983,12 +1908,11 @@ FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, |
iIndex += 2; |
} |
} |
- if (iIndex < iLength) { |
- return iRet; |
- } |
+ if (iIndex < iLength) |
+ return FALSE; |
+ |
iZoneHour *= iSign; |
- iRet = TRUE; |
- return iRet; |
+ return TRUE; |
} |
// static |
@@ -2009,40 +1933,35 @@ FX_BOOL CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData, |
iHour = 0; |
iMinute = 0; |
iSecond = 0; |
- if (!pData) { |
+ if (!pData) |
return FALSE; |
- } |
- int32_t iRet = FALSE; |
+ |
int32_t iIndex = 0; |
while (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') { |
- if (iIndex >= iLength) { |
- return iRet; |
- } |
+ if (iIndex >= iLength) |
+ return FALSE; |
++iIndex; |
} |
- if (iIndex != 8 && iIndex != 10) { |
- return iRet; |
- } |
+ if (iIndex != 8 && iIndex != 10) |
+ return FALSE; |
+ |
int32_t iStyle = -1; |
- iRet = IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay); |
- if (!iRet) { |
- return iRet; |
- } |
- if (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') { |
- return iRet; |
- } |
+ if (!IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay)) |
+ return FALSE; |
+ if (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') |
+ return TRUE; |
+ |
++iIndex; |
if (((iLength - iIndex > 13) && (iLength - iIndex < 6)) && |
(iLength - iIndex != 15)) { |
- return iRet; |
+ return TRUE; |
} |
- iRet = IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute, |
- iSecond, iMillionSecond, iZoneHour, iZoneMinute); |
- if (!iRet) { |
- return iRet; |
+ if (!IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute, |
+ iSecond, iMillionSecond, iZoneHour, iZoneMinute)) { |
+ return FALSE; |
} |
- iRet = TRUE; |
- return iRet; |
+ |
+ return TRUE; |
} |
// static |
@@ -2052,30 +1971,31 @@ FX_BOOL CXFA_FM2JSContext::Local2IsoDate(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szLocale, |
CFX_ByteString& strIsoDate) { |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return FALSE; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
+ CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); |
IFX_Locale* pLocale = nullptr; |
if (szLocale.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
ASSERT(pThisNode); |
+ |
CXFA_WidgetData widgetData(pThisNode); |
pLocale = widgetData.GetLocal(); |
} else { |
pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return FALSE; |
- } |
+ |
CFX_WideString wsFormat; |
- if (szFormat.IsEmpty()) { |
+ if (szFormat.IsEmpty()) |
pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
- } else { |
+ else |
wsFormat = CFX_WideString::FromUTF8(szFormat); |
- } |
+ |
CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), |
- wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); |
+ wsFormat, pLocale, pMgr); |
CFX_Unitime dt = widgetValue.GetDate(); |
strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay()); |
return TRUE; |
@@ -2088,32 +2008,33 @@ FX_BOOL CXFA_FM2JSContext::Local2IsoTime(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szLocale, |
CFX_ByteString& strIsoTime) { |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return FALSE; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
+ CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); |
IFX_Locale* pLocale = nullptr; |
if (szLocale.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
ASSERT(pThisNode); |
+ |
CXFA_WidgetData widgetData(pThisNode); |
pLocale = widgetData.GetLocal(); |
} else { |
pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return FALSE; |
- } |
+ |
CFX_WideString wsFormat; |
- if (szFormat.IsEmpty()) { |
+ if (szFormat.IsEmpty()) |
pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
- } else { |
+ else |
wsFormat = CFX_WideString::FromUTF8(szFormat); |
- } |
+ |
wsFormat = FX_WSTRC(L"time{") + wsFormat; |
wsFormat += FX_WSTRC(L"}"); |
CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), |
- wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); |
+ wsFormat, pLocale, pMgr); |
CFX_Unitime utime = widgetValue.GetTime(); |
strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(), |
utime.GetSecond(), utime.GetMillisecond()); |
@@ -2127,10 +2048,10 @@ FX_BOOL CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szLocale, |
CFX_ByteString& strLocalDate) { |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return FALSE; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
+ CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); |
IFX_Locale* pLocale = nullptr; |
if (szLocale.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
@@ -2140,17 +2061,17 @@ FX_BOOL CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis, |
} else { |
pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return FALSE; |
- } |
+ |
CFX_WideString wsFormat; |
- if (szFormat.IsEmpty()) { |
+ if (szFormat.IsEmpty()) |
pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
- } else { |
+ else |
wsFormat = CFX_WideString::FromUTF8(szFormat); |
- } |
+ |
CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), |
- (CXFA_LocaleMgr*)pMgr); |
+ pMgr); |
CFX_WideString wsRet; |
widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, |
XFA_VALUEPICTURE_Display); |
@@ -2165,10 +2086,10 @@ FX_BOOL CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szLocale, |
CFX_ByteString& strLocalTime) { |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return FALSE; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
+ CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); |
IFX_Locale* pLocale = nullptr; |
if (szLocale.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
@@ -2178,19 +2099,19 @@ FX_BOOL CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis, |
} else { |
pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return FALSE; |
- } |
+ |
CFX_WideString wsFormat; |
- if (szFormat.IsEmpty()) { |
+ if (szFormat.IsEmpty()) |
pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
- } else { |
+ else |
wsFormat = CFX_WideString::FromUTF8(szFormat); |
- } |
+ |
wsFormat = FX_WSTRC(L"time{") + wsFormat; |
wsFormat += FX_WSTRC(L"}"); |
CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), |
- (CXFA_LocaleMgr*)pMgr); |
+ pMgr); |
CFX_WideString wsRet; |
widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, |
XFA_VALUEPICTURE_Display); |
@@ -2205,10 +2126,10 @@ FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, |
const CFX_ByteStringC& szLocale, |
CFX_ByteString& strGMTTime) { |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return FALSE; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
+ CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr(); |
IFX_Locale* pLocale = nullptr; |
if (szLocale.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
@@ -2218,19 +2139,19 @@ FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, |
} else { |
pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return FALSE; |
- } |
+ |
CFX_WideString wsFormat; |
- if (szFormat.IsEmpty()) { |
+ if (szFormat.IsEmpty()) |
pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); |
- } else { |
+ else |
wsFormat = CFX_WideString::FromUTF8(szFormat); |
- } |
+ |
wsFormat = FX_WSTRC(L"time{") + wsFormat; |
wsFormat += FX_WSTRC(L"}"); |
CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), |
- (CXFA_LocaleMgr*)pMgr); |
+ pMgr); |
CFX_WideString wsRet; |
widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, |
XFA_VALUEPICTURE_Display); |
@@ -2240,74 +2161,57 @@ FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, |
// static |
int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { |
- FX_BOOL bFlags = FALSE; |
int32_t iLength = szDateString.GetLength(); |
- FX_BOOL iRet = FALSE; |
- int32_t iStyle = -1; |
int32_t iYear = 0; |
int32_t iMonth = 0; |
int32_t iDay = 0; |
- int32_t iHour = 0; |
- int32_t iMinute = 0; |
- int32_t iSecond = 0; |
- int32_t iMillionSecond = 0; |
- int32_t iZoneHour = 0; |
- int32_t iZoneMinute = 0; |
if (iLength <= 10) { |
- iRet = IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth, |
- iDay); |
+ int32_t iStyle = -1; |
+ if (!IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth, |
+ iDay)) { |
+ return 0; |
+ } |
} else { |
- iRet = IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, |
- iDay, iHour, iMinute, iSecond, iMillionSecond, |
- iZoneHour, iZoneMinute); |
- } |
- if (!iRet) { |
- bFlags = TRUE; |
+ int32_t iHour = 0; |
+ int32_t iMinute = 0; |
+ int32_t iSecond = 0; |
+ int32_t iMilliSecond = 0; |
+ int32_t iZoneHour = 0; |
+ int32_t iZoneMinute = 0; |
+ if (!IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, iDay, |
+ iHour, iMinute, iSecond, iMilliSecond, iZoneHour, |
+ iZoneMinute)) { |
+ return 0; |
+ } |
} |
+ |
FX_FLOAT dDays = 0; |
int32_t i = 1; |
- if (iYear < 1900) { |
- bFlags = TRUE; |
+ if (iYear < 1900) |
+ return 0; |
+ |
+ while (iYear - i >= 1900) { |
+ dDays += |
+ ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400)) |
+ ? 366 |
+ : 365; |
+ ++i; |
} |
- if (!bFlags) { |
- while (iYear - i >= 1900) { |
- if ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400)) { |
- dDays += 366; |
- } else { |
- dDays += 365; |
- } |
- ++i; |
- } |
- i = 1; |
- while (i < iMonth) { |
- if (i == 2) { |
- if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) { |
- dDays += 29; |
- } else { |
- dDays += 28; |
- } |
- } else if (i <= 7) { |
- if (i % 2 == 0) { |
- dDays += 30; |
- } else { |
- dDays += 31; |
- } |
- } else { |
- if (i % 2 == 0) { |
- dDays += 31; |
- } else { |
- dDays += 30; |
- } |
- } |
- ++i; |
- } |
- i = 0; |
- while (iDay - i > 0) { |
- dDays += 1; |
- ++i; |
- } |
- } else { |
- dDays = 0; |
+ i = 1; |
+ while (i < iMonth) { |
+ if (i == 2) |
+ dDays += ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) ? 29 : 28; |
+ else if (i <= 7) |
+ dDays += (i % 2 == 0) ? 30 : 31; |
+ else |
+ dDays += (i % 2 == 0) ? 31 : 30; |
+ |
+ ++i; |
+ } |
+ i = 0; |
+ while (iDay - i > 0) { |
+ dDays += 1; |
+ ++i; |
} |
return (int32_t)dDays; |
} |
@@ -2320,42 +2224,39 @@ void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis, |
FX_BOOL bStandard) { |
FX_LOCALEDATETIMESUBCATEGORY strStyle; |
switch (iStyle) { |
- case 0: |
- strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
- break; |
case 1: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; |
break; |
- case 2: |
- strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
- break; |
case 3: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; |
break; |
case 4: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; |
break; |
+ case 0: |
+ case 2: |
default: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
break; |
} |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
IFX_Locale* pLocale = nullptr; |
if (szLocalStr.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
ASSERT(pThisNode); |
+ |
CXFA_WidgetData widgetData(pThisNode); |
pLocale = widgetData.GetLocal(); |
} else { |
- pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); |
+ pLocale = pDoc->GetLocalMgr()->GetLocaleByName( |
+ CFX_WideString::FromUTF8(szLocalStr)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return; |
- } |
+ |
CFX_WideString strRet; |
pLocale->GetDatePattern(strStyle, strRet); |
if (!bStandard) { |
@@ -2374,42 +2275,39 @@ void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis, |
FX_BOOL bStandard) { |
FX_LOCALEDATETIMESUBCATEGORY strStyle; |
switch (iStyle) { |
- case 0: |
- strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
- break; |
case 1: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; |
break; |
- case 2: |
- strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
- break; |
case 3: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; |
break; |
case 4: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; |
break; |
+ case 0: |
+ case 2: |
default: |
strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; |
break; |
} |
CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); |
- if (!pDoc) { |
+ if (!pDoc) |
return; |
- } |
- IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); |
+ |
IFX_Locale* pLocale = nullptr; |
if (szLocalStr.IsEmpty()) { |
CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); |
ASSERT(pThisNode); |
+ |
CXFA_WidgetData widgetData(pThisNode); |
pLocale = widgetData.GetLocal(); |
} else { |
- pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); |
+ pLocale = pDoc->GetLocalMgr()->GetLocaleByName( |
+ CFX_WideString::FromUTF8(szLocalStr)); |
} |
- if (!pLocale) { |
+ if (!pLocale) |
return; |
- } |
+ |
CFX_WideString strRet; |
pLocale->GetTimePattern(strStyle, strRet); |
if (!bStandard) { |
@@ -2446,19 +2344,21 @@ void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, |
int32_t iHour = 0; |
int32_t iMin = 0; |
int32_t iSec = 0; |
- int32_t iZoneHour = 0; |
- int32_t iZoneMin = 0; |
- int32_t iZoneSec = 0; |
iHour = static_cast<int>(iTime) / 3600000; |
iMin = (static_cast<int>(iTime) - iHour * 3600000) / 60000; |
iSec = (static_cast<int>(iTime) - iHour * 3600000 - iMin * 60000) / 1000; |
+ |
if (!bGM) { |
+ int32_t iZoneHour = 0; |
+ int32_t iZoneMin = 0; |
+ int32_t iZoneSec = 0; |
GetLocalTimeZone(iZoneHour, iZoneMin, iZoneSec); |
iHour += iZoneHour; |
iMin += iZoneMin; |
iSec += iZoneSec; |
} |
- int32_t iRet = 0; |
+ |
+ FX_BOOL iRet = FALSE; |
CFX_ByteString strIsoTime; |
strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec); |
if (bGM) { |
@@ -2468,9 +2368,8 @@ void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, |
iRet = IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale, |
strTime); |
} |
- if (!iRet) { |
+ if (!iRet) |
strTime = ""; |
- } |
} |
// static |
@@ -2479,17 +2378,12 @@ void CXFA_FM2JSContext::GetLocalTimeZone(int32_t& iHour, |
int32_t& iSec) { |
time_t now; |
time(&now); |
+ |
struct tm* pGmt = gmtime(&now); |
- int32_t iGMHour = pGmt->tm_hour; |
- int32_t iGMMin = pGmt->tm_min; |
- int32_t iGMSec = pGmt->tm_sec; |
struct tm* pLocal = localtime(&now); |
- int32_t iLocalHour = pLocal->tm_hour; |
- int32_t iLocalMin = pLocal->tm_min; |
- int32_t iLocalSec = pLocal->tm_sec; |
- iHour = iLocalHour - iGMHour; |
- iMin = iLocalMin - iGMMin; |
- iSec = iLocalSec - iGMSec; |
+ iHour = pLocal->tm_hour - pGmt->tm_hour; |
+ iMin = pLocal->tm_min - pGmt->tm_min; |
+ iSec = pLocal->tm_sec - pGmt->tm_sec; |
} |
// static |