diff options
Diffstat (limited to 'fxjs')
-rw-r--r-- | fxjs/cjs_publicmethods.cpp | 18 | ||||
-rw-r--r-- | fxjs/cjs_publicmethods.h | 9 | ||||
-rw-r--r-- | fxjs/cjs_publicmethods_embeddertest.cpp | 81 | ||||
-rw-r--r-- | fxjs/cjs_util.cpp | 2 |
4 files changed, 58 insertions, 52 deletions
diff --git a/fxjs/cjs_publicmethods.cpp b/fxjs/cjs_publicmethods.cpp index 5fbee0dbdf..4ccd00d554 100644 --- a/fxjs/cjs_publicmethods.cpp +++ b/fxjs/cjs_publicmethods.cpp @@ -490,9 +490,9 @@ double CJS_PublicMethods::ParseNormalDate(const WideString& value, nYear, nHour, nMin, nSec)); } -double CJS_PublicMethods::MakeRegularDate(const WideString& value, - const WideString& format, - bool* bWrongFormat) { +double CJS_PublicMethods::ParseDateUsingFormat(const WideString& value, + const WideString& format, + bool* bWrongFormat) { double dt = JS_GetDateTime(); if (format.IsEmpty() || value.IsEmpty()) @@ -753,8 +753,8 @@ double CJS_PublicMethods::MakeRegularDate(const WideString& value, return dRet; } -WideString CJS_PublicMethods::MakeFormatDate(double dDate, - const WideString& format) { +WideString CJS_PublicMethods::PrintDateUsingFormat(double dDate, + const WideString& format) { WideString sRet; WideString sPart; @@ -1195,7 +1195,7 @@ CJS_Result CJS_PublicMethods::AFDate_FormatEx( // such as "Tue Aug 11 14:24:16 GMT+08002009" dDate = MakeInterDate(strValue); } else { - dDate = MakeRegularDate(strValue, sFormat, nullptr); + dDate = ParseDateUsingFormat(strValue, sFormat, nullptr); } if (std::isnan(dDate)) { @@ -1205,7 +1205,7 @@ CJS_Result CJS_PublicMethods::AFDate_FormatEx( return CJS_Result::Failure(JSMessage::kParseDateError); } - val = MakeFormatDate(dDate, sFormat); + val = PrintDateUsingFormat(dDate, sFormat); return CJS_Result::Success(); } @@ -1268,7 +1268,7 @@ CJS_Result CJS_PublicMethods::AFDate_KeystrokeEx( WideString sFormat = pRuntime->ToWideString(params[0]); bool bWrongFormat = false; - double dRet = MakeRegularDate(strValue, sFormat, &bWrongFormat); + double dRet = ParseDateUsingFormat(strValue, sFormat, &bWrongFormat); if (bWrongFormat || std::isnan(dRet)) { WideString swMsg = WideString::Format( JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str()); @@ -1521,7 +1521,7 @@ CJS_Result CJS_PublicMethods::AFParseDateEx( WideString sValue = pRuntime->ToWideString(params[0]); WideString sFormat = pRuntime->ToWideString(params[1]); - double dDate = MakeRegularDate(sValue, sFormat, nullptr); + double dDate = ParseDateUsingFormat(sValue, sFormat, nullptr); if (std::isnan(dDate)) { WideString swMsg = WideString::Format( JSGetStringFromID(JSMessage::kParseDateError).c_str(), sFormat.c_str()); diff --git a/fxjs/cjs_publicmethods.h b/fxjs/cjs_publicmethods.h index 975ba6e9d4..0b72fb3e0a 100644 --- a/fxjs/cjs_publicmethods.h +++ b/fxjs/cjs_publicmethods.h @@ -18,12 +18,13 @@ class CJS_PublicMethods final : public CJS_Object { ~CJS_PublicMethods() override; static void DefineJSObjects(CFXJS_Engine* pEngine); - static double MakeRegularDate(const WideString& value, - const WideString& format, - bool* bWrongFormat); + static double ParseDateUsingFormat(const WideString& value, + const WideString& format, + bool* bWrongFormat); // Exposed for testing. - static WideString MakeFormatDate(double dDate, const WideString& format); + static WideString PrintDateUsingFormat(double dDate, + const WideString& format); static bool IsNumber(const WideString& str); static CJS_Result AFNumber_Format( diff --git a/fxjs/cjs_publicmethods_embeddertest.cpp b/fxjs/cjs_publicmethods_embeddertest.cpp index 5f241f391e..93c526a352 100644 --- a/fxjs/cjs_publicmethods_embeddertest.cpp +++ b/fxjs/cjs_publicmethods_embeddertest.cpp @@ -21,7 +21,7 @@ double RoundDownDate(double date) { class CJS_PublicMethodsEmbedderTest : public JSEmbedderTest {}; -TEST_F(CJS_PublicMethodsEmbedderTest, MakeRegularDate) { +TEST_F(CJS_PublicMethodsEmbedderTest, ParseDateUsingFormat) { v8::Isolate::Scope isolate_scope(isolate()); v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(GetV8Context()); @@ -30,144 +30,149 @@ TEST_F(CJS_PublicMethodsEmbedderTest, MakeRegularDate) { // 1968 bWrongFormat = false; - date = CJS_PublicMethods::MakeRegularDate(L"06/25/1968", L"mm/dd/yyyy", - &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"06/25/1968", L"mm/dd/yyyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(-47865600000, date); EXPECT_FALSE(bWrongFormat); // 1968 bWrongFormat = false; - date = CJS_PublicMethods::MakeRegularDate(L"25061968", L"ddmmyyyy", - &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"25061968", L"ddmmyyyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(-47865600000, date); EXPECT_FALSE(bWrongFormat); // 1968 bWrongFormat = false; - date = CJS_PublicMethods::MakeRegularDate(L"19680625", L"yyyymmdd", - &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"19680625", L"yyyymmdd", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(-47865600000, date); EXPECT_FALSE(bWrongFormat); // 1985 bWrongFormat = false; - date = CJS_PublicMethods::MakeRegularDate(L"31121985", L"ddmmyyyy", - &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"31121985", L"ddmmyyyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(504835200000.0, date); EXPECT_FALSE(bWrongFormat); // 2085, the other '85. bWrongFormat = false; - date = - CJS_PublicMethods::MakeRegularDate(L"311285", L"ddmmyy", &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"311285", L"ddmmyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(3660595200000.0, date); EXPECT_FALSE(bWrongFormat); // 1995 bWrongFormat = false; - date = CJS_PublicMethods::MakeRegularDate(L"01021995", L"ddmmyyyy", - &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"01021995", L"ddmmyyyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(791596800000.0, date); EXPECT_FALSE(bWrongFormat); // 2095, the other '95. bWrongFormat = false; - date = - CJS_PublicMethods::MakeRegularDate(L"010295", L"ddmmyy", &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"010295", L"ddmmyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(3947356800000.0, date); EXPECT_FALSE(bWrongFormat); // 2005 bWrongFormat = false; - date = CJS_PublicMethods::MakeRegularDate(L"01022005", L"ddmmyyyy", - &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"01022005", L"ddmmyyyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(1107216000000.0, date); EXPECT_FALSE(bWrongFormat); // 2005 bWrongFormat = false; - date = - CJS_PublicMethods::MakeRegularDate(L"010205", L"ddmmyy", &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"010205", L"ddmmyy", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(1107216000000.0, date); EXPECT_FALSE(bWrongFormat); // 2005 in a different format. https://crbug.com/436572 bWrongFormat = false; - date = - CJS_PublicMethods::MakeRegularDate(L"050201", L"yymmdd", &bWrongFormat); + date = CJS_PublicMethods::ParseDateUsingFormat(L"050201", L"yymmdd", + &bWrongFormat); date = RoundDownDate(date); EXPECT_DOUBLE_EQ(1107216000000.0, date); EXPECT_FALSE(bWrongFormat); } -TEST_F(CJS_PublicMethodsEmbedderTest, MakeFormatDate) { +TEST_F(CJS_PublicMethodsEmbedderTest, PrintDateUsingFormat) { v8::Isolate::Scope isolate_scope(isolate()); v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope(GetV8Context()); WideString formatted_date; // 1968-06-25 - formatted_date = CJS_PublicMethods::MakeFormatDate(-47952000000, L"ddmmyy"); + formatted_date = + CJS_PublicMethods::PrintDateUsingFormat(-47952000000, L"ddmmyy"); EXPECT_STREQ(L"250668", formatted_date.c_str()); - formatted_date = CJS_PublicMethods::MakeFormatDate(-47952000000, L"yy/mm/dd"); + formatted_date = + CJS_PublicMethods::PrintDateUsingFormat(-47952000000, L"yy/mm/dd"); EXPECT_STREQ(L"68/06/25", formatted_date.c_str()); // 1969-12-31 - formatted_date = CJS_PublicMethods::MakeFormatDate(-0.0001, L"ddmmyy"); + formatted_date = CJS_PublicMethods::PrintDateUsingFormat(-0.0001, L"ddmmyy"); EXPECT_STREQ(L"311269", formatted_date.c_str()); - formatted_date = CJS_PublicMethods::MakeFormatDate(-0.0001, L"yy!mmdd"); + formatted_date = CJS_PublicMethods::PrintDateUsingFormat(-0.0001, L"yy!mmdd"); EXPECT_STREQ(L"69!1231", formatted_date.c_str()); // 1970-01-01 - formatted_date = CJS_PublicMethods::MakeFormatDate(0, L"ddmmyy"); + formatted_date = CJS_PublicMethods::PrintDateUsingFormat(0, L"ddmmyy"); EXPECT_STREQ(L"010170", formatted_date.c_str()); - formatted_date = CJS_PublicMethods::MakeFormatDate(0, L"mm-yyyy-dd"); + formatted_date = CJS_PublicMethods::PrintDateUsingFormat(0, L"mm-yyyy-dd"); EXPECT_STREQ(L"01-1970-01", formatted_date.c_str()); // 1985-12-31 - formatted_date = CJS_PublicMethods::MakeFormatDate(504835200000.0, L"ddmmyy"); + formatted_date = + CJS_PublicMethods::PrintDateUsingFormat(504835200000.0, L"ddmmyy"); EXPECT_STREQ(L"311285", formatted_date.c_str()); - formatted_date = CJS_PublicMethods::MakeFormatDate(504835200000.0, L"yymmdd"); + formatted_date = + CJS_PublicMethods::PrintDateUsingFormat(504835200000.0, L"yymmdd"); EXPECT_STREQ(L"851231", formatted_date.c_str()); // 1995-02-01 - formatted_date = CJS_PublicMethods::MakeFormatDate(791596800000.0, L"ddmmyy"); + formatted_date = + CJS_PublicMethods::PrintDateUsingFormat(791596800000.0, L"ddmmyy"); EXPECT_STREQ(L"010295", formatted_date.c_str()); formatted_date = - CJS_PublicMethods::MakeFormatDate(791596800000.0, L"yyyymmdd"); + CJS_PublicMethods::PrintDateUsingFormat(791596800000.0, L"yyyymmdd"); EXPECT_STREQ(L"19950201", formatted_date.c_str()); // 2005-02-01 formatted_date = - CJS_PublicMethods::MakeFormatDate(1107216000000.0, L"ddmmyy"); + CJS_PublicMethods::PrintDateUsingFormat(1107216000000.0, L"ddmmyy"); EXPECT_STREQ(L"010205", formatted_date.c_str()); formatted_date = - CJS_PublicMethods::MakeFormatDate(1107216000000.0, L"yyyyddmm"); + CJS_PublicMethods::PrintDateUsingFormat(1107216000000.0, L"yyyyddmm"); EXPECT_STREQ(L"20050102", formatted_date.c_str()); // 2085-12-31 formatted_date = - CJS_PublicMethods::MakeFormatDate(3660595200000.0, L"ddmmyy"); + CJS_PublicMethods::PrintDateUsingFormat(3660595200000.0, L"ddmmyy"); EXPECT_STREQ(L"311285", formatted_date.c_str()); formatted_date = - CJS_PublicMethods::MakeFormatDate(3660595200000.0, L"yyyydd"); + CJS_PublicMethods::PrintDateUsingFormat(3660595200000.0, L"yyyydd"); EXPECT_STREQ(L"208531", formatted_date.c_str()); // 2095-02-01 formatted_date = - CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"ddmmyy"); + CJS_PublicMethods::PrintDateUsingFormat(3947356800000.0, L"ddmmyy"); EXPECT_STREQ(L"010295", formatted_date.c_str()); formatted_date = - CJS_PublicMethods::MakeFormatDate(3947356800000.0, L"mmddyyyy"); + CJS_PublicMethods::PrintDateUsingFormat(3947356800000.0, L"mmddyyyy"); EXPECT_STREQ(L"02012095", formatted_date.c_str()); } diff --git a/fxjs/cjs_util.cpp b/fxjs/cjs_util.cpp index 0c40b10117..6d883cc0bc 100644 --- a/fxjs/cjs_util.cpp +++ b/fxjs/cjs_util.cpp @@ -370,7 +370,7 @@ CJS_Result CJS_Util::scand(CJS_Runtime* pRuntime, WideString sDate = pRuntime->ToWideString(params[1]); double dDate = JS_GetDateTime(); if (sDate.GetLength() > 0) - dDate = CJS_PublicMethods::MakeRegularDate(sDate, sFormat, nullptr); + dDate = CJS_PublicMethods::ParseDateUsingFormat(sDate, sFormat, nullptr); if (std::isnan(dDate)) return CJS_Result::Success(pRuntime->NewUndefined()); |