| OLD | NEW |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
| 6 | 6 |
| 7 #include "fpdfsdk/javascript/PublicMethods.h" | 7 #include "fpdfsdk/javascript/PublicMethods.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 if (bWrongFormat) | 299 if (bWrongFormat) |
| 300 *bWrongFormat = false; | 300 *bWrongFormat = false; |
| 301 } else { | 301 } else { |
| 302 if (bWrongFormat) | 302 if (bWrongFormat) |
| 303 *bWrongFormat = true; | 303 *bWrongFormat = true; |
| 304 return dt; | 304 return dt; |
| 305 } | 305 } |
| 306 | 306 |
| 307 CFX_WideString swTemp; | 307 CFX_WideString swTemp; |
| 308 swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec); | 308 swTemp.Format(L"%d/%d/%d %d:%d:%d", nMonth, nDay, nYear, nHour, nMin, nSec); |
| 309 return JS_DateParse(swTemp.c_str()); | 309 return JS_DateParse(swTemp); |
| 310 } | 310 } |
| 311 | 311 |
| 312 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, | 312 double CJS_PublicMethods::MakeRegularDate(const CFX_WideString& value, |
| 313 const CFX_WideString& format, | 313 const CFX_WideString& format, |
| 314 bool* bWrongFormat) { | 314 bool* bWrongFormat) { |
| 315 double dt = JS_GetDateTime(); | 315 double dt = JS_GetDateTime(); |
| 316 | 316 |
| 317 if (format.IsEmpty() || value.IsEmpty()) | 317 if (format.IsEmpty() || value.IsEmpty()) |
| 318 return dt; | 318 return dt; |
| 319 | 319 |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 if (nHour < 0 || nHour > 24) | 556 if (nHour < 0 || nHour > 24) |
| 557 bBadFormat = true; | 557 bBadFormat = true; |
| 558 | 558 |
| 559 if (nMin < 0 || nMin > 60) | 559 if (nMin < 0 || nMin > 60) |
| 560 bBadFormat = true; | 560 bBadFormat = true; |
| 561 | 561 |
| 562 if (nSec < 0 || nSec > 60) | 562 if (nSec < 0 || nSec > 60) |
| 563 bBadFormat = true; | 563 bBadFormat = true; |
| 564 | 564 |
| 565 double dRet = 0; | 565 double dRet = 0; |
| 566 | |
| 567 if (bBadFormat) { | 566 if (bBadFormat) { |
| 568 dRet = ParseNormalDate(value, &bBadFormat); | 567 dRet = ParseNormalDate(value, &bBadFormat); |
| 569 } else { | 568 } else { |
| 570 dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), | 569 dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), |
| 571 JS_MakeTime(nHour, nMin, nSec, 0)); | 570 JS_MakeTime(nHour, nMin, nSec, 0)); |
| 572 | 571 if (JS_PortIsNan(dRet)) |
| 573 if (JS_PortIsNan(dRet)) { | 572 dRet = JS_DateParse(value); |
| 574 dRet = JS_DateParse(value.c_str()); | |
| 575 } | |
| 576 } | 573 } |
| 577 | 574 |
| 578 if (JS_PortIsNan(dRet)) { | 575 if (JS_PortIsNan(dRet)) |
| 579 dRet = ParseNormalDate(value, &bBadFormat); | 576 dRet = ParseNormalDate(value, &bBadFormat); |
| 580 } | |
| 581 | 577 |
| 582 if (bWrongFormat) | 578 if (bWrongFormat) |
| 583 *bWrongFormat = bBadFormat; | 579 *bWrongFormat = bBadFormat; |
| 580 |
| 584 return dRet; | 581 return dRet; |
| 585 } | 582 } |
| 586 | 583 |
| 587 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, | 584 CFX_WideString CJS_PublicMethods::MakeFormatDate(double dDate, |
| 588 const CFX_WideString& format) { | 585 const CFX_WideString& format) { |
| 589 CFX_WideString sRet = L"", sPart = L""; | 586 CFX_WideString sRet = L"", sPart = L""; |
| 590 | 587 |
| 591 int nYear = JS_GetYearFromTime(dDate); | 588 int nYear = JS_GetYearFromTime(dDate); |
| 592 int nMonth = JS_GetMonthFromTime(dDate) + 1; | 589 int nMonth = JS_GetMonthFromTime(dDate) + 1; |
| 593 int nDay = JS_GetDayFromTime(dDate); | 590 int nDay = JS_GetDayFromTime(dDate); |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1197 nMonth = 12; | 1194 nMonth = 12; |
| 1198 | 1195 |
| 1199 int nDay = FX_atof(wsArray[2].AsStringC()); | 1196 int nDay = FX_atof(wsArray[2].AsStringC()); |
| 1200 int nHour = FX_atof(wsArray[3].AsStringC()); | 1197 int nHour = FX_atof(wsArray[3].AsStringC()); |
| 1201 int nMin = FX_atof(wsArray[4].AsStringC()); | 1198 int nMin = FX_atof(wsArray[4].AsStringC()); |
| 1202 int nSec = FX_atof(wsArray[5].AsStringC()); | 1199 int nSec = FX_atof(wsArray[5].AsStringC()); |
| 1203 int nYear = FX_atof(wsArray[7].AsStringC()); | 1200 int nYear = FX_atof(wsArray[7].AsStringC()); |
| 1204 double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), | 1201 double dRet = JS_MakeDate(JS_MakeDay(nYear, nMonth - 1, nDay), |
| 1205 JS_MakeTime(nHour, nMin, nSec, 0)); | 1202 JS_MakeTime(nHour, nMin, nSec, 0)); |
| 1206 if (JS_PortIsNan(dRet)) | 1203 if (JS_PortIsNan(dRet)) |
| 1207 dRet = JS_DateParse(strValue.c_str()); | 1204 dRet = JS_DateParse(strValue); |
| 1208 | 1205 |
| 1209 return dRet; | 1206 return dRet; |
| 1210 } | 1207 } |
| 1211 | 1208 |
| 1212 // AFDate_KeystrokeEx(cFormat) | 1209 // AFDate_KeystrokeEx(cFormat) |
| 1213 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( | 1210 FX_BOOL CJS_PublicMethods::AFDate_KeystrokeEx( |
| 1214 IJS_Context* cc, | 1211 IJS_Context* cc, |
| 1215 const std::vector<CJS_Value>& params, | 1212 const std::vector<CJS_Value>& params, |
| 1216 CJS_Value& vRet, | 1213 CJS_Value& vRet, |
| 1217 CFX_WideString& sError) { | 1214 CFX_WideString& sError) { |
| (...skipping 627 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1845 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); | 1842 nums.SetElement(nIndex, CJS_Value(pRuntime, sPart.c_str())); |
| 1846 } | 1843 } |
| 1847 | 1844 |
| 1848 if (nums.GetLength() > 0) | 1845 if (nums.GetLength() > 0) |
| 1849 vRet = nums; | 1846 vRet = nums; |
| 1850 else | 1847 else |
| 1851 vRet.SetNull(); | 1848 vRet.SetNull(); |
| 1852 | 1849 |
| 1853 return TRUE; | 1850 return TRUE; |
| 1854 } | 1851 } |
| OLD | NEW |