1e41f4b71Sopenharmony_ci# Time Subsystem ChangeLog
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci## cl.time.1 API Error Change
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ciErrors thrown by timer APIs of the time subsystem: **202** (non-system application) and **401** (invalid parameters).
6e41f4b71Sopenharmony_ci
7e41f4b71Sopenharmony_ci**Change Impacts**
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ciThe API change is forward compatible. Applications developed based on earlier versions can still use the APIs, and corresponding error handling is added. The original functions are not affected.
10e41f4b71Sopenharmony_ci
11e41f4b71Sopenharmony_ci**Key API/Component Changes**
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ciBefore change:
14e41f4b71Sopenharmony_ci  - The API throws an error message without an error code.
15e41f4b71Sopenharmony_ci
16e41f4b71Sopenharmony_ciAfter change:
17e41f4b71Sopenharmony_ci  - The API throws an error message with an error code. Error code **202** indicates that the application is not a system application, and error code **401** indicates that the parameters are invalid.
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci    | Module           | Class       | Method/Attribute/Enumeration/Constant                                         | Change Type|
20e41f4b71Sopenharmony_ci    | ----------------- | ----------- | ------------------------------------------------------------ | -------- |
21e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function createTimer(options: TimerOptions, callback: AsyncCallback\<number>): void | Changed    |
22e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function createTimer(options: TimerOptions): Promise\<number> | Changed    |
23e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function startTimer(timer: number, triggerTime: number, callback: AsyncCallback\<void>): void | Changed    |
24e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function startTimer(timer: number, triggerTime: number): Promise\<void> | Changed    |
25e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function stopTimer(timer: number, callback: AsyncCallback\<void>): void | Changed    |
26e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function stopTimer(timer: number): Promise\<void>            | Changed    |
27e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function destroyTimer(timer: number, callback: AsyncCallback\<void>): void | Changed    |
28e41f4b71Sopenharmony_ci    | @ohos.systemTimer | systemTimer | function destroyTimer(timer: number): Promise\<void>         | Changed    |
29e41f4b71Sopenharmony_ci
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Adaptation Guide**
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ciRefer to the code below to capture errors when **systemTimer** APIs are called in applications.
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_cicreateTimer callback mode:
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci**Example**
38e41f4b71Sopenharmony_ci
39e41f4b71Sopenharmony_ci```js
40e41f4b71Sopenharmony_ciexport default {
41e41f4b71Sopenharmony_ci  systemTimer () {
42e41f4b71Sopenharmony_ci    let options = {
43e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
44e41f4b71Sopenharmony_ci      repeat: false
45e41f4b71Sopenharmony_ci    };
46e41f4b71Sopenharmony_ci    try {
47e41f4b71Sopenharmony_ci      systemTimer.createTimer(options, (error, timerId) => {
48e41f4b71Sopenharmony_ci        if (error) {
49e41f4b71Sopenharmony_ci          // Capture the permission denial error.
50e41f4b71Sopenharmony_ci          console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
51e41f4b71Sopenharmony_ci        }
52e41f4b71Sopenharmony_ci        console.info(`Succeeded in creating timer. timerId: ${timerId}`);
53e41f4b71Sopenharmony_ci      });
54e41f4b71Sopenharmony_ci    } catch(e) {
55e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
56e41f4b71Sopenharmony_ci      console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
57e41f4b71Sopenharmony_ci    }
58e41f4b71Sopenharmony_ci  }
59e41f4b71Sopenharmony_ci}
60e41f4b71Sopenharmony_ci```
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_cicreateTimer promise mode:
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci**Example**
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci```js
67e41f4b71Sopenharmony_ciexport default {
68e41f4b71Sopenharmony_ci  systemTimer () {
69e41f4b71Sopenharmony_ci    let options = {
70e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
71e41f4b71Sopenharmony_ci      repeat: false
72e41f4b71Sopenharmony_ci    };
73e41f4b71Sopenharmony_ci    try {
74e41f4b71Sopenharmony_ci      systemTimer.createTimer(options).then((timerId) => {
75e41f4b71Sopenharmony_ci        console.info(`Succeeded in creating timer. timerId: ${timerId}`);
76e41f4b71Sopenharmony_ci      }).catch((error) => {
77e41f4b71Sopenharmony_ci        // Capture the permission denial error.
78e41f4b71Sopenharmony_ci        console.info(`Failed to create timer. message: ${error.message}, code: ${error.code}`);
79e41f4b71Sopenharmony_ci      });
80e41f4b71Sopenharmony_ci    } catch(e) {
81e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
82e41f4b71Sopenharmony_ci      console.info(`Failed to create timer. message: ${e.message}, code: ${e.code}`);
83e41f4b71Sopenharmony_ci    }
84e41f4b71Sopenharmony_ci  }
85e41f4b71Sopenharmony_ci}
86e41f4b71Sopenharmony_ci```
87e41f4b71Sopenharmony_ci
88e41f4b71Sopenharmony_cistartTimer callback mode:
89e41f4b71Sopenharmony_ci
90e41f4b71Sopenharmony_ci**Example**
91e41f4b71Sopenharmony_ci
92e41f4b71Sopenharmony_ci```js
93e41f4b71Sopenharmony_ciexport default {
94e41f4b71Sopenharmony_ci  async systemTimer () {
95e41f4b71Sopenharmony_ci    let options = {
96e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
97e41f4b71Sopenharmony_ci      repeat:false
98e41f4b71Sopenharmony_ci    }
99e41f4b71Sopenharmony_ci    let timerId = await systemTimer.createTimer(options);
100e41f4b71Sopenharmony_ci    let triggerTime = new Date().getTime();
101e41f4b71Sopenharmony_ci    triggerTime += 3000;
102e41f4b71Sopenharmony_ci    try {
103e41f4b71Sopenharmony_ci      systemTimer.startTimer(timerId, triggerTime, (error) => {
104e41f4b71Sopenharmony_ci        if (error) {
105e41f4b71Sopenharmony_ci          // Capture the permission denial error.
106e41f4b71Sopenharmony_ci          console.error(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
107e41f4b71Sopenharmony_ci        }
108e41f4b71Sopenharmony_ci        });
109e41f4b71Sopenharmony_ci    } catch (e) {
110e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
111e41f4b71Sopenharmony_ci      console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
112e41f4b71Sopenharmony_ci    }
113e41f4b71Sopenharmony_ci  }
114e41f4b71Sopenharmony_ci}
115e41f4b71Sopenharmony_ci```
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_cistartTimer promise mode:
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci**Example**
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci```js
122e41f4b71Sopenharmony_ciexport default {
123e41f4b71Sopenharmony_ci  async systemTimer (){
124e41f4b71Sopenharmony_ci    let options = {
125e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
126e41f4b71Sopenharmony_ci      repeat:false
127e41f4b71Sopenharmony_ci    }
128e41f4b71Sopenharmony_ci    let timerId = await systemTimer.createTimer(options);
129e41f4b71Sopenharmony_ci    let triggerTime = new Date().getTime();
130e41f4b71Sopenharmony_ci    triggerTime += 3000;
131e41f4b71Sopenharmony_ci    try {
132e41f4b71Sopenharmony_ci      systemTimer.startTimer(timerId, triggerTime).then((data) => {
133e41f4b71Sopenharmony_ci        console.log(`Succeeded in startting timer. Data:` + data);
134e41f4b71Sopenharmony_ci      }).catch((error) => {
135e41f4b71Sopenharmony_ci        // Capture the permission denial error.
136e41f4b71Sopenharmony_ci        console.info(`Failed to start timer. message: ${error.message}, code: ${error.code}`);
137e41f4b71Sopenharmony_ci      });
138e41f4b71Sopenharmony_ci    } catch (e) {
139e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
140e41f4b71Sopenharmony_ci      console.info(`Failed to start timer. message: ${e.message}, code: ${e.code}`);
141e41f4b71Sopenharmony_ci    }
142e41f4b71Sopenharmony_ci  }
143e41f4b71Sopenharmony_ci}
144e41f4b71Sopenharmony_ci```
145e41f4b71Sopenharmony_ci
146e41f4b71Sopenharmony_cistopTimer callback mode:
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci**Example**
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci```js
151e41f4b71Sopenharmony_ciexport default {
152e41f4b71Sopenharmony_ci  async systemTimer () {
153e41f4b71Sopenharmony_ci    let options = {
154e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
155e41f4b71Sopenharmony_ci      repeat:false
156e41f4b71Sopenharmony_ci    }
157e41f4b71Sopenharmony_ci    let timerId = await systemTimer.createTimer(options);
158e41f4b71Sopenharmony_ci    let triggerTime = new Date().getTime();
159e41f4b71Sopenharmony_ci    triggerTime += 3000;
160e41f4b71Sopenharmony_ci    systemTimer.startTimer(timerId, triggerTime);
161e41f4b71Sopenharmony_ci    try {
162e41f4b71Sopenharmony_ci      systemTimer.stopTimer(timerId, triggerTime, (error) => {
163e41f4b71Sopenharmony_ci        if (error) {
164e41f4b71Sopenharmony_ci          // Capture the permission denial error.
165e41f4b71Sopenharmony_ci          console.error(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
166e41f4b71Sopenharmony_ci        }
167e41f4b71Sopenharmony_ci        });
168e41f4b71Sopenharmony_ci    } catch (e) {
169e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
170e41f4b71Sopenharmony_ci      console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
171e41f4b71Sopenharmony_ci    }
172e41f4b71Sopenharmony_ci  }
173e41f4b71Sopenharmony_ci}git 
174e41f4b71Sopenharmony_ci```
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_cistopTimer promise mode:
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Example**
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci```js
181e41f4b71Sopenharmony_ciexport default {
182e41f4b71Sopenharmony_ci  async systemTimer (){
183e41f4b71Sopenharmony_ci    let options = {
184e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
185e41f4b71Sopenharmony_ci      repeat:false
186e41f4b71Sopenharmony_ci    }
187e41f4b71Sopenharmony_ci    let timerId = await systemTimer.createTimer(options);
188e41f4b71Sopenharmony_ci    let triggerTime = new Date().getTime();
189e41f4b71Sopenharmony_ci    triggerTime += 3000;
190e41f4b71Sopenharmony_ci    systemTimer.startTimer(timerId, triggerTime);
191e41f4b71Sopenharmony_ci    try {
192e41f4b71Sopenharmony_ci      systemTimer.stopTimer(timerId, triggerTime).then((data) => {
193e41f4b71Sopenharmony_ci        console.log(`Succeeded in stop timer. Data:` + data);
194e41f4b71Sopenharmony_ci      }).catch((error) => {
195e41f4b71Sopenharmony_ci        // Capture the permission denial error.
196e41f4b71Sopenharmony_ci        console.info(`Failed to stop timer. message: ${error.message}, code: ${error.code}`);
197e41f4b71Sopenharmony_ci      });
198e41f4b71Sopenharmony_ci    } catch (e) {
199e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
200e41f4b71Sopenharmony_ci      console.info(`Failed to stop timer. message: ${e.message}, code: ${e.code}`);
201e41f4b71Sopenharmony_ci    }
202e41f4b71Sopenharmony_ci  }
203e41f4b71Sopenharmony_ci}
204e41f4b71Sopenharmony_ci```
205e41f4b71Sopenharmony_ci
206e41f4b71Sopenharmony_cidestroyTimer callback mode:
207e41f4b71Sopenharmony_ci
208e41f4b71Sopenharmony_ci**Example**
209e41f4b71Sopenharmony_ci
210e41f4b71Sopenharmony_ci```js
211e41f4b71Sopenharmony_ciexport default {
212e41f4b71Sopenharmony_ci  async systemTimer () {
213e41f4b71Sopenharmony_ci    let options = {
214e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
215e41f4b71Sopenharmony_ci      repeat:false
216e41f4b71Sopenharmony_ci    }
217e41f4b71Sopenharmony_ci    let timerId = await systemTimer.createTimer(options);
218e41f4b71Sopenharmony_ci    let triggerTime = new Date().getTime();
219e41f4b71Sopenharmony_ci    triggerTime += 3000;
220e41f4b71Sopenharmony_ci    systemTimer.startTimer(timerId, triggerTime);
221e41f4b71Sopenharmony_ci    systemTimer.stopTimer(timerId);
222e41f4b71Sopenharmony_ci    try {
223e41f4b71Sopenharmony_ci      systemTimer.destroyTimer(timerId, triggerTime, (error) => {
224e41f4b71Sopenharmony_ci        if (error) {
225e41f4b71Sopenharmony_ci          // Capture the permission denial error.
226e41f4b71Sopenharmony_ci          console.error(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
227e41f4b71Sopenharmony_ci        }
228e41f4b71Sopenharmony_ci        });
229e41f4b71Sopenharmony_ci    } catch (e) {
230e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
231e41f4b71Sopenharmony_ci      console.info(`Failed to destroy timer. message: ${e.message}, code: ${e.code}`);
232e41f4b71Sopenharmony_ci    }
233e41f4b71Sopenharmony_ci  }
234e41f4b71Sopenharmony_ci}
235e41f4b71Sopenharmony_ci```
236e41f4b71Sopenharmony_ci
237e41f4b71Sopenharmony_cidestroyTimer promise mode:
238e41f4b71Sopenharmony_ci
239e41f4b71Sopenharmony_ci**Example**
240e41f4b71Sopenharmony_ci
241e41f4b71Sopenharmony_ci```js
242e41f4b71Sopenharmony_ciexport default {
243e41f4b71Sopenharmony_ci  async systemTimer (){
244e41f4b71Sopenharmony_ci    let options = {
245e41f4b71Sopenharmony_ci      type: systemTimer.TIMER_TYPE_REALTIME,
246e41f4b71Sopenharmony_ci      repeat:false
247e41f4b71Sopenharmony_ci    }
248e41f4b71Sopenharmony_ci    let timerId = await systemTimer.createTimer(options);
249e41f4b71Sopenharmony_ci    let triggerTime = new Date().getTime();
250e41f4b71Sopenharmony_ci    triggerTime += 3000;
251e41f4b71Sopenharmony_ci    systemTimer.startTimer(timerId, triggerTime);
252e41f4b71Sopenharmony_ci    systemTimer.stopTimer(timerId);
253e41f4b71Sopenharmony_ci    try {
254e41f4b71Sopenharmony_ci      systemTimer.destroyTimer(timerId, triggerTime).then((data) => {
255e41f4b71Sopenharmony_ci        console.log(`Succeeded in destroy timer. Data:` + data);
256e41f4b71Sopenharmony_ci      }).catch((error) => {
257e41f4b71Sopenharmony_ci        // Capture the permission denial error.
258e41f4b71Sopenharmony_ci        console.info(`Failed to destroy timer. message: ${error.message}, code: ${error.code}`);
259e41f4b71Sopenharmony_ci      });
260e41f4b71Sopenharmony_ci    } catch (e) {
261e41f4b71Sopenharmony_ci      // Capture the parameter verification error.
262e41f4b71Sopenharmony_ci      console.info(`Failed to destroy timer. message: ${e.message}, code: ${e.code}`);
263e41f4b71Sopenharmony_ci    }
264e41f4b71Sopenharmony_ci  }
265e41f4b71Sopenharmony_ci}
266e41f4b71Sopenharmony_ci```
267e41f4b71Sopenharmony_ci
268e41f4b71Sopenharmony_ci## cl.time.2 API Error Change
269e41f4b71Sopenharmony_ci
270e41f4b71Sopenharmony_ciErrors thrown by timer APIs of the time subsystem: **201** (permission denied), **202** (non-system application), and **401** (invalid parameters).
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci**Change Impacts**
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ciApplications developed based on earlier versions can still use the APIs. When new APIs are used, errors must be captured and processed.
275e41f4b71Sopenharmony_ci
276e41f4b71Sopenharmony_ci**Key API/Component Changes**
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ciBefore change:
279e41f4b71Sopenharmony_ci  - The API throws an error message with error code **-1**.
280e41f4b71Sopenharmony_ci
281e41f4b71Sopenharmony_ciAfter change:
282e41f4b71Sopenharmony_ci  - 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.
283e41f4b71Sopenharmony_ci
284e41f4b71Sopenharmony_ciDeprecated APIs can be replaced with new ones with same names.
285e41f4b71Sopenharmony_ci
286e41f4b71Sopenharmony_ci| Original API          | New API              |
287e41f4b71Sopenharmony_ci| ---------------- | -------------------- |
288e41f4b71Sopenharmony_ci| @ohos.systemTime | @ohos.systemDateTime |
289e41f4b71Sopenharmony_ci
290e41f4b71Sopenharmony_ci**Adaptation Guide**
291e41f4b71Sopenharmony_ci
292e41f4b71Sopenharmony_ciRefer to the code below to capture errors when **systemTime** APIs are called in applications. In the examples, the **setTime** API is invoked.
293e41f4b71Sopenharmony_ci
294e41f4b71Sopenharmony_ciIn callback mode:
295e41f4b71Sopenharmony_ci
296e41f4b71Sopenharmony_ci**Example**
297e41f4b71Sopenharmony_ci
298e41f4b71Sopenharmony_ci```js
299e41f4b71Sopenharmony_ciimport systemDateTime from @ohos.systemDateTime
300e41f4b71Sopenharmony_ci// Set the system time to 2021-01-20 02:36:25.
301e41f4b71Sopenharmony_cilet time = 1611081385000;
302e41f4b71Sopenharmony_citry {
303e41f4b71Sopenharmony_ci  systemDateTime.setTime(time, (error) => {
304e41f4b71Sopenharmony_ci    // Capture permission denial and non-system-application errors.
305e41f4b71Sopenharmony_ci    if (error) {
306e41f4b71Sopenharmony_ci      console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
307e41f4b71Sopenharmony_ci      return;
308e41f4b71Sopenharmony_ci    }
309e41f4b71Sopenharmony_ci    console.info(`Succeeded in setting time.`);
310e41f4b71Sopenharmony_ci  })
311e41f4b71Sopenharmony_ci} catch(e) {
312e41f4b71Sopenharmony_ci  // Capture the parameter verification error.
313e41f4b71Sopenharmony_ci  console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
314e41f4b71Sopenharmony_ci}
315e41f4b71Sopenharmony_ci```
316e41f4b71Sopenharmony_ci
317e41f4b71Sopenharmony_ciIn promise mode:
318e41f4b71Sopenharmony_ci
319e41f4b71Sopenharmony_ci**Example**
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci```js
322e41f4b71Sopenharmony_ciimport systemDateTime from @ohos.systemDateTime
323e41f4b71Sopenharmony_ci// Set the system time to 2021-01-20 02:36:25.
324e41f4b71Sopenharmony_cilet time = 1611081385000;
325e41f4b71Sopenharmony_citry {
326e41f4b71Sopenharmony_ci  systemDateTime.setTime(time).then(() => {
327e41f4b71Sopenharmony_ci    console.info(`Succeeded in setting time.`);
328e41f4b71Sopenharmony_ci  }).catch((error) => {
329e41f4b71Sopenharmony_ci    // Capture permission denial and non-system-application errors.
330e41f4b71Sopenharmony_ci    console.info(`Failed to setting time. message: ${error.message}, code: ${error.code}`);
331e41f4b71Sopenharmony_ci  });
332e41f4b71Sopenharmony_ci} catch(e) {
333e41f4b71Sopenharmony_ci   // Capture the parameter verification error.
334e41f4b71Sopenharmony_ci  console.info(`Failed to set time. message: ${e.message}, code: ${e.code}`);
335e41f4b71Sopenharmony_ci}
336e41f4b71Sopenharmony_ci```
337