Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: xfa/fxfa/fm2js/xfa_fm2jscontext.cpp

Issue 2043743002: xfa_fm2jscontext method cleanup - pt IV (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@execute_context
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "xfa/fxfa/fm2js/xfa_fm2jscontext.h" 7 #include "xfa/fxfa/fm2js/xfa_fm2jscontext.h"
8 8
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 1210 matching lines...) Expand 10 before | Expand all | Expand 10 after
1221 int32_t iResult = 1221 int32_t iResult =
1222 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1; 1222 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1;
1223 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult); 1223 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult);
1224 } 1224 }
1225 1225
1226 // static 1226 // static
1227 void CXFA_FM2JSContext::LocalDateFmt(CFXJSE_Value* pThis, 1227 void CXFA_FM2JSContext::LocalDateFmt(CFXJSE_Value* pThis,
1228 const CFX_ByteStringC& szFuncName, 1228 const CFX_ByteStringC& szFuncName,
1229 CFXJSE_Arguments& args) { 1229 CFXJSE_Arguments& args) {
1230 int32_t argc = args.GetLength(); 1230 int32_t argc = args.GetLength();
1231 if (argc < 3) { 1231 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.
1232 FX_BOOL bFlags = FALSE;
1233 int32_t iStyle = 0;
1234 CFX_ByteString szLocal;
1235 if (argc > 0) {
1236 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1237 if (FXJSE_Value_IsNull(argStyle.get())) {
1238 bFlags = TRUE;
1239 }
1240 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1241 if (iStyle > 4 || iStyle < 0) {
1242 iStyle = 0;
1243 }
1244 }
1245 if (argc == 2) {
1246 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1247 if (FXJSE_Value_IsNull(argLocal.get())) {
1248 bFlags = TRUE;
1249 } else {
1250 ValueToUTF8String(argLocal.get(), szLocal);
1251 }
1252 }
1253 if (!bFlags) {
1254 CFX_ByteString formatStr;
1255 GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1256 if (formatStr.IsEmpty()) {
1257 formatStr = "";
1258 }
1259 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1260 } else {
1261 FXJSE_Value_SetNull(args.GetReturnValue());
1262 }
1263 } else {
1264 ToJSContext(pThis, nullptr) 1232 ToJSContext(pThis, nullptr)
1265 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalDateFmt"); 1233 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalDateFmt");
1234 return;
1266 } 1235 }
1236
1237 int32_t iStyle = 0;
1238 if (argc > 0) {
1239 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1240 if (FXJSE_Value_IsNull(argStyle.get())) {
1241 FXJSE_Value_SetNull(args.GetReturnValue());
1242 return;
1243 }
1244 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1245 if (iStyle > 4 || iStyle < 0)
1246 iStyle = 0;
1247 }
1248
1249 CFX_ByteString szLocal;
1250 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.
1251 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1252 if (FXJSE_Value_IsNull(argLocal.get())) {
1253 FXJSE_Value_SetNull(args.GetReturnValue());
1254 return;
1255 }
1256 ValueToUTF8String(argLocal.get(), szLocal);
1257 }
1258
1259 CFX_ByteString formatStr;
1260 GetLocalDateFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1261 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1267 } 1262 }
1268 1263
1269 // static 1264 // static
1270 void CXFA_FM2JSContext::LocalTimeFmt(CFXJSE_Value* pThis, 1265 void CXFA_FM2JSContext::LocalTimeFmt(CFXJSE_Value* pThis,
1271 const CFX_ByteStringC& szFuncName, 1266 const CFX_ByteStringC& szFuncName,
1272 CFXJSE_Arguments& args) { 1267 CFXJSE_Arguments& args) {
1273 int32_t argc = args.GetLength(); 1268 int32_t argc = args.GetLength();
1274 if (argc < 3) { 1269 if (argc >= 3) {
1275 FX_BOOL bFlags = FALSE;
1276 int32_t iStyle = 0;
1277 CFX_ByteString szLocal;
1278 if (argc > 0) {
1279 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1280 if (FXJSE_Value_IsNull(argStyle.get())) {
1281 bFlags = TRUE;
1282 }
1283 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1284 if (iStyle > 4 || iStyle < 0) {
1285 iStyle = 0;
1286 }
1287 }
1288 if (argc == 2) {
1289 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1290 if (FXJSE_Value_IsNull(argLocal.get())) {
1291 bFlags = TRUE;
1292 } else {
1293 ValueToUTF8String(argLocal.get(), szLocal);
1294 }
1295 }
1296 if (!bFlags) {
1297 CFX_ByteString formatStr;
1298 GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1299 if (formatStr.IsEmpty()) {
1300 formatStr = "";
1301 }
1302 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1303 } else {
1304 FXJSE_Value_SetNull(args.GetReturnValue());
1305 }
1306 } else {
1307 ToJSContext(pThis, nullptr) 1270 ToJSContext(pThis, nullptr)
1308 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalTimeFmt"); 1271 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"LocalTimeFmt");
1272 return;
1309 } 1273 }
1274
1275 int32_t iStyle = 0;
1276 if (argc > 0) {
1277 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1278 if (FXJSE_Value_IsNull(argStyle.get())) {
1279 FXJSE_Value_SetNull(args.GetReturnValue());
1280 return;
1281 }
1282 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1283 if (iStyle > 4 || iStyle < 0)
1284 iStyle = 0;
1285 }
1286
1287 CFX_ByteString szLocal;
1288 if (argc == 2) {
1289 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1290 if (FXJSE_Value_IsNull(argLocal.get())) {
1291 FXJSE_Value_SetNull(args.GetReturnValue());
1292 return;
1293 }
1294 ValueToUTF8String(argLocal.get(), szLocal);
1295 }
1296
1297 CFX_ByteString formatStr;
1298 GetLocalTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr, FALSE);
1299 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1310 } 1300 }
1311 1301
1312 // static 1302 // static
1313 void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis, 1303 void CXFA_FM2JSContext::Num2Date(CFXJSE_Value* pThis,
1314 const CFX_ByteStringC& szFuncName, 1304 const CFX_ByteStringC& szFuncName,
1315 CFXJSE_Arguments& args) { 1305 CFXJSE_Arguments& args) {
1316 int32_t argc = args.GetLength(); 1306 int32_t argc = args.GetLength();
1317 if ((argc > 0) && (argc < 4)) { 1307 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
1318 FX_BOOL bFlags = FALSE; 1308 ToJSContext(pThis, nullptr)
1319 int32_t dDate = 0; 1309 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Date");
1320 CFX_ByteString formatString; 1310 return;
1321 CFX_ByteString localString; 1311 }
1322 std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0); 1312
1323 if (ValueIsNull(pThis, dateValue.get())) { 1313 std::unique_ptr<CFXJSE_Value> dateValue = GetSimpleValue(pThis, args, 0);
1324 bFlags = TRUE; 1314 if (ValueIsNull(pThis, dateValue.get())) {
1315 FXJSE_Value_SetNull(args.GetReturnValue());
1316 return;
1317 }
1318 int32_t dDate = (int32_t)ValueToFloat(pThis, dateValue.get());
1319 if (dDate < 1) {
1320 FXJSE_Value_SetNull(args.GetReturnValue());
1321 return;
1322 }
1323
1324 CFX_ByteString formatString;
1325 if (argc > 1) {
1326 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1327 if (ValueIsNull(pThis, formatValue.get())) {
1328 FXJSE_Value_SetNull(args.GetReturnValue());
1329 return;
1330 }
1331 ValueToUTF8String(formatValue.get(), formatString);
1332 }
1333
1334 CFX_ByteString localString;
1335 if (argc == 3) {
1336 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1337 if (ValueIsNull(pThis, localValue.get())) {
1338 FXJSE_Value_SetNull(args.GetReturnValue());
1339 return;
1340 }
1341 ValueToUTF8String(localValue.get(), localString);
1342 }
1343
1344 int32_t iYear = 1900;
1345 int32_t iMonth = 1;
1346 int32_t iDay = 1;
1347 int32_t i = 0;
1348 while (dDate > 0) {
1349 if (iMonth == 2) {
1350 if ((!((iYear + i) % 4) && ((iYear + i) % 100)) || !((iYear + i) % 400)) {
1351 if (dDate > 29) {
1352 ++iMonth;
1353 if (iMonth > 12) {
1354 iMonth = 1;
1355 ++i;
1356 }
1357 iDay = 1;
1358 dDate -= 29;
1359 } else {
1360 iDay += static_cast<int32_t>(dDate) - 1;
1361 dDate = 0;
1362 }
1363 } else {
1364 if (dDate > 28) {
1365 ++iMonth;
1366 if (iMonth > 12) {
1367 iMonth = 1;
1368 ++i;
1369 }
1370 iDay = 1;
1371 dDate -= 28;
1372 } else {
1373 iDay += static_cast<int32_t>(dDate) - 1;
1374 dDate = 0;
1375 }
1376 }
1377 } else if (iMonth < 8) {
1378 if ((iMonth % 2 == 0)) {
1379 if (dDate > 30) {
1380 ++iMonth;
1381 if (iMonth > 12) {
1382 iMonth = 1;
1383 ++i;
1384 }
1385 iDay = 1;
1386 dDate -= 30;
1387 } else {
1388 iDay += static_cast<int32_t>(dDate) - 1;
1389 dDate = 0;
1390 }
1391 } else {
1392 if (dDate > 31) {
1393 ++iMonth;
1394 if (iMonth > 12) {
1395 iMonth = 1;
1396 ++i;
1397 }
1398 iDay = 1;
1399 dDate -= 31;
1400 } else {
1401 iDay += static_cast<int32_t>(dDate) - 1;
1402 dDate = 0;
1403 }
1404 }
1325 } else { 1405 } else {
1326 dDate = (int32_t)ValueToFloat(pThis, dateValue.get()); 1406 if (iMonth % 2 != 0) {
1327 bFlags = dDate < 1; 1407 if (dDate > 30) {
1328 } 1408 ++iMonth;
1329 if (argc > 1) { 1409 if (iMonth > 12) {
1330 std::unique_ptr<CFXJSE_Value> formatValue = 1410 iMonth = 1;
1331 GetSimpleValue(pThis, args, 1); 1411 ++i;
1332 if (ValueIsNull(pThis, formatValue.get())) { 1412 }
1333 bFlags = TRUE; 1413 iDay = 1;
1414 dDate -= 30;
1415 } else {
1416 iDay += static_cast<int32_t>(dDate) - 1;
1417 dDate = 0;
1418 }
1334 } else { 1419 } else {
1335 ValueToUTF8String(formatValue.get(), formatString); 1420 if (dDate > 31) {
1421 ++iMonth;
1422 if (iMonth > 12) {
1423 iMonth = 1;
1424 ++i;
1425 }
1426 iDay = 1;
1427 dDate -= 31;
1428 } else {
1429 iDay += static_cast<int32_t>(dDate) - 1;
1430 dDate = 0;
1431 }
1336 } 1432 }
1337 } 1433 }
1338 if (argc == 3) {
1339 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1340 if (ValueIsNull(pThis, localValue.get())) {
1341 bFlags = TRUE;
1342 } else {
1343 ValueToUTF8String(localValue.get(), localString);
1344 }
1345 }
1346 if (!bFlags) {
1347 int32_t iYear = 1900;
1348 int32_t iMonth = 1;
1349 int32_t iDay = 1;
1350 int32_t i = 0;
1351 while (dDate > 0) {
1352 if (iMonth == 2) {
1353 if ((!((iYear + i) % 4) && ((iYear + i) % 100)) ||
1354 !((iYear + i) % 400)) {
1355 if (dDate > 29) {
1356 ++iMonth;
1357 if (iMonth > 12) {
1358 iMonth = 1;
1359 ++i;
1360 }
1361 iDay = 1;
1362 dDate -= 29;
1363 } else {
1364 iDay += static_cast<int32_t>(dDate) - 1;
1365 dDate = 0;
1366 }
1367 } else {
1368 if (dDate > 28) {
1369 ++iMonth;
1370 if (iMonth > 12) {
1371 iMonth = 1;
1372 ++i;
1373 }
1374 iDay = 1;
1375 dDate -= 28;
1376 } else {
1377 iDay += static_cast<int32_t>(dDate) - 1;
1378 dDate = 0;
1379 }
1380 }
1381 } else if (iMonth < 8) {
1382 if ((iMonth % 2 == 0)) {
1383 if (dDate > 30) {
1384 ++iMonth;
1385 if (iMonth > 12) {
1386 iMonth = 1;
1387 ++i;
1388 }
1389 iDay = 1;
1390 dDate -= 30;
1391 } else {
1392 iDay += static_cast<int32_t>(dDate) - 1;
1393 dDate = 0;
1394 }
1395 } else {
1396 if (dDate > 31) {
1397 ++iMonth;
1398 if (iMonth > 12) {
1399 iMonth = 1;
1400 ++i;
1401 }
1402 iDay = 1;
1403 dDate -= 31;
1404 } else {
1405 iDay += static_cast<int32_t>(dDate) - 1;
1406 dDate = 0;
1407 }
1408 }
1409 } else {
1410 if (iMonth % 2 != 0) {
1411 if (dDate > 30) {
1412 ++iMonth;
1413 if (iMonth > 12) {
1414 iMonth = 1;
1415 ++i;
1416 }
1417 iDay = 1;
1418 dDate -= 30;
1419 } else {
1420 iDay += static_cast<int32_t>(dDate) - 1;
1421 dDate = 0;
1422 }
1423 } else {
1424 if (dDate > 31) {
1425 ++iMonth;
1426 if (iMonth > 12) {
1427 iMonth = 1;
1428 ++i;
1429 }
1430 iDay = 1;
1431 dDate -= 31;
1432 } else {
1433 iDay += static_cast<int32_t>(dDate) - 1;
1434 dDate = 0;
1435 }
1436 }
1437 }
1438 }
1439 CFX_ByteString szIsoDateString;
1440 szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay);
1441 CFX_ByteString szLocalDateString;
1442 IsoDate2Local(pThis, szIsoDateString.AsStringC(),
1443 formatString.AsStringC(), localString.AsStringC(),
1444 szLocalDateString);
1445 if (szLocalDateString.IsEmpty()) {
1446 szLocalDateString = "";
1447 }
1448 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1449 szLocalDateString.AsStringC());
1450 } else {
1451 FXJSE_Value_SetNull(args.GetReturnValue());
1452 }
1453 } else {
1454 ToJSContext(pThis, nullptr)
1455 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Date");
1456 } 1434 }
1435
1436 CFX_ByteString szIsoDateString;
1437 szIsoDateString.Format("%d%02d%02d", iYear + i, iMonth, iDay);
1438 CFX_ByteString szLocalDateString;
1439 IsoDate2Local(pThis, szIsoDateString.AsStringC(), formatString.AsStringC(),
1440 localString.AsStringC(), szLocalDateString);
1441 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1442 szLocalDateString.AsStringC());
1457 } 1443 }
1458 1444
1459 // static 1445 // static
1460 void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis, 1446 void CXFA_FM2JSContext::Num2GMTime(CFXJSE_Value* pThis,
1461 const CFX_ByteStringC& szFuncName, 1447 const CFX_ByteStringC& szFuncName,
1462 CFXJSE_Arguments& args) { 1448 CFXJSE_Arguments& args) {
1463 int32_t argc = args.GetLength(); 1449 int32_t argc = args.GetLength();
1464 if ((argc > 0) && (argc < 4)) { 1450 if (argc <= 0 && argc >= 4) {
Tom Sepez 2016/06/06 17:01:53 ||
dsinclair 2016/06/06 18:07:54 Done.
1465 FX_BOOL bFlags = FALSE;
1466 int32_t iTime = 0;
1467 CFX_ByteString formatString;
1468 CFX_ByteString localString;
1469 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1470 if (FXJSE_Value_IsNull(timeValue.get())) {
1471 bFlags = TRUE;
1472 } else {
1473 iTime = (int32_t)ValueToFloat(pThis, timeValue.get());
1474 if (FXSYS_abs(iTime) < 1.0) {
1475 bFlags = TRUE;
1476 }
1477 }
1478 if (argc > 1) {
1479 std::unique_ptr<CFXJSE_Value> formatValue =
1480 GetSimpleValue(pThis, args, 1);
1481 if (FXJSE_Value_IsNull(formatValue.get())) {
1482 bFlags = TRUE;
1483 } else {
1484 ValueToUTF8String(formatValue.get(), formatString);
1485 }
1486 }
1487 if (argc == 3) {
1488 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1489 if (FXJSE_Value_IsNull(localValue.get())) {
1490 bFlags = TRUE;
1491 } else {
1492 ValueToUTF8String(localValue.get(), localString);
1493 }
1494 }
1495 if (!bFlags) {
1496 CFX_ByteString szGMTTimeString;
1497 Num2AllTime(pThis, iTime, formatString.AsStringC(),
1498 localString.AsStringC(), TRUE, szGMTTimeString);
1499 if (szGMTTimeString.IsEmpty()) {
1500 szGMTTimeString = "";
1501 }
1502 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1503 szGMTTimeString.AsStringC());
1504 } else {
1505 FXJSE_Value_SetNull(args.GetReturnValue());
1506 }
1507 } else {
1508 ToJSContext(pThis, nullptr) 1451 ToJSContext(pThis, nullptr)
1509 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2GMTime"); 1452 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2GMTime");
1453 return;
1510 } 1454 }
1455
1456 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1457 if (FXJSE_Value_IsNull(timeValue.get())) {
1458 FXJSE_Value_SetNull(args.GetReturnValue());
1459 return;
1460 }
1461 int32_t iTime = (int32_t)ValueToFloat(pThis, timeValue.get());
1462 if (FXSYS_abs(iTime) < 1.0) {
1463 FXJSE_Value_SetNull(args.GetReturnValue());
1464 return;
1465 }
1466
1467 CFX_ByteString formatString;
1468 if (argc > 1) {
1469 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1470 if (FXJSE_Value_IsNull(formatValue.get())) {
1471 FXJSE_Value_SetNull(args.GetReturnValue());
1472 return;
1473 }
1474 ValueToUTF8String(formatValue.get(), formatString);
1475 }
1476
1477 CFX_ByteString localString;
1478 if (argc == 3) {
1479 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1480 if (FXJSE_Value_IsNull(localValue.get())) {
1481 FXJSE_Value_SetNull(args.GetReturnValue());
1482 return;
1483 }
1484 ValueToUTF8String(localValue.get(), localString);
1485 }
1486
1487 CFX_ByteString szGMTTimeString;
1488 Num2AllTime(pThis, iTime, formatString.AsStringC(), localString.AsStringC(),
1489 TRUE, szGMTTimeString);
1490 FXJSE_Value_SetUTF8String(args.GetReturnValue(), szGMTTimeString.AsStringC());
1511 } 1491 }
1512 1492
1513 // static 1493 // static
1514 void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis, 1494 void CXFA_FM2JSContext::Num2Time(CFXJSE_Value* pThis,
1515 const CFX_ByteStringC& szFuncName, 1495 const CFX_ByteStringC& szFuncName,
1516 CFXJSE_Arguments& args) { 1496 CFXJSE_Arguments& args) {
1517 int32_t argc = args.GetLength(); 1497 int32_t argc = args.GetLength();
1518 if ((argc > 0) && (argc < 4)) { 1498 if (argc <= 0 && argc >= 4) {
Tom Sepez 2016/06/06 17:01:53 ||
dsinclair 2016/06/06 18:07:54 Done.
1519 FX_BOOL bFlags = FALSE;
1520 FX_FLOAT fTime = 0.0f;
1521 CFX_ByteString formatString;
1522 CFX_ByteString localString;
1523 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1524 if (FXJSE_Value_IsNull(timeValue.get())) {
1525 bFlags = TRUE;
1526 } else {
1527 fTime = ValueToFloat(pThis, timeValue.get());
1528 if (FXSYS_fabs(fTime) < 1.0) {
1529 bFlags = TRUE;
1530 }
1531 }
1532 if (argc > 1) {
1533 std::unique_ptr<CFXJSE_Value> formatValue =
1534 GetSimpleValue(pThis, args, 1);
1535 if (FXJSE_Value_IsNull(formatValue.get())) {
1536 bFlags = TRUE;
1537 } else {
1538 ValueToUTF8String(formatValue.get(), formatString);
1539 }
1540 }
1541 if (argc == 3) {
1542 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1543 if (FXJSE_Value_IsNull(localValue.get())) {
1544 bFlags = TRUE;
1545 } else {
1546 ValueToUTF8String(localValue.get(), localString);
1547 }
1548 }
1549 if (!bFlags) {
1550 CFX_ByteString szLocalTimeString;
1551 Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(),
1552 localString.AsStringC(), FALSE, szLocalTimeString);
1553 if (szLocalTimeString.IsEmpty()) {
1554 szLocalTimeString = "";
1555 }
1556 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1557 szLocalTimeString.AsStringC());
1558 } else {
1559 FXJSE_Value_SetNull(args.GetReturnValue());
1560 }
1561 } else {
1562 ToJSContext(pThis, nullptr) 1499 ToJSContext(pThis, nullptr)
1563 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Time"); 1500 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Num2Time");
1501 return;
1564 } 1502 }
1503
1504 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1505 if (FXJSE_Value_IsNull(timeValue.get())) {
1506 FXJSE_Value_SetNull(args.GetReturnValue());
1507 return;
1508 }
1509 FX_FLOAT fTime = ValueToFloat(pThis, timeValue.get());
1510 if (FXSYS_fabs(fTime) < 1.0) {
1511 FXJSE_Value_SetNull(args.GetReturnValue());
1512 return;
1513 }
1514
1515 CFX_ByteString formatString;
1516 if (argc > 1) {
1517 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1518 if (FXJSE_Value_IsNull(formatValue.get())) {
1519 FXJSE_Value_SetNull(args.GetReturnValue());
1520 return;
1521 }
1522 ValueToUTF8String(formatValue.get(), formatString);
1523 }
1524
1525 CFX_ByteString localString;
1526 if (argc == 3) {
1527 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1528 if (FXJSE_Value_IsNull(localValue.get())) {
1529 FXJSE_Value_SetNull(args.GetReturnValue());
1530 return;
1531 }
1532 ValueToUTF8String(localValue.get(), localString);
1533 }
1534
1535 CFX_ByteString szLocalTimeString;
1536 Num2AllTime(pThis, (int32_t)fTime, formatString.AsStringC(),
1537 localString.AsStringC(), FALSE, szLocalTimeString);
1538 FXJSE_Value_SetUTF8String(args.GetReturnValue(),
1539 szLocalTimeString.AsStringC());
1565 } 1540 }
1566 1541
1567 // static 1542 // static
1568 void CXFA_FM2JSContext::Time(CFXJSE_Value* pThis, 1543 void CXFA_FM2JSContext::Time(CFXJSE_Value* pThis,
1569 const CFX_ByteStringC& szFuncName, 1544 const CFX_ByteStringC& szFuncName,
1570 CFXJSE_Arguments& args) { 1545 CFXJSE_Arguments& args) {
1571 if (args.GetLength() == 0) { 1546 if (args.GetLength() != 0) {
1572 time_t now;
1573 time(&now);
1574 struct tm* pGmt = gmtime(&now);
1575 int32_t iGMHour = pGmt->tm_hour;
1576 int32_t iGMMin = pGmt->tm_min;
1577 int32_t iGMSec = pGmt->tm_sec;
1578 FXJSE_Value_SetInteger(args.GetReturnValue(),
1579 ((iGMHour * 3600 + iGMMin * 60 + iGMSec) * 1000));
1580 } else {
1581 ToJSContext(pThis, nullptr) 1547 ToJSContext(pThis, nullptr)
1582 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time"); 1548 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time");
1549 return;
1583 } 1550 }
1551
1552 time_t now;
1553 time(&now);
1554
1555 struct tm* pGmt = gmtime(&now);
1556 FXJSE_Value_SetInteger(
1557 args.GetReturnValue(),
1558 ((pGmt->tm_hour * 3600 + pGmt->tm_min * 60 + pGmt->tm_sec) * 1000));
1584 } 1559 }
1585 1560
1586 // static 1561 // static
1587 void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis, 1562 void CXFA_FM2JSContext::Time2Num(CFXJSE_Value* pThis,
1588 const CFX_ByteStringC& szFuncName, 1563 const CFX_ByteStringC& szFuncName,
1589 CFXJSE_Arguments& args) { 1564 CFXJSE_Arguments& args) {
1590 int32_t argc = args.GetLength(); 1565 int32_t argc = args.GetLength();
1591 if ((argc > 0) && (argc < 4)) { 1566 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.
1592 FX_BOOL bFlags = FALSE;
1593 CFX_ByteString timeString;
1594 CFX_ByteString formatString;
1595 CFX_ByteString localString;
1596 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1597 if (ValueIsNull(pThis, timeValue.get())) {
1598 bFlags = TRUE;
1599 } else {
1600 ValueToUTF8String(timeValue.get(), timeString);
1601 }
1602 if (argc > 1) {
1603 std::unique_ptr<CFXJSE_Value> formatValue =
1604 GetSimpleValue(pThis, args, 1);
1605 if (ValueIsNull(pThis, formatValue.get())) {
1606 bFlags = TRUE;
1607 } else {
1608 ValueToUTF8String(formatValue.get(), formatString);
1609 }
1610 }
1611 if (argc == 3) {
1612 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1613 if (ValueIsNull(pThis, localValue.get())) {
1614 bFlags = TRUE;
1615 } else {
1616 ValueToUTF8String(localValue.get(), localString);
1617 }
1618 }
1619 if (!bFlags) {
1620 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
1621 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
1622 IFX_Locale* pLocale = nullptr;
1623 if (localString.IsEmpty()) {
1624 CXFA_Node* pThisNode =
1625 ToNode(pDoc->GetScriptContext()->GetThisObject());
1626 ASSERT(pThisNode);
1627 CXFA_WidgetData widgetData(pThisNode);
1628 pLocale = widgetData.GetLocal();
1629 } else {
1630 pLocale = pMgr->GetLocaleByName(
1631 CFX_WideString::FromUTF8(localString.AsStringC()));
1632 }
1633 CFX_WideString wsFormat;
1634 if (formatString.IsEmpty()) {
1635 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
1636 } else {
1637 wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC());
1638 }
1639 wsFormat = FX_WSTRC(L"time{") + wsFormat;
1640 wsFormat += FX_WSTRC(L"}");
1641 CXFA_LocaleValue localeValue(
1642 XFA_VT_TIME, CFX_WideString::FromUTF8(timeString.AsStringC()),
1643 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr);
1644 if (localeValue.IsValid()) {
1645 CFX_Unitime uniTime = localeValue.GetTime();
1646 int32_t hour = uniTime.GetHour();
1647 int32_t min = uniTime.GetMinute();
1648 int32_t second = uniTime.GetSecond();
1649 int32_t milSecond = uniTime.GetMillisecond();
1650 int32_t mins = hour * 60 + min;
1651 CXFA_TimeZoneProvider* pProvider = CXFA_TimeZoneProvider::Get();
1652 if (pProvider) {
1653 FX_TIMEZONE tz;
1654 pProvider->GetTimeZone(tz);
1655 mins -= (tz.tzHour * 60);
1656 while (mins > 1440) {
1657 mins -= 1440;
1658 }
1659 while (mins < 0) {
1660 mins += 1440;
1661 }
1662 hour = mins / 60;
1663 min = mins % 60;
1664 }
1665 int32_t iResult =
1666 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1;
1667 FXJSE_Value_SetInteger(args.GetReturnValue(), iResult);
1668 } else {
1669 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1670 }
1671 } else {
1672 FXJSE_Value_SetNull(args.GetReturnValue());
1673 }
1674 } else {
1675 ToJSContext(pThis, nullptr) 1567 ToJSContext(pThis, nullptr)
1676 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time2Num"); 1568 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"Time2Num");
1569 return;
1677 } 1570 }
1571
1572 CFX_ByteString timeString;
1573 std::unique_ptr<CFXJSE_Value> timeValue = GetSimpleValue(pThis, args, 0);
1574 if (ValueIsNull(pThis, timeValue.get())) {
1575 FXJSE_Value_SetNull(args.GetReturnValue());
1576 return;
1577 }
1578 ValueToUTF8String(timeValue.get(), timeString);
1579
1580 CFX_ByteString formatString;
1581 if (argc > 1) {
1582 std::unique_ptr<CFXJSE_Value> formatValue = GetSimpleValue(pThis, args, 1);
1583 if (ValueIsNull(pThis, formatValue.get())) {
1584 FXJSE_Value_SetNull(args.GetReturnValue());
1585 return;
1586 }
1587 ValueToUTF8String(formatValue.get(), formatString);
1588 }
1589
1590 CFX_ByteString localString;
1591 if (argc == 3) {
1592 std::unique_ptr<CFXJSE_Value> localValue = GetSimpleValue(pThis, args, 2);
1593 if (ValueIsNull(pThis, localValue.get())) {
1594 FXJSE_Value_SetNull(args.GetReturnValue());
1595 return;
1596 }
1597 ValueToUTF8String(localValue.get(), localString);
1598 }
1599
1600 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
1601 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
1602 IFX_Locale* pLocale = nullptr;
1603 if (localString.IsEmpty()) {
1604 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
1605 ASSERT(pThisNode);
1606
1607 CXFA_WidgetData widgetData(pThisNode);
1608 pLocale = widgetData.GetLocal();
1609 } else {
1610 pLocale = pMgr->GetLocaleByName(
1611 CFX_WideString::FromUTF8(localString.AsStringC()));
1612 }
1613
1614 CFX_WideString wsFormat;
1615 if (formatString.IsEmpty())
1616 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
1617 else
1618 wsFormat = CFX_WideString::FromUTF8(formatString.AsStringC());
1619
1620 wsFormat = FX_WSTRC(L"time{") + wsFormat;
1621 wsFormat += FX_WSTRC(L"}");
1622 CXFA_LocaleValue localeValue(XFA_VT_TIME,
1623 CFX_WideString::FromUTF8(timeString.AsStringC()),
1624 wsFormat, pLocale, pMgr);
1625 if (!localeValue.IsValid()) {
1626 FXJSE_Value_SetInteger(args.GetReturnValue(), 0);
1627 return;
1628 }
1629
1630 CFX_Unitime uniTime = localeValue.GetTime();
1631 int32_t hour = uniTime.GetHour();
1632 int32_t min = uniTime.GetMinute();
1633 int32_t second = uniTime.GetSecond();
1634 int32_t milSecond = uniTime.GetMillisecond();
1635 int32_t mins = hour * 60 + min;
1636 CXFA_TimeZoneProvider* pProvider = CXFA_TimeZoneProvider::Get();
1637 if (pProvider) {
1638 FX_TIMEZONE tz;
1639 pProvider->GetTimeZone(tz);
1640 mins -= (tz.tzHour * 60);
1641 while (mins > 1440)
1642 mins -= 1440;
1643 while (mins < 0)
1644 mins += 1440;
1645
1646 hour = mins / 60;
1647 min = mins % 60;
1648 }
1649 FXJSE_Value_SetInteger(
1650 args.GetReturnValue(),
1651 hour * 3600000 + min * 60000 + second * 1000 + milSecond + 1);
1678 } 1652 }
1679 1653
1680 // static 1654 // static
1681 void CXFA_FM2JSContext::TimeFmt(CFXJSE_Value* pThis, 1655 void CXFA_FM2JSContext::TimeFmt(CFXJSE_Value* pThis,
1682 const CFX_ByteStringC& szFuncName, 1656 const CFX_ByteStringC& szFuncName,
1683 CFXJSE_Arguments& args) { 1657 CFXJSE_Arguments& args) {
1684 int32_t argc = args.GetLength(); 1658 int32_t argc = args.GetLength();
1685 if (argc < 3) { 1659 if (argc >= 3) {
1686 FX_BOOL bFlags = FALSE;
1687 int32_t iStyle = 0;
1688 CFX_ByteString szLocal;
1689 if (argc > 0) {
1690 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1691 if (FXJSE_Value_IsNull(argStyle.get())) {
1692 bFlags = TRUE;
1693 }
1694 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1695 if (iStyle > 4 || iStyle < 0) {
1696 iStyle = 0;
1697 }
1698 }
1699 if (argc == 2) {
1700 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1701 if (FXJSE_Value_IsNull(argLocal.get())) {
1702 bFlags = TRUE;
1703 } else {
1704 ValueToUTF8String(argLocal.get(), szLocal);
1705 }
1706 }
1707 if (!bFlags) {
1708 CFX_ByteString formatStr;
1709 GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr);
1710 if (formatStr.IsEmpty()) {
1711 formatStr = "";
1712 }
1713 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1714 } else {
1715 FXJSE_Value_SetNull(args.GetReturnValue());
1716 }
1717 } else {
1718 ToJSContext(pThis, nullptr) 1660 ToJSContext(pThis, nullptr)
1719 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"TimeFmt"); 1661 ->ThrowException(XFA_IDS_INCORRECT_NUMBER_OF_METHOD, L"TimeFmt");
1662 return;
1720 } 1663 }
1664
1665 int32_t iStyle = 0;
1666 if (argc > 0) {
1667 std::unique_ptr<CFXJSE_Value> argStyle = GetSimpleValue(pThis, args, 0);
1668 if (FXJSE_Value_IsNull(argStyle.get())) {
1669 FXJSE_Value_SetNull(args.GetReturnValue());
1670 return;
1671 }
1672 iStyle = (int32_t)ValueToFloat(pThis, argStyle.get());
1673 if (iStyle > 4 || iStyle < 0)
1674 iStyle = 0;
1675 }
1676
1677 CFX_ByteString szLocal;
1678 if (argc == 2) {
1679 std::unique_ptr<CFXJSE_Value> argLocal = GetSimpleValue(pThis, args, 1);
1680 if (FXJSE_Value_IsNull(argLocal.get())) {
1681 FXJSE_Value_SetNull(args.GetReturnValue());
1682 return;
1683 }
1684 ValueToUTF8String(argLocal.get(), szLocal);
1685 }
1686
1687 CFX_ByteString formatStr;
1688 GetStandardTimeFormat(pThis, iStyle, szLocal.AsStringC(), formatStr);
1689 FXJSE_Value_SetUTF8String(args.GetReturnValue(), formatStr.AsStringC());
1721 } 1690 }
1722 1691
1723 // static 1692 // static
1724 FX_BOOL CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData, 1693 FX_BOOL CXFA_FM2JSContext::IsIsoDateFormat(const FX_CHAR* pData,
1725 int32_t iLength, 1694 int32_t iLength,
1726 int32_t& iStyle, 1695 int32_t& iStyle,
1727 int32_t& iYear, 1696 int32_t& iYear,
1728 int32_t& iMonth, 1697 int32_t& iMonth,
1729 int32_t& iDay) { 1698 int32_t& iDay) {
1730 iYear = 0; 1699 iYear = 0;
1731 iMonth = 1; 1700 iMonth = 1;
1732 iDay = 1; 1701 iDay = 1;
1733 FX_BOOL iRet = FALSE; 1702
1734 if (iLength < 4) { 1703 if (iLength < 4)
1735 return iRet; 1704 return FALSE;
1736 } 1705
1737 FX_CHAR strYear[5]; 1706 FX_CHAR strYear[5];
1738 strYear[4] = '\0'; 1707 strYear[4] = '\0';
1739 for (int32_t i = 0; i < 4; ++i) { 1708 for (int32_t i = 0; i < 4; ++i) {
1740 if (*(pData + i) <= '9' && *(pData + i) >= '0') { 1709 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.
1741 strYear[i] = *(pData + i); 1710 return FALSE;
1742 } else { 1711
1743 return iRet; 1712 strYear[i] = *(pData + i);
1744 }
1745 } 1713 }
1746 iYear = FXSYS_atoi(strYear); 1714 iYear = FXSYS_atoi(strYear);
1747 iStyle = 0; 1715 iStyle = 0;
1748 if (iLength > 4) { 1716 if (iLength == 4)
1749 if (*(pData + 4) == '-') { 1717 return TRUE;
1750 iStyle = 1; 1718
1751 } else { 1719 iStyle = *(pData + 4) == '-' ? 1 : 0;
1752 iStyle = 0; 1720
1753 }
1754 } else {
1755 iRet = TRUE;
1756 return iRet;
1757 }
1758 FX_CHAR strTemp[3]; 1721 FX_CHAR strTemp[3];
1759 strTemp[2] = '\0'; 1722 strTemp[2] = '\0';
1760 int32_t iPosOff = 0; 1723 int32_t iPosOff = iStyle == 0 ? 4 : 5;
1761 if (iStyle == 0) {
1762 iPosOff = 4;
1763 if (iLength == 4) {
1764 iRet = TRUE;
1765 return iRet;
1766 }
1767 } else {
1768 iPosOff = 5;
1769 if (iLength == 4) {
1770 iRet = TRUE;
1771 return iRet;
1772 }
1773 }
1774 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') || 1724 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') ||
1775 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) { 1725 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0'))
1776 return iRet; 1726 return FALSE;
1777 } 1727
1778 strTemp[0] = *(pData + iPosOff); 1728 strTemp[0] = *(pData + iPosOff);
1779 strTemp[1] = *(pData + iPosOff + 1); 1729 strTemp[1] = *(pData + iPosOff + 1);
1780 iMonth = FXSYS_atoi(strTemp); 1730 iMonth = FXSYS_atoi(strTemp);
1781 if (iMonth > 12 || iMonth < 1) { 1731 if (iMonth > 12 || iMonth < 1)
1782 return iRet; 1732 return FALSE;
1783 } 1733
1784 if (iStyle == 0) { 1734 if (iStyle == 0) {
1785 iPosOff += 2; 1735 iPosOff += 2;
1786 if (iLength == 6) { 1736 if (iLength == 6)
1787 iRet = 1; 1737 return TRUE;
1788 return iRet;
1789 }
1790 } else { 1738 } else {
1791 iPosOff += 3; 1739 iPosOff += 3;
1792 if (iLength == 7) { 1740 if (iLength == 7)
1793 iRet = 1; 1741 return TRUE;
1794 return iRet;
1795 }
1796 } 1742 }
1797 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') || 1743 if ((*(pData + iPosOff) > '9' || *(pData + iPosOff) < '0') ||
1798 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0')) { 1744 (*(pData + iPosOff + 1) > '9' || *(pData + iPosOff + 1) < '0'))
1799 return iRet; 1745 return FALSE;
1800 } 1746
1801 strTemp[0] = *(pData + iPosOff); 1747 strTemp[0] = *(pData + iPosOff);
1802 strTemp[1] = *(pData + iPosOff + 1); 1748 strTemp[1] = *(pData + iPosOff + 1);
1803 iDay = FXSYS_atoi(strTemp); 1749 iDay = FXSYS_atoi(strTemp);
1804 if (iPosOff + 2 < iLength) { 1750 if (iPosOff + 2 < iLength)
1805 return iRet; 1751 return FALSE;
1752
1753 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) {
1754 if (iMonth == 2 && iDay > 29)
1755 return FALSE;
1756 } else {
1757 if (iMonth == 2 && iDay > 28)
1758 return FALSE;
1806 } 1759 }
1807 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) { 1760 if (iMonth != 2) {
1808 if (iMonth == 2) { 1761 if (iMonth < 8) {
1809 if (iDay > 29) { 1762 if (iDay > (iMonth % 2 == 0 ? 30 : 31))
1810 return iRet; 1763 return FALSE;
1811 } 1764 } else if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1812 } else { 1765 return FALSE;
1813 if (iMonth < 8) {
1814 if (iDay > (iMonth % 2 == 0 ? 30 : 31)) {
1815 return iRet;
1816 }
1817 } else {
1818 if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1819 return iRet;
1820 }
1821 }
1822 }
1823 } else {
1824 if (iMonth == 2) {
1825 if (iDay > 28) {
1826 return iRet;
1827 }
1828 } else {
1829 if (iMonth < 8) {
1830 if (iDay > (iMonth % 2 == 0 ? 30 : 31)) {
1831 return iRet;
1832 }
1833 } else {
1834 if (iDay > (iMonth % 2 == 0 ? 31 : 30)) {
1835 return iRet;
1836 }
1837 }
1838 } 1766 }
1839 } 1767 }
1840 iRet = TRUE; 1768 return TRUE;
1841 return iRet;
1842 } 1769 }
1843 1770
1844 // static 1771 // static
1845 FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData, 1772 FX_BOOL CXFA_FM2JSContext::IsIsoTimeFormat(const FX_CHAR* pData,
1846 int32_t iLength, 1773 int32_t iLength,
1847 int32_t& iHour, 1774 int32_t& iHour,
1848 int32_t& iMinute, 1775 int32_t& iMinute,
1849 int32_t& iSecond, 1776 int32_t& iSecond,
1850 int32_t& iMilliSecond, 1777 int32_t& iMilliSecond,
1851 int32_t& iZoneHour, 1778 int32_t& iZoneHour,
1852 int32_t& iZoneMinute) { 1779 int32_t& iZoneMinute) {
1853 iHour = 0; 1780 iHour = 0;
1854 iMinute = 0; 1781 iMinute = 0;
1855 iSecond = 0; 1782 iSecond = 0;
1856 iMilliSecond = 0; 1783 iMilliSecond = 0;
1857 iZoneHour = 0; 1784 iZoneHour = 0;
1858 iZoneMinute = 0; 1785 iZoneMinute = 0;
1859 if (!pData) { 1786 if (!pData)
1860 return FALSE; 1787 return FALSE;
1861 } 1788
1862 int32_t iRet = FALSE;
1863 FX_CHAR strTemp[3]; 1789 FX_CHAR strTemp[3];
1864 strTemp[2] = '\0'; 1790 strTemp[2] = '\0';
1865 int32_t iIndex = 0;
1866 int32_t iZone = 0; 1791 int32_t iZone = 0;
1867 int32_t i = iIndex; 1792 int32_t i = 0;
1868 while (i < iLength) { 1793 while (i < iLength) {
1869 if ((*(pData + i) > '9' || *(pData + i) < '0') && *(pData + i) != ':') { 1794 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.
1870 iZone = i; 1795 iZone = i;
1871 break; 1796 break;
1872 } 1797 }
1873 ++i; 1798 ++i;
1874 } 1799 }
1875 if (i == iLength) { 1800 if (i == iLength)
1876 iZone = iLength; 1801 iZone = iLength;
1877 } 1802
1878 int32_t iPos = 0; 1803 int32_t iPos = 0;
1804 int32_t iIndex = 0;
1879 while (iIndex < iZone) { 1805 while (iIndex < iZone) {
1880 if (iIndex >= iZone) { 1806 if (iIndex >= iZone)
1881 break; 1807 break;
1882 } 1808
1883 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { 1809 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0')
1884 return iRet; 1810 return FALSE;
1885 } 1811
1886 strTemp[0] = *(pData + iIndex); 1812 strTemp[0] = *(pData + iIndex);
1887 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { 1813 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0')
1888 return iRet; 1814 return FALSE;
1889 } 1815
1890 strTemp[1] = *(pData + iIndex + 1); 1816 strTemp[1] = *(pData + iIndex + 1);
1891 if (FXSYS_atoi(strTemp) > 60) { 1817 if (FXSYS_atoi(strTemp) > 60)
1892 return iRet; 1818 return FALSE;
1893 } 1819
1894 if (*(pData + 2) == ':') { 1820 if (*(pData + 2) == ':') {
1895 if (iPos == 0) { 1821 if (iPos == 0) {
1896 iHour = FXSYS_atoi(strTemp); 1822 iHour = FXSYS_atoi(strTemp);
1897 ++iPos; 1823 ++iPos;
1898 } else if (iPos == 1) { 1824 } else if (iPos == 1) {
1899 iMinute = FXSYS_atoi(strTemp); 1825 iMinute = FXSYS_atoi(strTemp);
1900 ++iPos; 1826 ++iPos;
1901 } else { 1827 } else {
1902 iSecond = FXSYS_atoi(strTemp); 1828 iSecond = FXSYS_atoi(strTemp);
1903 } 1829 }
1904 iIndex += 3; 1830 iIndex += 3;
1905 } else { 1831 } else {
1906 if (iPos == 0) { 1832 if (iPos == 0) {
1907 iHour = FXSYS_atoi(strTemp); 1833 iHour = FXSYS_atoi(strTemp);
1908 ++iPos; 1834 ++iPos;
1909 } else if (iPos == 1) { 1835 } else if (iPos == 1) {
1910 iMinute = FXSYS_atoi(strTemp); 1836 iMinute = FXSYS_atoi(strTemp);
1911 ++iPos; 1837 ++iPos;
1912 } else if (iPos == 2) { 1838 } else if (iPos == 2) {
1913 iSecond = FXSYS_atoi(strTemp); 1839 iSecond = FXSYS_atoi(strTemp);
1914 ++iPos; 1840 ++iPos;
1915 } 1841 }
1916 iIndex += 2; 1842 iIndex += 2;
1917 } 1843 }
1918 } 1844 }
1919 if (*(pData + iIndex) == '.') { 1845 if (*(pData + iIndex) == '.') {
1920 ++iIndex; 1846 ++iIndex;
1921 FX_CHAR strSec[4]; 1847 FX_CHAR strSec[4];
1922 strSec[3] = '\0'; 1848 strSec[3] = '\0';
1923 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { 1849 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0')
1924 return iRet; 1850 return FALSE;
1925 } 1851
1926 strSec[0] = *(pData + iIndex); 1852 strSec[0] = *(pData + iIndex);
1927 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { 1853 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0')
1928 return iRet; 1854 return FALSE;
1929 } 1855
1930 strSec[1] = *(pData + iIndex + 1); 1856 strSec[1] = *(pData + iIndex + 1);
1931 if (*(pData + iIndex + 2) > '9' || *(pData + iIndex + 2) < '0') { 1857 if (*(pData + iIndex + 2) > '9' || *(pData + iIndex + 2) < '0')
1932 return iRet; 1858 return FALSE;
1933 } 1859
1934 strSec[2] = *(pData + iIndex + 2); 1860 strSec[2] = *(pData + iIndex + 2);
1935 iMilliSecond = FXSYS_atoi(strSec); 1861 iMilliSecond = FXSYS_atoi(strSec);
1936 if (iMilliSecond > 100) { 1862 if (iMilliSecond > 100) {
1937 iMilliSecond = 0; 1863 iMilliSecond = 0;
1938 return iRet; 1864 return FALSE;
1939 } 1865 }
1940 iIndex += 3; 1866 iIndex += 3;
1941 } 1867 }
1868 if (*(pData + iIndex) == 'z' || *(pData + iIndex) == 'Z')
1869 return TRUE;
1870
1942 int32_t iSign = 1; 1871 int32_t iSign = 1;
1943 if (*(pData + iIndex) == 'z' || *(pData + iIndex) == 'Z') { 1872 if (*(pData + iIndex) == '+') {
1944 iRet = 1;
1945 return iRet;
1946 } else if (*(pData + iIndex) == '+') {
1947 ++iIndex; 1873 ++iIndex;
1948 } else if (*(pData + iIndex) == '-') { 1874 } else if (*(pData + iIndex) == '-') {
1949 iSign = -1; 1875 iSign = -1;
1950 ++iIndex; 1876 ++iIndex;
1951 } 1877 }
1952 iPos = 0; 1878 iPos = 0;
1953 while (iIndex < iLength) { 1879 while (iIndex < iLength) {
1954 if (iIndex >= iLength) { 1880 if (iIndex >= iLength)
1955 return iRet; 1881 return FALSE;
1956 } 1882 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0')
1957 if (*(pData + iIndex) > '9' || *(pData + iIndex) < '0') { 1883 return FALSE;
1958 return iRet; 1884
1959 }
1960 strTemp[0] = *(pData + iIndex); 1885 strTemp[0] = *(pData + iIndex);
1961 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0') { 1886 if (*(pData + iIndex + 1) > '9' || *(pData + iIndex + 1) < '0')
1962 return iRet; 1887 return FALSE;
1963 } 1888
1964 strTemp[1] = *(pData + iIndex + 1); 1889 strTemp[1] = *(pData + iIndex + 1);
1965 if (FXSYS_atoi(strTemp) > 60) { 1890 if (FXSYS_atoi(strTemp) > 60)
1966 return iRet; 1891 return FALSE;
1967 } 1892
1968 if (*(pData + 2) == ':') { 1893 if (*(pData + 2) == ':') {
1969 if (iPos == 0) { 1894 if (iPos == 0) {
1970 iZoneHour = FXSYS_atoi(strTemp); 1895 iZoneHour = FXSYS_atoi(strTemp);
1971 } else if (iPos == 1) { 1896 } else if (iPos == 1) {
1972 iZoneMinute = FXSYS_atoi(strTemp); 1897 iZoneMinute = FXSYS_atoi(strTemp);
1973 } 1898 }
1974 iIndex += 3; 1899 iIndex += 3;
1975 } else { 1900 } else {
1976 if (!iPos) { 1901 if (!iPos) {
1977 iZoneHour = FXSYS_atoi(strTemp); 1902 iZoneHour = FXSYS_atoi(strTemp);
1978 ++iPos; 1903 ++iPos;
1979 } else if (iPos == 1) { 1904 } else if (iPos == 1) {
1980 iZoneMinute = FXSYS_atoi(strTemp); 1905 iZoneMinute = FXSYS_atoi(strTemp);
1981 ++iPos; 1906 ++iPos;
1982 } 1907 }
1983 iIndex += 2; 1908 iIndex += 2;
1984 } 1909 }
1985 } 1910 }
1986 if (iIndex < iLength) { 1911 if (iIndex < iLength)
1987 return iRet; 1912 return FALSE;
1988 } 1913
1989 iZoneHour *= iSign; 1914 iZoneHour *= iSign;
1990 iRet = TRUE; 1915 return TRUE;
1991 return iRet;
1992 } 1916 }
1993 1917
1994 // static 1918 // static
1995 FX_BOOL CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData, 1919 FX_BOOL CXFA_FM2JSContext::IsIsoDateTimeFormat(const FX_CHAR* pData,
1996 int32_t iLength, 1920 int32_t iLength,
1997 int32_t& iYear, 1921 int32_t& iYear,
1998 int32_t& iMonth, 1922 int32_t& iMonth,
1999 int32_t& iDay, 1923 int32_t& iDay,
2000 int32_t& iHour, 1924 int32_t& iHour,
2001 int32_t& iMinute, 1925 int32_t& iMinute,
2002 int32_t& iSecond, 1926 int32_t& iSecond,
2003 int32_t& iMillionSecond, 1927 int32_t& iMillionSecond,
2004 int32_t& iZoneHour, 1928 int32_t& iZoneHour,
2005 int32_t& iZoneMinute) { 1929 int32_t& iZoneMinute) {
2006 iYear = 0; 1930 iYear = 0;
2007 iMonth = 0; 1931 iMonth = 0;
2008 iDay = 0; 1932 iDay = 0;
2009 iHour = 0; 1933 iHour = 0;
2010 iMinute = 0; 1934 iMinute = 0;
2011 iSecond = 0; 1935 iSecond = 0;
2012 if (!pData) { 1936 if (!pData)
2013 return FALSE; 1937 return FALSE;
2014 } 1938
2015 int32_t iRet = FALSE;
2016 int32_t iIndex = 0; 1939 int32_t iIndex = 0;
2017 while (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') { 1940 while (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') {
2018 if (iIndex >= iLength) { 1941 if (iIndex >= iLength)
2019 return iRet; 1942 return FALSE;
2020 }
2021 ++iIndex; 1943 ++iIndex;
2022 } 1944 }
2023 if (iIndex != 8 && iIndex != 10) { 1945 if (iIndex != 8 && iIndex != 10)
2024 return iRet; 1946 return FALSE;
2025 } 1947
2026 int32_t iStyle = -1; 1948 int32_t iStyle = -1;
2027 iRet = IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay); 1949 if (!IsIsoDateFormat(pData, iIndex, iStyle, iYear, iMonth, iDay))
2028 if (!iRet) { 1950 return FALSE;
2029 return iRet; 1951 if (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't')
2030 } 1952 return TRUE;
2031 if (*(pData + iIndex) != 'T' && *(pData + iIndex) != 't') { 1953
2032 return iRet;
2033 }
2034 ++iIndex; 1954 ++iIndex;
2035 if (((iLength - iIndex > 13) && (iLength - iIndex < 6)) && 1955 if (((iLength - iIndex > 13) && (iLength - iIndex < 6)) &&
2036 (iLength - iIndex != 15)) { 1956 (iLength - iIndex != 15)) {
2037 return iRet; 1957 return TRUE;
2038 } 1958 }
2039 iRet = IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute, 1959 if (!IsIsoTimeFormat(pData + iIndex, iLength - iIndex, iHour, iMinute,
2040 iSecond, iMillionSecond, iZoneHour, iZoneMinute); 1960 iSecond, iMillionSecond, iZoneHour, iZoneMinute)) {
2041 if (!iRet) { 1961 return FALSE;
2042 return iRet;
2043 } 1962 }
2044 iRet = TRUE; 1963
2045 return iRet; 1964 return TRUE;
2046 } 1965 }
2047 1966
2048 // static 1967 // static
2049 FX_BOOL CXFA_FM2JSContext::Local2IsoDate(CFXJSE_Value* pThis, 1968 FX_BOOL CXFA_FM2JSContext::Local2IsoDate(CFXJSE_Value* pThis,
2050 const CFX_ByteStringC& szDate, 1969 const CFX_ByteStringC& szDate,
2051 const CFX_ByteStringC& szFormat, 1970 const CFX_ByteStringC& szFormat,
2052 const CFX_ByteStringC& szLocale, 1971 const CFX_ByteStringC& szLocale,
2053 CFX_ByteString& strIsoDate) { 1972 CFX_ByteString& strIsoDate) {
2054 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 1973 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2055 if (!pDoc) { 1974 if (!pDoc)
2056 return FALSE; 1975 return FALSE;
2057 } 1976
2058 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 1977 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2059 IFX_Locale* pLocale = nullptr; 1978 IFX_Locale* pLocale = nullptr;
2060 if (szLocale.IsEmpty()) { 1979 if (szLocale.IsEmpty()) {
2061 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 1980 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2062 ASSERT(pThisNode); 1981 ASSERT(pThisNode);
1982
2063 CXFA_WidgetData widgetData(pThisNode); 1983 CXFA_WidgetData widgetData(pThisNode);
2064 pLocale = widgetData.GetLocal(); 1984 pLocale = widgetData.GetLocal();
2065 } else { 1985 } else {
2066 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 1986 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2067 } 1987 }
2068 if (!pLocale) { 1988 if (!pLocale)
2069 return FALSE; 1989 return FALSE;
2070 } 1990
2071 CFX_WideString wsFormat; 1991 CFX_WideString wsFormat;
2072 if (szFormat.IsEmpty()) { 1992 if (szFormat.IsEmpty())
2073 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 1993 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2074 } else { 1994 else
2075 wsFormat = CFX_WideString::FromUTF8(szFormat); 1995 wsFormat = CFX_WideString::FromUTF8(szFormat);
2076 } 1996
2077 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), 1997 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate),
2078 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); 1998 wsFormat, pLocale, pMgr);
2079 CFX_Unitime dt = widgetValue.GetDate(); 1999 CFX_Unitime dt = widgetValue.GetDate();
2080 strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay()); 2000 strIsoDate.Format("%4d-%02d-%02d", dt.GetYear(), dt.GetMonth(), dt.GetDay());
2081 return TRUE; 2001 return TRUE;
2082 } 2002 }
2083 2003
2084 // static 2004 // static
2085 FX_BOOL CXFA_FM2JSContext::Local2IsoTime(CFXJSE_Value* pThis, 2005 FX_BOOL CXFA_FM2JSContext::Local2IsoTime(CFXJSE_Value* pThis,
2086 const CFX_ByteStringC& szTime, 2006 const CFX_ByteStringC& szTime,
2087 const CFX_ByteStringC& szFormat, 2007 const CFX_ByteStringC& szFormat,
2088 const CFX_ByteStringC& szLocale, 2008 const CFX_ByteStringC& szLocale,
2089 CFX_ByteString& strIsoTime) { 2009 CFX_ByteString& strIsoTime) {
2090 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2010 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2091 if (!pDoc) { 2011 if (!pDoc)
2092 return FALSE; 2012 return FALSE;
2093 } 2013
2094 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2014 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2095 IFX_Locale* pLocale = nullptr; 2015 IFX_Locale* pLocale = nullptr;
2096 if (szLocale.IsEmpty()) { 2016 if (szLocale.IsEmpty()) {
2097 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2017 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2098 ASSERT(pThisNode); 2018 ASSERT(pThisNode);
2019
2099 CXFA_WidgetData widgetData(pThisNode); 2020 CXFA_WidgetData widgetData(pThisNode);
2100 pLocale = widgetData.GetLocal(); 2021 pLocale = widgetData.GetLocal();
2101 } else { 2022 } else {
2102 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2023 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2103 } 2024 }
2104 if (!pLocale) { 2025 if (!pLocale)
2105 return FALSE; 2026 return FALSE;
2106 } 2027
2107 CFX_WideString wsFormat; 2028 CFX_WideString wsFormat;
2108 if (szFormat.IsEmpty()) { 2029 if (szFormat.IsEmpty())
2109 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2030 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2110 } else { 2031 else
2111 wsFormat = CFX_WideString::FromUTF8(szFormat); 2032 wsFormat = CFX_WideString::FromUTF8(szFormat);
2112 } 2033
2113 wsFormat = FX_WSTRC(L"time{") + wsFormat; 2034 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2114 wsFormat += FX_WSTRC(L"}"); 2035 wsFormat += FX_WSTRC(L"}");
2115 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), 2036 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime),
2116 wsFormat, pLocale, (CXFA_LocaleMgr*)pMgr); 2037 wsFormat, pLocale, pMgr);
2117 CFX_Unitime utime = widgetValue.GetTime(); 2038 CFX_Unitime utime = widgetValue.GetTime();
2118 strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(), 2039 strIsoTime.Format("%02d:%02d:%02d.%03d", utime.GetHour(), utime.GetMinute(),
2119 utime.GetSecond(), utime.GetMillisecond()); 2040 utime.GetSecond(), utime.GetMillisecond());
2120 return TRUE; 2041 return TRUE;
2121 } 2042 }
2122 2043
2123 // static 2044 // static
2124 FX_BOOL CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis, 2045 FX_BOOL CXFA_FM2JSContext::IsoDate2Local(CFXJSE_Value* pThis,
2125 const CFX_ByteStringC& szDate, 2046 const CFX_ByteStringC& szDate,
2126 const CFX_ByteStringC& szFormat, 2047 const CFX_ByteStringC& szFormat,
2127 const CFX_ByteStringC& szLocale, 2048 const CFX_ByteStringC& szLocale,
2128 CFX_ByteString& strLocalDate) { 2049 CFX_ByteString& strLocalDate) {
2129 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2050 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2130 if (!pDoc) { 2051 if (!pDoc)
2131 return FALSE; 2052 return FALSE;
2132 } 2053
2133 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2054 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2134 IFX_Locale* pLocale = nullptr; 2055 IFX_Locale* pLocale = nullptr;
2135 if (szLocale.IsEmpty()) { 2056 if (szLocale.IsEmpty()) {
2136 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2057 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2137 ASSERT(pThisNode); 2058 ASSERT(pThisNode);
2138 CXFA_WidgetData widgetData(pThisNode); 2059 CXFA_WidgetData widgetData(pThisNode);
2139 pLocale = widgetData.GetLocal(); 2060 pLocale = widgetData.GetLocal();
2140 } else { 2061 } else {
2141 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2062 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2142 } 2063 }
2143 if (!pLocale) { 2064 if (!pLocale)
2144 return FALSE; 2065 return FALSE;
2145 } 2066
2146 CFX_WideString wsFormat; 2067 CFX_WideString wsFormat;
2147 if (szFormat.IsEmpty()) { 2068 if (szFormat.IsEmpty())
2148 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2069 pLocale->GetDatePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2149 } else { 2070 else
2150 wsFormat = CFX_WideString::FromUTF8(szFormat); 2071 wsFormat = CFX_WideString::FromUTF8(szFormat);
2151 } 2072
2152 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate), 2073 CXFA_LocaleValue widgetValue(XFA_VT_DATE, CFX_WideString::FromUTF8(szDate),
2153 (CXFA_LocaleMgr*)pMgr); 2074 pMgr);
2154 CFX_WideString wsRet; 2075 CFX_WideString wsRet;
2155 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, 2076 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2156 XFA_VALUEPICTURE_Display); 2077 XFA_VALUEPICTURE_Display);
2157 strLocalDate = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); 2078 strLocalDate = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength());
2158 return TRUE; 2079 return TRUE;
2159 } 2080 }
2160 2081
2161 // static 2082 // static
2162 FX_BOOL CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis, 2083 FX_BOOL CXFA_FM2JSContext::IsoTime2Local(CFXJSE_Value* pThis,
2163 const CFX_ByteStringC& szTime, 2084 const CFX_ByteStringC& szTime,
2164 const CFX_ByteStringC& szFormat, 2085 const CFX_ByteStringC& szFormat,
2165 const CFX_ByteStringC& szLocale, 2086 const CFX_ByteStringC& szLocale,
2166 CFX_ByteString& strLocalTime) { 2087 CFX_ByteString& strLocalTime) {
2167 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2088 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2168 if (!pDoc) { 2089 if (!pDoc)
2169 return FALSE; 2090 return FALSE;
2170 } 2091
2171 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2092 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2172 IFX_Locale* pLocale = nullptr; 2093 IFX_Locale* pLocale = nullptr;
2173 if (szLocale.IsEmpty()) { 2094 if (szLocale.IsEmpty()) {
2174 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2095 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2175 ASSERT(pThisNode); 2096 ASSERT(pThisNode);
2176 CXFA_WidgetData widgetData(pThisNode); 2097 CXFA_WidgetData widgetData(pThisNode);
2177 pLocale = widgetData.GetLocal(); 2098 pLocale = widgetData.GetLocal();
2178 } else { 2099 } else {
2179 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2100 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2180 } 2101 }
2181 if (!pLocale) { 2102 if (!pLocale)
2182 return FALSE; 2103 return FALSE;
2183 } 2104
2184 CFX_WideString wsFormat; 2105 CFX_WideString wsFormat;
2185 if (szFormat.IsEmpty()) { 2106 if (szFormat.IsEmpty())
2186 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2107 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2187 } else { 2108 else
2188 wsFormat = CFX_WideString::FromUTF8(szFormat); 2109 wsFormat = CFX_WideString::FromUTF8(szFormat);
2189 } 2110
2190 wsFormat = FX_WSTRC(L"time{") + wsFormat; 2111 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2191 wsFormat += FX_WSTRC(L"}"); 2112 wsFormat += FX_WSTRC(L"}");
2192 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), 2113 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime),
2193 (CXFA_LocaleMgr*)pMgr); 2114 pMgr);
2194 CFX_WideString wsRet; 2115 CFX_WideString wsRet;
2195 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, 2116 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2196 XFA_VALUEPICTURE_Display); 2117 XFA_VALUEPICTURE_Display);
2197 strLocalTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); 2118 strLocalTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength());
2198 return TRUE; 2119 return TRUE;
2199 } 2120 }
2200 2121
2201 // static 2122 // static
2202 FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis, 2123 FX_BOOL CXFA_FM2JSContext::GetGMTTime(CFXJSE_Value* pThis,
2203 const CFX_ByteStringC& szTime, 2124 const CFX_ByteStringC& szTime,
2204 const CFX_ByteStringC& szFormat, 2125 const CFX_ByteStringC& szFormat,
2205 const CFX_ByteStringC& szLocale, 2126 const CFX_ByteStringC& szLocale,
2206 CFX_ByteString& strGMTTime) { 2127 CFX_ByteString& strGMTTime) {
2207 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2128 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2208 if (!pDoc) { 2129 if (!pDoc)
2209 return FALSE; 2130 return FALSE;
2210 } 2131
2211 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr(); 2132 CXFA_LocaleMgr* pMgr = pDoc->GetLocalMgr();
2212 IFX_Locale* pLocale = nullptr; 2133 IFX_Locale* pLocale = nullptr;
2213 if (szLocale.IsEmpty()) { 2134 if (szLocale.IsEmpty()) {
2214 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2135 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2215 ASSERT(pThisNode); 2136 ASSERT(pThisNode);
2216 CXFA_WidgetData widgetData(pThisNode); 2137 CXFA_WidgetData widgetData(pThisNode);
2217 pLocale = widgetData.GetLocal(); 2138 pLocale = widgetData.GetLocal();
2218 } else { 2139 } else {
2219 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale)); 2140 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocale));
2220 } 2141 }
2221 if (!pLocale) { 2142 if (!pLocale)
2222 return FALSE; 2143 return FALSE;
2223 } 2144
2224 CFX_WideString wsFormat; 2145 CFX_WideString wsFormat;
2225 if (szFormat.IsEmpty()) { 2146 if (szFormat.IsEmpty())
2226 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat); 2147 pLocale->GetTimePattern(FX_LOCALEDATETIMESUBCATEGORY_Default, wsFormat);
2227 } else { 2148 else
2228 wsFormat = CFX_WideString::FromUTF8(szFormat); 2149 wsFormat = CFX_WideString::FromUTF8(szFormat);
2229 } 2150
2230 wsFormat = FX_WSTRC(L"time{") + wsFormat; 2151 wsFormat = FX_WSTRC(L"time{") + wsFormat;
2231 wsFormat += FX_WSTRC(L"}"); 2152 wsFormat += FX_WSTRC(L"}");
2232 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime), 2153 CXFA_LocaleValue widgetValue(XFA_VT_TIME, CFX_WideString::FromUTF8(szTime),
2233 (CXFA_LocaleMgr*)pMgr); 2154 pMgr);
2234 CFX_WideString wsRet; 2155 CFX_WideString wsRet;
2235 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale, 2156 widgetValue.FormatPatterns(wsRet, wsFormat, pLocale,
2236 XFA_VALUEPICTURE_Display); 2157 XFA_VALUEPICTURE_Display);
2237 strGMTTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength()); 2158 strGMTTime = FX_UTF8Encode(wsRet.c_str(), wsRet.GetLength());
2238 return TRUE; 2159 return TRUE;
2239 } 2160 }
2240 2161
2241 // static 2162 // static
2242 int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) { 2163 int32_t CXFA_FM2JSContext::DateString2Num(const CFX_ByteStringC& szDateString) {
2243 FX_BOOL bFlags = FALSE;
2244 int32_t iLength = szDateString.GetLength(); 2164 int32_t iLength = szDateString.GetLength();
2245 FX_BOOL iRet = FALSE;
2246 int32_t iStyle = -1;
2247 int32_t iYear = 0; 2165 int32_t iYear = 0;
2248 int32_t iMonth = 0; 2166 int32_t iMonth = 0;
2249 int32_t iDay = 0; 2167 int32_t iDay = 0;
2250 int32_t iHour = 0;
2251 int32_t iMinute = 0;
2252 int32_t iSecond = 0;
2253 int32_t iMillionSecond = 0;
2254 int32_t iZoneHour = 0;
2255 int32_t iZoneMinute = 0;
2256 if (iLength <= 10) { 2168 if (iLength <= 10) {
2257 iRet = IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth, 2169 int32_t iStyle = -1;
2258 iDay); 2170 if (!IsIsoDateFormat(szDateString.c_str(), iLength, iStyle, iYear, iMonth,
2171 iDay)) {
2172 return 0;
2173 }
2259 } else { 2174 } else {
2260 iRet = IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, 2175 int32_t iHour = 0;
2261 iDay, iHour, iMinute, iSecond, iMillionSecond, 2176 int32_t iMinute = 0;
2262 iZoneHour, iZoneMinute); 2177 int32_t iSecond = 0;
2178 int32_t iMilliSecond = 0;
2179 int32_t iZoneHour = 0;
2180 int32_t iZoneMinute = 0;
2181 if (!IsIsoDateTimeFormat(szDateString.c_str(), iLength, iYear, iMonth, iDay,
2182 iHour, iMinute, iSecond, iMilliSecond, iZoneHour,
2183 iZoneMinute)) {
2184 return 0;
2185 }
2263 } 2186 }
2264 if (!iRet) { 2187
2265 bFlags = TRUE;
2266 }
2267 FX_FLOAT dDays = 0; 2188 FX_FLOAT dDays = 0;
2268 int32_t i = 1; 2189 int32_t i = 1;
2269 if (iYear < 1900) { 2190 if (iYear < 1900)
2270 bFlags = TRUE; 2191 return 0;
2192
2193 while (iYear - i >= 1900) {
2194 dDays +=
2195 ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400))
2196 ? 366
2197 : 365;
2198 ++i;
2271 } 2199 }
2272 if (!bFlags) { 2200 i = 1;
2273 while (iYear - i >= 1900) { 2201 while (i < iMonth) {
2274 if ((!((iYear - i) % 4) && ((iYear - i) % 100)) || !((iYear - i) % 400)) { 2202 if (i == 2)
2275 dDays += 366; 2203 dDays += ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) ? 29 : 28;
2276 } else { 2204 else if (i <= 7)
2277 dDays += 365; 2205 dDays += (i % 2 == 0) ? 30 : 31;
2278 } 2206 else
2279 ++i; 2207 dDays += (i % 2 == 0) ? 31 : 30;
2280 } 2208
2281 i = 1; 2209 ++i;
2282 while (i < iMonth) { 2210 }
2283 if (i == 2) { 2211 i = 0;
2284 if ((!(iYear % 4) && (iYear % 100)) || !(iYear % 400)) { 2212 while (iDay - i > 0) {
2285 dDays += 29; 2213 dDays += 1;
2286 } else { 2214 ++i;
2287 dDays += 28;
2288 }
2289 } else if (i <= 7) {
2290 if (i % 2 == 0) {
2291 dDays += 30;
2292 } else {
2293 dDays += 31;
2294 }
2295 } else {
2296 if (i % 2 == 0) {
2297 dDays += 31;
2298 } else {
2299 dDays += 30;
2300 }
2301 }
2302 ++i;
2303 }
2304 i = 0;
2305 while (iDay - i > 0) {
2306 dDays += 1;
2307 ++i;
2308 }
2309 } else {
2310 dDays = 0;
2311 } 2215 }
2312 return (int32_t)dDays; 2216 return (int32_t)dDays;
2313 } 2217 }
2314 2218
2315 // static 2219 // static
2316 void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis, 2220 void CXFA_FM2JSContext::GetLocalDateFormat(CFXJSE_Value* pThis,
2317 int32_t iStyle, 2221 int32_t iStyle,
2318 const CFX_ByteStringC& szLocalStr, 2222 const CFX_ByteStringC& szLocalStr,
2319 CFX_ByteString& strFormat, 2223 CFX_ByteString& strFormat,
2320 FX_BOOL bStandard) { 2224 FX_BOOL bStandard) {
2321 FX_LOCALEDATETIMESUBCATEGORY strStyle; 2225 FX_LOCALEDATETIMESUBCATEGORY strStyle;
2322 switch (iStyle) { 2226 switch (iStyle) {
2323 case 0:
2324 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2325 break;
2326 case 1: 2227 case 1:
2327 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; 2228 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short;
2328 break; 2229 break;
2329 case 2:
2330 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2331 break;
2332 case 3: 2230 case 3:
2333 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; 2231 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long;
2334 break; 2232 break;
2335 case 4: 2233 case 4:
2336 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; 2234 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full;
2337 break; 2235 break;
2236 case 0:
2237 case 2:
2338 default: 2238 default:
2339 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; 2239 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2340 break; 2240 break;
2341 } 2241 }
2342 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2242 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2343 if (!pDoc) { 2243 if (!pDoc)
2344 return; 2244 return;
2345 } 2245
2346 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2347 IFX_Locale* pLocale = nullptr; 2246 IFX_Locale* pLocale = nullptr;
2348 if (szLocalStr.IsEmpty()) { 2247 if (szLocalStr.IsEmpty()) {
2349 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2248 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2350 ASSERT(pThisNode); 2249 ASSERT(pThisNode);
2250
2351 CXFA_WidgetData widgetData(pThisNode); 2251 CXFA_WidgetData widgetData(pThisNode);
2352 pLocale = widgetData.GetLocal(); 2252 pLocale = widgetData.GetLocal();
2353 } else { 2253 } else {
2354 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); 2254 pLocale = pDoc->GetLocalMgr()->GetLocaleByName(
2255 CFX_WideString::FromUTF8(szLocalStr));
2355 } 2256 }
2356 if (!pLocale) { 2257 if (!pLocale)
2357 return; 2258 return;
2358 } 2259
2359 CFX_WideString strRet; 2260 CFX_WideString strRet;
2360 pLocale->GetDatePattern(strStyle, strRet); 2261 pLocale->GetDatePattern(strStyle, strRet);
2361 if (!bStandard) { 2262 if (!bStandard) {
2362 CFX_WideString wsSymbols; 2263 CFX_WideString wsSymbols;
2363 pLocale->GetDateTimeSymbols(wsSymbols); 2264 pLocale->GetDateTimeSymbols(wsSymbols);
2364 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date); 2265 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Date);
2365 } 2266 }
2366 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); 2267 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength());
2367 } 2268 }
2368 2269
2369 // static 2270 // static
2370 void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis, 2271 void CXFA_FM2JSContext::GetLocalTimeFormat(CFXJSE_Value* pThis,
2371 int32_t iStyle, 2272 int32_t iStyle,
2372 const CFX_ByteStringC& szLocalStr, 2273 const CFX_ByteStringC& szLocalStr,
2373 CFX_ByteString& strFormat, 2274 CFX_ByteString& strFormat,
2374 FX_BOOL bStandard) { 2275 FX_BOOL bStandard) {
2375 FX_LOCALEDATETIMESUBCATEGORY strStyle; 2276 FX_LOCALEDATETIMESUBCATEGORY strStyle;
2376 switch (iStyle) { 2277 switch (iStyle) {
2377 case 0:
2378 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2379 break;
2380 case 1: 2278 case 1:
2381 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short; 2279 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Short;
2382 break; 2280 break;
2383 case 2:
2384 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2385 break;
2386 case 3: 2281 case 3:
2387 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long; 2282 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Long;
2388 break; 2283 break;
2389 case 4: 2284 case 4:
2390 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full; 2285 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Full;
2391 break; 2286 break;
2287 case 0:
2288 case 2:
2392 default: 2289 default:
2393 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium; 2290 strStyle = FX_LOCALEDATETIMESUBCATEGORY_Medium;
2394 break; 2291 break;
2395 } 2292 }
2396 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument(); 2293 CXFA_Document* pDoc = ToJSContext(pThis, nullptr)->GetDocument();
2397 if (!pDoc) { 2294 if (!pDoc)
2398 return; 2295 return;
2399 } 2296
2400 IFX_LocaleMgr* pMgr = (IFX_LocaleMgr*)pDoc->GetLocalMgr();
2401 IFX_Locale* pLocale = nullptr; 2297 IFX_Locale* pLocale = nullptr;
2402 if (szLocalStr.IsEmpty()) { 2298 if (szLocalStr.IsEmpty()) {
2403 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject()); 2299 CXFA_Node* pThisNode = ToNode(pDoc->GetScriptContext()->GetThisObject());
2404 ASSERT(pThisNode); 2300 ASSERT(pThisNode);
2301
2405 CXFA_WidgetData widgetData(pThisNode); 2302 CXFA_WidgetData widgetData(pThisNode);
2406 pLocale = widgetData.GetLocal(); 2303 pLocale = widgetData.GetLocal();
2407 } else { 2304 } else {
2408 pLocale = pMgr->GetLocaleByName(CFX_WideString::FromUTF8(szLocalStr)); 2305 pLocale = pDoc->GetLocalMgr()->GetLocaleByName(
2306 CFX_WideString::FromUTF8(szLocalStr));
2409 } 2307 }
2410 if (!pLocale) { 2308 if (!pLocale)
2411 return; 2309 return;
2412 } 2310
2413 CFX_WideString strRet; 2311 CFX_WideString strRet;
2414 pLocale->GetTimePattern(strStyle, strRet); 2312 pLocale->GetTimePattern(strStyle, strRet);
2415 if (!bStandard) { 2313 if (!bStandard) {
2416 CFX_WideString wsSymbols; 2314 CFX_WideString wsSymbols;
2417 pLocale->GetDateTimeSymbols(wsSymbols); 2315 pLocale->GetDateTimeSymbols(wsSymbols);
2418 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time); 2316 AlternateDateTimeSymbols(strRet, wsSymbols, g_sAltTable_Time);
2419 } 2317 }
2420 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength()); 2318 strFormat = FX_UTF8Encode(strRet.c_str(), strRet.GetLength());
2421 } 2319 }
2422 2320
(...skipping 16 matching lines...) Expand all
2439 // static 2337 // static
2440 void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis, 2338 void CXFA_FM2JSContext::Num2AllTime(CFXJSE_Value* pThis,
2441 int32_t iTime, 2339 int32_t iTime,
2442 const CFX_ByteStringC& szFormat, 2340 const CFX_ByteStringC& szFormat,
2443 const CFX_ByteStringC& szLocale, 2341 const CFX_ByteStringC& szLocale,
2444 FX_BOOL bGM, 2342 FX_BOOL bGM,
2445 CFX_ByteString& strTime) { 2343 CFX_ByteString& strTime) {
2446 int32_t iHour = 0; 2344 int32_t iHour = 0;
2447 int32_t iMin = 0; 2345 int32_t iMin = 0;
2448 int32_t iSec = 0; 2346 int32_t iSec = 0;
2449 int32_t iZoneHour = 0;
2450 int32_t iZoneMin = 0;
2451 int32_t iZoneSec = 0;
2452 iHour = static_cast<int>(iTime) / 3600000; 2347 iHour = static_cast<int>(iTime) / 3600000;
2453 iMin = (static_cast<int>(iTime) - iHour * 3600000) / 60000; 2348 iMin = (static_cast<int>(iTime) - iHour * 3600000) / 60000;
2454 iSec = (static_cast<int>(iTime) - iHour * 3600000 - iMin * 60000) / 1000; 2349 iSec = (static_cast<int>(iTime) - iHour * 3600000 - iMin * 60000) / 1000;
2350
2455 if (!bGM) { 2351 if (!bGM) {
2352 int32_t iZoneHour = 0;
2353 int32_t iZoneMin = 0;
2354 int32_t iZoneSec = 0;
2456 GetLocalTimeZone(iZoneHour, iZoneMin, iZoneSec); 2355 GetLocalTimeZone(iZoneHour, iZoneMin, iZoneSec);
2457 iHour += iZoneHour; 2356 iHour += iZoneHour;
2458 iMin += iZoneMin; 2357 iMin += iZoneMin;
2459 iSec += iZoneSec; 2358 iSec += iZoneSec;
2460 } 2359 }
2461 int32_t iRet = 0; 2360
2361 FX_BOOL iRet = FALSE;
2462 CFX_ByteString strIsoTime; 2362 CFX_ByteString strIsoTime;
2463 strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec); 2363 strIsoTime.Format("%02d:%02d:%02d", iHour, iMin, iSec);
2464 if (bGM) { 2364 if (bGM) {
2465 iRet = 2365 iRet =
2466 GetGMTTime(pThis, strIsoTime.AsStringC(), szFormat, szLocale, strTime); 2366 GetGMTTime(pThis, strIsoTime.AsStringC(), szFormat, szLocale, strTime);
2467 } else { 2367 } else {
2468 iRet = IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale, 2368 iRet = IsoTime2Local(pThis, strIsoTime.AsStringC(), szFormat, szLocale,
2469 strTime); 2369 strTime);
2470 } 2370 }
2471 if (!iRet) { 2371 if (!iRet)
2472 strTime = ""; 2372 strTime = "";
2473 }
2474 } 2373 }
2475 2374
2476 // static 2375 // static
2477 void CXFA_FM2JSContext::GetLocalTimeZone(int32_t& iHour, 2376 void CXFA_FM2JSContext::GetLocalTimeZone(int32_t& iHour,
2478 int32_t& iMin, 2377 int32_t& iMin,
2479 int32_t& iSec) { 2378 int32_t& iSec) {
2480 time_t now; 2379 time_t now;
2481 time(&now); 2380 time(&now);
2381
2482 struct tm* pGmt = gmtime(&now); 2382 struct tm* pGmt = gmtime(&now);
2483 int32_t iGMHour = pGmt->tm_hour;
2484 int32_t iGMMin = pGmt->tm_min;
2485 int32_t iGMSec = pGmt->tm_sec;
2486 struct tm* pLocal = localtime(&now); 2383 struct tm* pLocal = localtime(&now);
2487 int32_t iLocalHour = pLocal->tm_hour; 2384 iHour = pLocal->tm_hour - pGmt->tm_hour;
2488 int32_t iLocalMin = pLocal->tm_min; 2385 iMin = pLocal->tm_min - pGmt->tm_min;
2489 int32_t iLocalSec = pLocal->tm_sec; 2386 iSec = pLocal->tm_sec - pGmt->tm_sec;
2490 iHour = iLocalHour - iGMHour;
2491 iMin = iLocalMin - iGMMin;
2492 iSec = iLocalSec - iGMSec;
2493 } 2387 }
2494 2388
2495 // static 2389 // static
2496 void CXFA_FM2JSContext::Apr(CFXJSE_Value* pThis, 2390 void CXFA_FM2JSContext::Apr(CFXJSE_Value* pThis,
2497 const CFX_ByteStringC& szFuncName, 2391 const CFX_ByteStringC& szFuncName,
2498 CFXJSE_Arguments& args) { 2392 CFXJSE_Arguments& args) {
2499 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr); 2393 CXFA_FM2JSContext* pContext = ToJSContext(pThis, nullptr);
2500 if (args.GetLength() == 3) { 2394 if (args.GetLength() == 3) {
2501 FX_BOOL bFlags = FALSE; 2395 FX_BOOL bFlags = FALSE;
2502 FX_DOUBLE nPrincipal = 0; 2396 FX_DOUBLE nPrincipal = 0;
(...skipping 4379 matching lines...) Expand 10 before | Expand all | Expand 10 after
6882 CFX_WideString wsFormat; 6776 CFX_WideString wsFormat;
6883 pAppProvider->LoadString(iStringID, wsFormat); 6777 pAppProvider->LoadString(iStringID, wsFormat);
6884 CFX_WideString wsMessage; 6778 CFX_WideString wsMessage;
6885 va_list arg_ptr; 6779 va_list arg_ptr;
6886 va_start(arg_ptr, iStringID); 6780 va_start(arg_ptr, iStringID);
6887 wsMessage.FormatV(wsFormat.c_str(), arg_ptr); 6781 wsMessage.FormatV(wsFormat.c_str(), arg_ptr);
6888 va_end(arg_ptr); 6782 va_end(arg_ptr);
6889 FXJSE_ThrowMessage( 6783 FXJSE_ThrowMessage(
6890 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC()); 6784 "", FX_UTF8Encode(wsMessage.c_str(), wsMessage.GetLength()).AsStringC());
6891 } 6785 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698