From c45d9b8a3c1004a2dea2131f18e8da0f2298e03c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E5=A4=A9=E4=BD=91?= <1462027985@qq.com> Date: Wed, 29 Dec 2021 06:55:25 +0000 Subject: [PATCH 1/3] update runtime/main/extend/systemplugin/ohos/systemTime.js. add systemTime js api8 mock --- .../extend/systemplugin/ohos/systemTime.js | 96 +++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/runtime/main/extend/systemplugin/ohos/systemTime.js b/runtime/main/extend/systemplugin/ohos/systemTime.js index 0afd3d84..9cc6eb8f 100644 --- a/runtime/main/extend/systemplugin/ohos/systemTime.js +++ b/runtime/main/extend/systemplugin/ohos/systemTime.js @@ -14,6 +14,78 @@ export function mockSystemTime() { }) } }, + getCurrentTime: function (...args) { + console.warn("systemTime.getCurrentTime interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getCurrentTimeNs: function (...args) { + console.warn("systemTime.getCurrentTimeNs interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getRealActiveTime: function (...args) { + console.warn("systemTime.getRealActiveTime interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getRealActiveTimeNs: function (...args) { + console.warn("systemTime.getRealActiveTimeNs interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getRealTime: function (...args) { + console.warn("systemTime.getRealTime interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, + getRealTimeNs: function (...args) { + console.warn("systemTime.getRealTimeNs interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramNumberMock); + }) + } + }, setDate: function (...args) { console.warn("systemTime.setDate interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -26,6 +98,18 @@ export function mockSystemTime() { }) } }, + getDate: function (...args) { + console.warn("systemTime.getDate interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramObjectMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramObjectMock); + }) + } + }, setTimezone: function (...args) { console.warn("systemTime.setTimezone interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") @@ -37,6 +121,18 @@ export function mockSystemTime() { resolve(); }) } + }, + getTimeZone: function (...args) { + console.warn("systemTime.getTimeZone interface mocked in the Previewer. How this interface works on the" + + " Previewer may be different from that on a real device.") + const len = args.length + if (typeof args[len - 1] === 'function') { + args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramStringMock) + } else { + return new Promise((resolve, reject) => { + resolve(paramMock.paramStringMock); + }) + } } } } \ No newline at end of file -- Gitee From 5ba62c9c7ff4e9fe41ab8890a16be90db756627b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E5=A4=A9=E4=BD=91?= <1462027985@qq.com> Date: Wed, 29 Dec 2021 07:32:26 +0000 Subject: [PATCH 2/3] update runtime/main/extend/systemplugin/ohos/systemTime.js. Signed-off-by: zhangtianyou --- .../main/extend/systemplugin/ohos/systemTime.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/runtime/main/extend/systemplugin/ohos/systemTime.js b/runtime/main/extend/systemplugin/ohos/systemTime.js index 9cc6eb8f..8a0561e1 100644 --- a/runtime/main/extend/systemplugin/ohos/systemTime.js +++ b/runtime/main/extend/systemplugin/ohos/systemTime.js @@ -19,7 +19,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); @@ -31,7 +31,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); @@ -43,7 +43,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); @@ -55,7 +55,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); @@ -67,7 +67,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); @@ -79,7 +79,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); @@ -103,7 +103,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramObjectMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramObjectMock); @@ -127,7 +127,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock,paramMock.paramStringMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) } else { return new Promise((resolve, reject) => { resolve(paramMock.paramStringMock); -- Gitee From 01aa94aed2ed314cac80dcdcd161acd7c541bf4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BA=84=E5=A4=A9=E4=BD=91?= <1462027985@qq.com> Date: Wed, 29 Dec 2021 07:58:57 +0000 Subject: [PATCH 3/3] update runtime/main/extend/systemplugin/ohos/systemTime.js. Signed-off-by: zhuangtianyou <1462027985@qq.com> --- .../extend/systemplugin/ohos/systemTime.js | 84 +++++++++---------- 1 file changed, 42 insertions(+), 42 deletions(-) diff --git a/runtime/main/extend/systemplugin/ohos/systemTime.js b/runtime/main/extend/systemplugin/ohos/systemTime.js index 8a0561e1..0555a58d 100644 --- a/runtime/main/extend/systemplugin/ohos/systemTime.js +++ b/runtime/main/extend/systemplugin/ohos/systemTime.js @@ -5,7 +5,7 @@ export function mockSystemTime() { setTime: function (...args) { console.warn("systemTime.setTime interface mocked in the Previewer. How this interface works on the" + " Previewer may be different from that on a real device.") - const len = args.length + const len = args.length; if (typeof args[len - 1] === 'function') { args[len - 1].call(this, paramMock.businessErrorMock) } else { @@ -15,75 +15,75 @@ export function mockSystemTime() { } }, getCurrentTime: function (...args) { - console.warn("systemTime.getCurrentTime interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getCurrentTime interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); - }) + }); } }, getCurrentTimeNs: function (...args) { - console.warn("systemTime.getCurrentTimeNs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getCurrentTimeNs interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); - }) + }); } }, getRealActiveTime: function (...args) { - console.warn("systemTime.getRealActiveTime interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getRealActiveTime interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); - }) + }); } }, getRealActiveTimeNs: function (...args) { - console.warn("systemTime.getRealActiveTimeNs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getRealActiveTimeNs interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); - }) + }); } }, getRealTime: function (...args) { - console.warn("systemTime.getRealTime interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getRealTime interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); - }) + }); } }, getRealTimeNs: function (...args) { - console.warn("systemTime.getRealTimeNs interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getRealTimeNs interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramNumberMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramNumberMock); - }) + }); } }, setDate: function (...args) { @@ -91,7 +91,7 @@ export function mockSystemTime() { " Previewer may be different from that on a real device.") const len = args.length if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock) + args[len - 1].call(this, paramMock.businessErrorMock); } else { return new Promise((resolve, reject) => { resolve(); @@ -99,15 +99,15 @@ export function mockSystemTime() { } }, getDate: function (...args) { - console.warn("systemTime.getDate interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getDate interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramObjectMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramObjectMock); - }) + }); } }, setTimezone: function (...args) { @@ -123,15 +123,15 @@ export function mockSystemTime() { } }, getTimeZone: function (...args) { - console.warn("systemTime.getTimeZone interface mocked in the Previewer. How this interface works on the" + - " Previewer may be different from that on a real device.") - const len = args.length + console.warn('systemTime.getTimeZone interface mocked in the Previewer. How this interface works on the' + + 'Previewer may be different from that on a real device.'); + const len = args.length; if (typeof args[len - 1] === 'function') { - args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock) + args[len - 1].call(this, paramMock.businessErrorMock, paramMock.paramStringMock); } else { return new Promise((resolve, reject) => { resolve(paramMock.paramStringMock); - }) + }); } } } -- Gitee