未验证 提交 4d673aee 编写于 作者: O openharmony_ci 提交者: Gitee

!13848 翻译完成 13487

Merge pull request !13848 from ester.zhou/TR-13487
...@@ -18,14 +18,14 @@ After change: ...@@ -18,14 +18,14 @@ After change:
| Module | Class | Method/Attribute/Enumeration/Constant | Change Type| | Module | Class | Method/Attribute/Enumeration/Constant | Change Type|
| ----------------- | ----------- | ------------------------------------------------------------ | -------- | | ----------------- | ----------- | ------------------------------------------------------------ | -------- |
| @ohos.systemTimer | systemTimer | function createTimer(options: TimerOptions, callback: AsyncCallback<number>): void | Changed | | @ohos.systemTimer | systemTimer | function createTimer(options: TimerOptions, callback: AsyncCallback\<number>): void | Changed |
| @ohos.systemTimer | systemTimer | function createTimer(options: TimerOptions): Promise<number> | Changed | | @ohos.systemTimer | systemTimer | function createTimer(options: TimerOptions): Promise\<number> | Changed |
| @ohos.systemTimer | systemTimer | function startTimer(timer: number, triggerTime: number, callback: AsyncCallback<void>): void | Changed | | @ohos.systemTimer | systemTimer | function startTimer(timer: number, triggerTime: number, callback: AsyncCallback\<void>): void | Changed |
| @ohos.systemTimer | systemTimer | function startTimer(timer: number, triggerTime: number): Promise<void> | Changed | | @ohos.systemTimer | systemTimer | function startTimer(timer: number, triggerTime: number): Promise\<void> | Changed |
| @ohos.systemTimer | systemTimer | function stopTimer(timer: number, callback: AsyncCallback<void>): void | Changed | | @ohos.systemTimer | systemTimer | function stopTimer(timer: number, callback: AsyncCallback\<void>): void | Changed |
| @ohos.systemTimer | systemTimer | function stopTimer(timer: number): Promise<void> | Changed | | @ohos.systemTimer | systemTimer | function stopTimer(timer: number): Promise\<void> | Changed |
| @ohos.systemTimer | systemTimer | function destroyTimer(timer: number, callback: AsyncCallback<void>): void | Changed | | @ohos.systemTimer | systemTimer | function destroyTimer(timer: number, callback: AsyncCallback\<void>): void | Changed |
| @ohos.systemTimer | systemTimer | function destroyTimer(timer: number): Promise<void> | Changed | | @ohos.systemTimer | systemTimer | function destroyTimer(timer: number): Promise\<void> | Changed |
**Adaptation Guide** **Adaptation Guide**
...@@ -34,7 +34,7 @@ Refer to the code below to capture errors when **systemTimer** APIs are called i ...@@ -34,7 +34,7 @@ Refer to the code below to capture errors when **systemTimer** APIs are called i
createTimer callback mode: createTimer callback mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -44,15 +44,16 @@ export default { ...@@ -44,15 +44,16 @@ export default {
repeat: false repeat: false
}; };
try { try {
systemTimer.createTimer(options, (error, data) => { systemTimer.createTimer(options, (error, timerId) => {
if (error) { if (error) {
// Capture the permission denial error. // Capture the permission denial error.
console.info(`Failed to create timer. message:${error.message}, code:${error.code}`); console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
} }
console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}); });
} catch(e) { } catch(e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to create timer. message:${e.message}, code:${e.code}`); console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
...@@ -60,7 +61,7 @@ export default { ...@@ -60,7 +61,7 @@ export default {
createTimer promise mode: createTimer promise mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -70,15 +71,15 @@ export default { ...@@ -70,15 +71,15 @@ export default {
repeat: false repeat: false
}; };
try { try {
systemTimer.createTimer(options).then((data) => { systemTimer.createTimer(options).then((timerId) => {
console.info(`Succeeded in creating timer. Data:` + data); console.info(`Succeeded in creating timer. timerId: ${timerId}`);
}).catch((error) => { }).catch((error) => {
// Capture the permission denial error. // Capture the permission denial error.
console.info(`Failed to create timer. message:${error.message}, code:${error.code}`); console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
}); });
} catch(e) { } catch(e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to create timer. message:${e.message}, code:${e.code}`); console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
...@@ -86,7 +87,7 @@ export default { ...@@ -86,7 +87,7 @@ export default {
startTimer callback mode: startTimer callback mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -102,12 +103,12 @@ export default { ...@@ -102,12 +103,12 @@ export default {
systemTimer.startTimer(timerId, triggerTime, (error) => { systemTimer.startTimer(timerId, triggerTime, (error) => {
if (error) { if (error) {
// Capture the permission denial error. // Capture the permission denial error.
console.error(`Failed to start timer. message:${error.message}, code:${error.code}`); console.error(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
} }
}); });
} catch (e) { } catch (e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to start timer. message:${e.message}, code:${e.code}`); console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
...@@ -115,7 +116,7 @@ export default { ...@@ -115,7 +116,7 @@ export default {
startTimer promise mode: startTimer promise mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -132,11 +133,11 @@ export default { ...@@ -132,11 +133,11 @@ export default {
console.log(`Succeeded in startting timer. Data:` + data); console.log(`Succeeded in startting timer. Data:` + data);
}).catch((error) => { }).catch((error) => {
// Capture the permission denial error. // Capture the permission denial error.
console.info(`Failed to start timer. message:${error.message}, code:${error.code}`); console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
}); });
} catch (e) { } catch (e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to start timer. message:${e.message}, code:${e.code}`); console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
...@@ -144,7 +145,7 @@ export default { ...@@ -144,7 +145,7 @@ export default {
stopTimer callback mode: stopTimer callback mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -161,20 +162,20 @@ export default { ...@@ -161,20 +162,20 @@ export default {
systemTimer.stopTimer(timerId, triggerTime, (error) => { systemTimer.stopTimer(timerId, triggerTime, (error) => {
if (error) { if (error) {
// Capture the permission denial error. // Capture the permission denial error.
console.error(`Failed to stop timer. message:${error.message}, code:${error.code}`); console.error(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
} }
}); });
} catch (e) { } catch (e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to stop timer. message:${e.message}, code:${e.code}`); console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }git
``` ```
stopTimer promise mode: stopTimer promise mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -192,11 +193,11 @@ export default { ...@@ -192,11 +193,11 @@ export default {
console.log(`Succeeded in stop timer. Data:` + data); console.log(`Succeeded in stop timer. Data:` + data);
}).catch((error) => { }).catch((error) => {
// Capture the permission denial error. // Capture the permission denial error.
console.info(`Failed to stop timer. message:${error.message}, code:${error.code}`); console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
}); });
} catch (e) { } catch (e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to stop timer. message:${e.message}, code:${e.code}`); console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
...@@ -204,7 +205,7 @@ export default { ...@@ -204,7 +205,7 @@ export default {
destroyTimer callback mode: destroyTimer callback mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -222,12 +223,12 @@ export default { ...@@ -222,12 +223,12 @@ export default {
systemTimer.destroyTimer(timerId, triggerTime, (error) => { systemTimer.destroyTimer(timerId, triggerTime, (error) => {
if (error) { if (error) {
// Capture the permission denial error. // Capture the permission denial error.
console.error(`Failed to destroy timer. message:${error.message}, code:${error.code}`); console.error(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
} }
}); });
} catch (e) { } catch (e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to destroy timer. message:${e.message}, code:${e.code}`); console.info(`Failed to destroy timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
...@@ -235,7 +236,7 @@ export default { ...@@ -235,7 +236,7 @@ export default {
destroyTimer promise mode: destroyTimer promise mode:
**Example**: **Example**
```js ```js
export default { export default {
...@@ -254,12 +255,82 @@ export default { ...@@ -254,12 +255,82 @@ export default {
console.log(`Succeeded in destroy timer. Data:` + data); console.log(`Succeeded in destroy timer. Data:` + data);
}).catch((error) => { }).catch((error) => {
// Capture the permission denial error. // Capture the permission denial error.
console.info(`Failed to destroy timer. message:${error.message}, code:${error.code}`); console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
}); });
} catch (e) { } catch (e) {
// Capture the parameter verification error. // Capture the parameter verification error.
console.info(`Failed to destroy timer. message:${e.message}, code:${e.code}`); console.info(`Failed to destroy timer. message: ${e.message}, code: ${e.code}`);
} }
} }
} }
``` ```
## cl.time.2 API Error Change
Errors thrown by timer APIs of the time subsystem: **201** (permission denied), **202** (non-system application), and **401** (invalid parameters).
**Change Impacts**
Applications developed based on earlier versions can still use the APIs. When new APIs are used, errors must be captured and processed.
**Key API/Component Changes**
Before change:
- The API throws an error message with error code **-1**.
After change:
- The API throws an error message with an error code. Error code **201** indicates that the permission is denied, error code **202** indicates that the application is not a system application, and error code **401** indicates that the parameters are invalid.
Deprecated APIs can be replaced with new ones with same names.
| Original API | New API |
| ---------------- | -------------------- |
| @ohos.systemTime | @ohos.systemDateTime |
**Adaptation Guide**
Refer to the code below to capture errors when **systemTime** APIs are called in applications. In the examples, the **setTime** API is invoked.
In callback mode:
**Example**
```js
import systemDateTime from @ohos.systemDateTime
// Set the system time to 2021-01-20 02:36:25.
let time = 1611081385000;
try {
systemDateTime.setTime(time, (error) => {
// Capture permission denial and non-system-application errors.
if (error) {
console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
return;
}
console.info(`Succeeded in setting time.`);
})
} catch(e) {
// Capture the parameter verification error.
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
}
```
In promise mode:
**Example**
```js
import systemDateTime from @ohos.systemDateTime
// Set the system time to 2021-01-20 02:36:25.
let time = 1611081385000;
try {
systemDateTime.setTime(time).then(() => {
console.info(`Succeeded in setting time.`);
}).catch((error) => {
// Capture permission denial and non-system-application errors.
console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
});
} catch(e) {
// Capture the parameter verification error.
console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
}
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册