bugfix of Compare Date

issue:https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I71FTU?from=project-issue

Signed-off-by: maojunwei <maojunwei1@huawei.com>
Change-Id: Ic00eeca26b952f3f05377d204f82b9e602a5e454
This commit is contained in:
maojunwei 2023-05-09 09:22:09 +08:00
parent 73f3401a67
commit ad5feaadd6
5 changed files with 67 additions and 0 deletions

View File

@ -30,6 +30,7 @@
#include "ecmascript/js_api/js_api_stack.h"
#include "ecmascript/js_api/js_api_vector.h"
#include "ecmascript/js_array.h"
#include "ecmascript/js_date.h"
#include "ecmascript/js_handle.h"
#include "ecmascript/js_object-inl.h"
#include "ecmascript/js_primitive_ref.h"
@ -270,6 +271,11 @@ bool JSTaggedValue::Equal(JSThread *thread, const JSHandle<JSTaggedValue> &x, co
ComparisonResult JSTaggedValue::Compare(JSThread *thread, const JSHandle<JSTaggedValue> &x,
const JSHandle<JSTaggedValue> &y)
{
if (x->IsDate() && y->IsDate()) {
double timeX = JSDate::Cast(x->GetTaggedObject())->GetTimeValue().GetDouble();
double timeY = JSDate::Cast(y->GetTaggedObject())->GetTimeValue().GetDouble();
return StrictNumberCompare(timeX, timeY);
}
JSHandle<JSTaggedValue> primX(thread, ToPrimitive(thread, x));
RETURN_VALUE_IF_ABRUPT_COMPLETION(thread, ComparisonResult::UNDEFINED);
JSHandle<JSTaggedValue> primY(thread, ToPrimitive(thread, y));

View File

@ -33,6 +33,7 @@ group("ark_js_moduletest") {
"container",
"dataproperty",
"datecase",
"datecompare",
"dateparse",
"dynamicimport",
"dyninstruction",

View File

@ -0,0 +1,18 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("datecompare") {
deps = []
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @tc.name:datecompare
* @tc.desc:test date
* @tc.type: FUNC
* @tc.require: issueI5NO8G
*/
var str1 = Date.parse('08/04/2011')
var str2 = Date.parse('2010-08-04')
var timer1 = new Date(str1)
var timer2 = new Date(str2)
print(timer1 > timer2)

View File

@ -0,0 +1,14 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
true