• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.calendarManager (Calendar Manager)
2
3The **calendarManager** module provides APIs for calendar and event management, including those for creating, deleting, modifying, and querying calendars and events. A [CalendarManager](#calendarmanager) object is used to manage [Calendar](#calendar) objects. A [Calendar](#calendar) object contains the account information [CalendarAccount](#calendaraccount) and configuration information [CalendarConfig](#calendarconfig). Calendars and events are in the one-to-many relationship. That is, a calendar can have multiple events, but an event belongs to only one calendar.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 10. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9
10## Modules to Import
11
12```typescript
13import calendarManager from '@ohos.calendarManager';
14```
15
16## calendarManager.getCalendarManager
17
18getCalendarManager(context : Context): CalendarManager
19
20Obtains a **CalendarManager** object based on the context.
21
22**System capability**: SystemCapability.Applications.CalendarData
23
24**Model restriction**: This API can be used only in the stage model.
25
26**Parameters**
27
28| Name  | Type                       | Mandatory| Description                                                        |
29| -------- | --------------------------- | ---- | ------------------------------------------------------------ |
30| context  | Context                     | Yes  | Application context. For details about the application context of the stage model, see [Context](js-apis-inner-application-context.md).|
31
32**Return value**
33
34| Type                          | Description                                 |
35| ------------------------------ | ------------------------------------- |
36| CalendarManager | **CalendarManager** object obtained.|
37
38**Example**
39
40```typescript
41// Obtain the context.
42// Obtain a calendarManager object.
43// In the following code, class EntryAbility extends UIAbility and onWindowStageCreate are available in main/ets/entryability/EntryAbility.ets and ohosTest/ets/testability/TestAbility.ets files and can be directly used.
44// calendarMgr must be obtained in the main thread, not in the worker thread.
45// To call getCalendarManager successfully, make sure the ohos.permission.WRITE_CALENDAR and ohos.permission.READ_CALENDAR permissions have been obtained.
46import UIAbility from '@ohos.app.ability.UIAbility';
47import common from '@ohos.app.ability.common';
48import window from '@ohos.window';
49
50export let mContext : common.UIAbilityContext | null = null;
51export let calendarMgr : calendarManager.CalendarManager | null = null;
52class EntryAbility extends UIAbility {
53  onWindowStageCreate(windowStage: window.WindowStage){
54    mContext = this.context;
55    // Before calling this API, make sure the required permission has been obtained.
56    calendarMgr = calendarManager.getCalendarManager(mContext);
57  }
58}
59```
60
61## CalendarManager
62
63Before calling any of the following APIs, you must use [getCalendarManager()](#calendarmanagergetcalendarmanager) to obtain a **CalendarManager** object.
64
65
66### createCalendar
67
68createCalendar(calendarAccount: CalendarAccount, callback: AsyncCallback\<Calendar>): void
69
70Creates a **Calendar** object based on the calendar account information. This API uses an asynchronous callback to return the result.
71
72**Required permissions**: ohos.permission.WRITE_CALENDAR or ohos.permission.WRITE_WHOLE_CALENDAR
73
74**System capability**: SystemCapability.Applications.CalendarData
75
76**Parameters**
77
78| Name         | Type                                 | Mandatory| Description                              |
79| --------------- | ------------------------------------- | ---- | ---------------------------------- |
80| calendarAccount | [CalendarAccount](#calendaraccount)   | Yes  | Calendar account information.                    |
81| callback        | AsyncCallback\<[Calendar](#calendar)> | Yes  | Callback used to return the created **Calendar** object.|
82
83**Example**
84
85```typescript
86import { BusinessError } from '@ohos.base';
87import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
88
89let calendar: calendarManager.Calendar | undefined = undefined;
90const calendarAccount: calendarManager.CalendarAccount = {
91  name: 'CreateMyCalendarByCallBack',
92  type: calendarManager.CalendarType.LOCAL
93};
94try {
95  calendarMgr?.createCalendar(calendarAccount, (err: BusinessError, data: calendarManager.Calendar) => {
96    if (err) {
97      console.error(`Failed to create calendar, err -> ${JSON.stringify(err)}`);
98    } else {
99      console.info(`Succeeded in creating the calendar, data -> ${JSON.stringify(data)}`);
100      calendar = data;
101    }
102  });
103} catch (error) {
104  console.error(`Failed to create calendar: err->${JSON.stringify(error)}`);
105}
106```
107
108### createCalendar
109
110createCalendar(calendarAccount: CalendarAccount): Promise\<Calendar>
111
112Creates a **Calendar** object based on the calendar account information. This API uses a promise to return the result.
113
114**Required permissions**: ohos.permission.WRITE_CALENDAR or ohos.permission.WRITE_WHOLE_CALENDAR
115
116**System capability**: SystemCapability.Applications.CalendarData
117
118**Parameters**
119
120| Name         | Type                               | Mandatory| Description          |
121| --------------- | ----------------------------------- | ---- | -------------- |
122| calendarAccount | [CalendarAccount](#calendaraccount) | Yes  | Calendar account information.|
123
124**Return value**
125
126| Type                          | Description                                 |
127| ------------------------------ | ------------------------------------- |
128| Promise<[Calendar](#calendar)> | Promise used to return the created **Calendar** object.|
129
130**Example**
131
132```typescript
133import { BusinessError } from '@ohos.base';
134import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
135
136let calendar : calendarManager.Calendar | undefined = undefined;
137const calendarAccount: calendarManager.CalendarAccount = {
138  name: 'CreateMyCalendarByPromise',
139  type: calendarManager.CalendarType.LOCAL,
140  displayName : 'MyApplication'
141};
142calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => {
143  console.info(`Succeeded in creating the calendar data->${JSON.stringify(data)}`);
144  calendar = data;
145}).catch((error : BusinessError) => {
146  console.error(`Failed to create calendar: err->${JSON.stringify(error)}`);
147});
148```
149
150### deleteCalendar
151
152deleteCalendar(calendar: Calendar, callback: AsyncCallback\<void>): void
153
154Deletes a specified **Calendar** object. This API uses an asynchronous callback to return the result.
155
156**Required permissions**: ohos.permission.WRITE_CALENDAR or ohos.permission.WRITE_WHOLE_CALENDAR
157
158**System capability**: SystemCapability.Applications.CalendarData
159
160**Parameters**
161
162| Name  | Type                 | Mandatory| Description          |
163| -------- | --------------------- | ---- | -------------- |
164| calendar | [Calendar](#calendar) | Yes  | **Calendar** object to delete.|
165| callback | AsyncCallback\<void>  | Yes  | Asynchronous callback that returns no value.    |
166
167**Example**
168
169```typescript
170import { BusinessError } from '@ohos.base';
171import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
172
173const calendarAccount: calendarManager.CalendarAccount = {
174  name: 'DeleteMyCalendarByCallBack',
175  type: calendarManager.CalendarType.LOCAL
176};
177await calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => {
178  console.info(`Succeeded in creating the calendar, data -> ${JSON.stringify(data)}`);
179}).catch((error: BusinessError) => {
180  console.error(`Failed to create calendar, error -> ${JSON.stringify(error)}`);
181})
182calendarMgr?.getCalendar(calendarAccount, (err: BusinessError, data: calendarManager.Calendar) => {
183  if (err) {
184    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
185  } else {
186    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
187    calendarMgr?.deleteCalendar(data, (err1: BusinessError) => {
188      if (err1) {
189        console.error(`Failed to delete calendar, err -> ${JSON.stringify(err1)}`);
190      } else {
191        console.info("Succeeded in deleting the calendar");
192      }
193    });
194  }
195});
196```
197
198### deleteCalendar
199
200deleteCalendar(calendar: Calendar): Promise\<void>
201
202Deletes a specified **Calendar** object. This API uses a promise to return the result.
203
204**Required permissions**: ohos.permission.WRITE_CALENDAR or ohos.permission.WRITE_WHOLE_CALENDAR
205
206**System capability**: SystemCapability.Applications.CalendarData
207
208**Parameters**
209
210| Name  | Type                 | Mandatory| Description          |
211| -------- | --------------------- | ---- | -------------- |
212| calendar | [Calendar](#calendar) | Yes  | **Calendar** object to delete.|
213
214**Return value**
215
216| Type          | Description                     |
217| -------------- | ------------------------- |
218| Promise\<void> | Promise that returns no value.|
219
220**Example**
221
222```typescript
223import { BusinessError } from '@ohos.base';
224import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
225
226const calendarAccount: calendarManager.CalendarAccount = {
227  name: 'DeleteMyCalendarByPromise',
228  type: calendarManager.CalendarType.LOCAL
229};
230await calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => {
231  console.info(`Succeeded in creating the calendar, data -> ${JSON.stringify(data)}`);
232}).catch((error: BusinessError) => {
233  console.error(`Failed to create calendar, error -> ${JSON.stringify(error)}`);
234})
235calendarMgr?.getCalendar(calendarAccount).then((data: calendarManager.Calendar) => {
236  console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
237  calendarMgr?.deleteCalendar(data).then(() => {
238    console.info("Succeeded in deleting the calendar");
239  }).catch((err: BusinessError) => {
240    console.error(`Failed to delete calendar: err -> ${JSON.stringify(err)}`);
241  });
242}).catch((err: BusinessError) => {
243  console.error(`Failed to get calendar: err -> ${JSON.stringify(err)}`);
244});
245```
246
247### getCalendar
248
249getCalendar(callback: AsyncCallback\<Calendar>): void
250
251Obtains the default **Calendar** object, which is created when the data storage runs for the first time. This API uses an asynchronous callback to return the result. You can call this API instead of [createCalendar()](#createcalendar) to use the default calendar for a new event.
252
253**Required permissions**: ohos.permission.READ_CALENDAR or ohos.permission.READ_WHOLE_CALENDAR
254
255**System capability**: SystemCapability.Applications.CalendarData
256
257**Parameters**
258
259| Name  | Type                                | Mandatory| Description                                |
260| -------- | ------------------------------------ | ---- | ------------------------------------ |
261| callback | AsyncCallback<[Calendar](#calendar)> | Yes  | Callback used to return the obtained **Calendar** object.|
262
263**Example**
264
265```typescript
266import { BusinessError } from '@ohos.base';
267import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
268
269let calendar : calendarManager.Calendar | undefined = undefined;
270calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
271  if (err) {
272    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
273  } else {
274    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
275    calendar = data;
276  }
277});
278```
279
280### getCalendar
281
282getCalendar(calendarAccount: CalendarAccount, callback: AsyncCallback\<Calendar>): void
283
284Obtains a specified **Calendar** object. This API uses an asynchronous callback to return the result.
285
286**Required permissions**: ohos.permission.READ_CALENDAR or ohos.permission.READ_WHOLE_CALENDAR
287
288**System capability**: SystemCapability.Applications.CalendarData
289
290**Parameters**
291
292| Name         | Type                                | Mandatory| Description                                |
293| --------------- | ------------------------------------ | ---- | ------------------------------------ |
294| calendarAccount | [CalendarAccount](#calendaraccount)  | Yes  | Calendar account information.                      |
295| callback        | AsyncCallback<[Calendar](#calendar)> | Yes  | Callback used to return the obtained **Calendar** object.|
296
297**Example**
298
299```typescript
300import { BusinessError } from '@ohos.base';
301import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
302
303let calendar : calendarManager.Calendar | undefined = undefined;
304const calendarAccount: calendarManager.CalendarAccount = {
305  name: 'MyCalendar',
306  type: calendarManager.CalendarType.LOCAL
307};
308await calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => {
309  console.info(`Succeeded in creating the calendar, data -> ${JSON.stringify(data)}`);
310}).catch((error: BusinessError) => {
311  console.error(`Failed to create calendar, error -> ${JSON.stringify(error)}`);
312})
313calendarMgr?.getCalendar(calendarAccount, (err: BusinessError, data: calendarManager.Calendar) => {
314  if (err) {
315    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
316  } else {
317    console.info(`Succeeded in getting the calendar data -> ${JSON.stringify(data)}`);
318    calendar = data;
319  }
320});
321```
322
323### getCalendar
324
325getCalendar(calendarAccount?: CalendarAccount): Promise\<Calendar>
326
327Obtains the default **Calendar** object or a specified **Calendar** object. This API uses a promise to return the result.
328
329**Required permissions**: ohos.permission.READ_CALENDAR or ohos.permission.READ_WHOLE_CALENDAR
330
331**System capability**: SystemCapability.Applications.CalendarData
332
333**Parameters**
334
335| Name         | Type                               | Mandatory| Description                                                        |
336| --------------- | ----------------------------------- | ---- | ------------------------------------------------------------ |
337| calendarAccount | [CalendarAccount](#calendaraccount) | No  | Calendar account information, which is used to obtain a specified **Calendar** object. If this parameter is not set, the default **Calendar** object is obtained.|
338
339**Return value**
340
341| Type                          | Description                                   |
342| ------------------------------ | --------------------------------------- |
343| Promise<[Calendar](#calendar)> | Promise used to return the obtained **Calendar** object.|
344
345**Example**
346
347```typescript
348import { BusinessError } from '@ohos.base';
349import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
350
351let calendar : calendarManager.Calendar | undefined = undefined;
352calendarMgr?.getCalendar().then((data: calendarManager.Calendar) => {
353  console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
354  calendar = data;
355}).catch((err: BusinessError) => {
356  console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
357});
358```
359
360### getAllCalendars
361
362getAllCalendars(callback: AsyncCallback\<Calendar[]>): void
363
364Obtains the created and default **Calendar** objects of the current application. This API uses an asynchronous callback to return the result.
365
366**Required permissions**: ohos.permission.READ_CALENDAR or ohos.permission.READ_WHOLE_CALENDAR
367
368**System capability**: SystemCapability.Applications.CalendarData
369
370**Parameters**
371
372| Name  | Type                                  | Mandatory| Description                                     |
373| -------- | -------------------------------------- | ---- | ----------------------------------------- |
374| callback | AsyncCallback<[Calendar](#calendar)[]> | Yes  | Callback used to return an array of obtained **Calendar** objects.|
375
376**Example**
377
378```typescript
379import { BusinessError } from '@ohos.base';
380import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
381
382calendarMgr?.getAllCalendars((err: BusinessError, data: calendarManager.Calendar[]) => {
383  if (err) {
384    console.error(`Failed to get all calendars, err -> ${JSON.stringify(err)}`);
385  } else {
386    console.info(`Succeeded in getting all calendars, data -> ${JSON.stringify(data)}`);
387    data.forEach((calendar) => {
388      const account = calendar.getAccount();
389      console.info(`account -> ${JSON.stringify(account)}`);
390    })
391  }
392});
393```
394
395### getAllCalendars
396
397getAllCalendars(): Promise\<Calendar[]>
398
399Obtains the created and default **Calendar** objects of the current application. This API uses a promise to return the result.
400
401**Required permissions**: ohos.permission.READ_CALENDAR or ohos.permission.WRITE_WHOLE_CALENDAR
402
403**System capability**: SystemCapability.Applications.CalendarData
404
405**Return value**
406
407| Type                            | Description                                       |
408| -------------------------------- | ------------------------------------------- |
409| Promise<[Calendar](#calendar)[]> | Promise used to return an array of obtained **Calendar** objects.|
410
411**Example**
412
413```typescript
414import { BusinessError } from '@ohos.base';
415import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
416
417calendarMgr?.getAllCalendars().then((data: calendarManager.Calendar[]) => {
418  console.info(`Succeeded in getting all calendars, data -> ${JSON.stringify(data)}`);
419  data.forEach((calendar) => {
420    const account = calendar.getAccount();
421    console.info(`account -> ${JSON.stringify(account)}`);
422  })
423}).catch((err: BusinessError) => {
424  console.error(`Failed to get all calendars, err -> ${JSON.stringify(err)}`);
425});
426```
427
428## Calendar
429
430In the following API examples, you need to use [createCalendar()](#createcalendar) or [getCalendar()](#getcalendar) to obtain a **Calendar** object before calling related APIs.
431
432### Attributes
433
434**System capability**: SystemCapability.Applications.CalendarData
435
436| Name| Type  | Read-only| Mandatory| Description    |
437| ---- | ------ | ---- | ---- | -------- |
438| id   | number | Yes  | Yes  | Calendar account ID.|
439
440### addEvent
441
442addEvent(event: Event, callback: AsyncCallback\<number>): void
443
444Creates an event, with no event ID specified in [Event](#event). This API uses an asynchronous callback to return the result.
445
446**System capability**: SystemCapability.Applications.CalendarData
447
448**Parameters**
449
450| Name  | Type                  | Mandatory| Description                  |
451| -------- | ---------------------- | ---- | ---------------------- |
452| event    | [Event](#event)        | Yes  | **Event** object.           |
453| callback | AsyncCallback\<number> | Yes  | Callback used to return the event ID.|
454
455**Example**
456
457```typescript
458import { BusinessError } from '@ohos.base';
459import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
460
461let calendar : calendarManager.Calendar | undefined = undefined;
462const date = new Date();
463const event: calendarManager.Event = {
464  type: calendarManager.EventType.NORMAL,
465  startTime: date.getTime(),
466  endTime: date.getTime() + 60 * 60 * 1000
467};
468await calendarMgr?.getCalendar().then((data: calendarManager.Calendar) => {
469  console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
470  calendar = data;
471  calendar.addEvent(event, (err: BusinessError, data: number): void => {
472    if (err) {
473      console.error(`Failed to addEvent, err -> ${JSON.stringify(err)}`);
474    } else {
475      console.info(`Succeeded in adding the event, id -> ${data}`);
476    }
477  });
478}).catch((err: BusinessError) => {
479  console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
480});
481```
482
483### addEvent
484
485addEvent(event: Event): Promise\<number>
486
487Creates an event, with no event ID specified in [Event](#event). This API uses a promise to return the result.
488
489**System capability**: SystemCapability.Applications.CalendarData
490
491**Parameters**
492
493| Name| Type           | Mandatory| Description       |
494| ------ | --------------- | ---- | ----------- |
495| event  | [Event](#event) | Yes  | **Event** object.|
496
497**Return value**
498
499| Type            | Description                       |
500| ---------------- | --------------------------- |
501| Promise\<number> | Promise used to return the event ID.|
502
503**Example**
504
505```typescript
506import { BusinessError } from '@ohos.base';
507import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
508
509let calendar : calendarManager.Calendar | undefined = undefined;
510const date = new Date();
511const event: calendarManager.Event = {
512  type: calendarManager.EventType.NORMAL,
513  startTime: date.getTime(),
514  endTime: date.getTime() + 60 * 60 * 1000
515};
516calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
517  if (err) {
518    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
519  } else {
520    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
521    calendar = data;
522    calendar.addEvent(event).then((data: number) => {
523      console.info(`Succeeded in adding the event, id -> ${data}`);
524    }).catch((err: BusinessError) => {
525      console.error(`Failed to addEvent, err -> ${JSON.stringify(err)}`);
526    });
527  }
528});
529```
530
531### addEvents
532
533addEvents(events: Event[], callback: AsyncCallback\<void>): void
534
535Creates a batch of events, with no event ID specified in [Event](#event). This API uses an asynchronous callback to return the result.
536
537**System capability**: SystemCapability.Applications.CalendarData
538
539**Parameters**
540
541| Name  | Type                | Mandatory| Description           |
542| -------- | -------------------- | ---- | --------------- |
543| events   | [Event](#event)[]    | Yes  | Array of **Event** objects.|
544| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.     |
545
546**Example**
547
548```typescript
549import { BusinessError } from '@ohos.base';
550import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
551
552let calendar : calendarManager.Calendar | undefined = undefined;
553const date = new Date();
554const events: calendarManager.Event[] = [
555  {
556    type: calendarManager.EventType.NORMAL,
557    startTime: date.getTime(),
558    endTime: date.getTime() + 60 * 60 * 1000
559  },
560  {
561    type: calendarManager.EventType.NORMAL,
562    startTime: date.getTime(),
563    endTime: date.getTime() + 60 * 60 * 1000
564  }
565];
566calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
567  if (err) {
568    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
569  } else {
570    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
571    calendar = data;
572    calendar.addEvents(events, (err: BusinessError) => {
573      if (err) {
574        console.error(`Failed to add events, err -> ${JSON.stringify(err)}`);
575      } else {
576        console.info("Succeeded in adding events");
577      }
578    });
579  }
580});
581```
582
583### addEvents
584
585addEvents(events: Event[]): Promise\<void>
586
587Creates a batch of events, with no event ID specified in [Event](#event). This API uses a promise to return the result.
588
589**System capability**: SystemCapability.Applications.CalendarData
590
591**Parameters**
592
593| Name| Type             | Mandatory| Description           |
594| ------ | ----------------- | ---- | --------------- |
595| events | [Event](#event)[] | Yes  | Array of **Event** objects.|
596
597**Return value**
598
599| Type          | Description                     |
600| -------------- | ------------------------- |
601| Promise\<void> | Promise that returns no value.|
602
603**Example**
604
605```typescript
606import { BusinessError } from '@ohos.base';
607import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
608
609let calendar : calendarManager.Calendar | undefined = undefined;
610const date = new Date();
611const events: calendarManager.Event[] = [
612  {
613    type: calendarManager.EventType.NORMAL,
614    startTime: date.getTime(),
615    endTime: date.getTime() + 60 * 60 * 1000
616  },
617  {
618    type: calendarManager.EventType.NORMAL,
619    startTime: date.getTime(),
620    endTime: date.getTime() + 60 * 60 * 1000
621  }
622];
623calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
624  if (err) {
625    console.error(`Failed to get calendar: err -> ${JSON.stringify(err)}`);
626  } else {
627    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
628    calendar = data;
629    calendar.addEvents(events).then(() => {
630      console.info("Succeeded in adding events");
631    }).catch((err: BusinessError) => {
632      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
633    });
634  }
635});
636```
637
638### deleteEvent
639
640deleteEvent(id: number, callback: AsyncCallback\<void>): void
641
642Deletes an event with the specified ID. This API uses an asynchronous callback to return the result.
643
644**System capability**: SystemCapability.Applications.CalendarData
645
646**Parameters**
647
648| Name  | Type                | Mandatory| Description      |
649| -------- | -------------------- | ---- | ---------- |
650| id       | number               | Yes  | Event ID.  |
651| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.|
652
653**Example**
654
655```typescript
656import { BusinessError } from '@ohos.base';
657import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
658
659let calendar : calendarManager.Calendar | undefined = undefined;
660let id: number = 0;
661const date = new Date();
662const event: calendarManager.Event = {
663  type: calendarManager.EventType.NORMAL,
664  startTime: date.getTime(),
665  endTime: date.getTime() + 60 * 60 * 1000
666};
667calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
668  if (err) {
669    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
670  } else {
671    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
672    calendar = data;
673    await calendar.addEvent(event).then((data: number) => {
674      console.info(`Succeeded in adding the event, id -> ${data}`);
675      id = data;
676    }).catch((err: BusinessError) => {
677      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
678    });
679    calendar.deleteEvent(id, (err: BusinessError) => {
680      if (err) {
681        console.error(`Failed to delete the event, err -> ${JSON.stringify(err)}`);
682      } else {
683        console.info("Succeeded in deleting the event");
684      }
685    });
686  }
687});
688```
689
690### deleteEvent
691
692deleteEvent(id: number): Promise\<void>
693
694Deletes an event with the specified ID. This API uses a promise to return the result.
695
696**System capability**: SystemCapability.Applications.CalendarData
697
698**Parameters**
699
700| Name| Type  | Mandatory| Description    |
701| ------ | ------ | ---- | -------- |
702| id     | number | Yes  | Event ID.|
703
704**Return value**
705
706| Type          | Description                     |
707| -------------- | ------------------------- |
708| Promise\<void> | Promise that returns no value.|
709
710**Example**
711
712```typescript
713import { BusinessError } from '@ohos.base';
714import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
715
716let calendar : calendarManager.Calendar | undefined = undefined;
717let id: number = 0;
718const date = new Date();
719const event: calendarManager.Event = {
720  type: calendarManager.EventType.NORMAL,
721  startTime: date.getTime(),
722  endTime: date.getTime() + 60 * 60 * 1000
723};
724calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
725  if (err) {
726    console.error(`Failed to get calendar: err->${JSON.stringify(err)}`);
727  } else {
728    console.info(`Succeeded in getting calendar data->${JSON.stringify(data)}`);
729    calendar = data;
730    await calendar.addEvent(event).then((data: number) => {
731      console.info(`Succeeded in adding the event, id -> ${data}`);
732      id = data;
733    }).catch((err: BusinessError) => {
734      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
735    });
736    calendar.deleteEvent(id).then(() => {
737      console.info("Succeeded in deleting the event");
738    }).catch((err: BusinessError) => {
739      console.error("Failed to delete event");
740    });
741  }
742});
743```
744
745### deleteEvents
746
747deleteEvents(ids: number[], callback: AsyncCallback\<void>): void
748
749Deletes a batch of events with the specified IDs. This API uses an asynchronous callback to return the result.
750
751**System capability**: SystemCapability.Applications.CalendarData
752
753**Parameters**
754
755| Name  | Type                | Mandatory| Description        |
756| -------- | -------------------- | ---- | ------------ |
757| ids      | number[]             | Yes  | Array of event IDs.|
758| callback | AsyncCallback\<void> | Yes  | Callback used to return the result.  |
759
760**Example**
761
762```typescript
763import { BusinessError } from '@ohos.base';
764import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
765
766let calendar : calendarManager.Calendar | undefined = undefined;
767let id1: number = 0;
768let id2: number = 0;
769const date = new Date();
770const event1: calendarManager.Event = {
771  type: calendarManager.EventType.NORMAL,
772  startTime: date.getTime(),
773  endTime: date.getTime() + 60 * 60 * 1000
774};
775const event2: calendarManager.Event = {
776  type: calendarManager.EventType.IMPORTANT,
777  startTime: date.getTime(),
778  endTime: date.getTime() + 60 * 60 * 1000
779};
780calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
781  if (err) {
782    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
783  } else {
784    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
785    calendar = data;
786    await calendar.addEvent(event1).then((data: number) => {
787      console.info(`Succeeded in adding the event, id -> ${data}`);
788      id1 = data;
789    }).catch((err: BusinessError) => {
790      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
791    });
792    await calendar.addEvent(event2).then((data: number) => {
793      console.info(`Succeeded in adding the event, id -> ${data}`);
794      id2 = data;
795    }).catch((err: BusinessError) => {
796      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
797    });
798    calendar.deleteEvents([id1, id2], (err: BusinessError) => {
799      if (err) {
800        console.error("Failed to delete events");
801      } else {
802        console.info("Succeeded in deleting the events");
803      }
804    });
805  }
806});
807```
808
809### deleteEvents
810
811deleteEvents(ids: number[]): Promise\<void>
812
813Deletes a batch of events with the specified IDs. This API uses a promise to return the result.
814
815**System capability**: SystemCapability.Applications.CalendarData
816
817**Parameters**
818
819| Name| Type    | Mandatory| Description        |
820| ------ | -------- | ---- | ------------ |
821| ids    | number[] | Yes  | Array of event IDs.|
822
823**Return value**
824
825| Type          | Description                     |
826| -------------- | ------------------------- |
827| Promise\<void> | Promise that returns no value.|
828
829**Example**
830
831```typescript
832import { BusinessError } from '@ohos.base';
833import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
834
835let calendar : calendarManager.Calendar | undefined = undefined;
836let id1: number = 0;
837let id2: number = 0;
838const date = new Date();
839const event1: calendarManager.Event = {
840  type: calendarManager.EventType.NORMAL,
841  startTime: date.getTime(),
842  endTime: date.getTime() + 60 * 60 * 1000
843};
844const event2: calendarManager.Event = {
845  type: calendarManager.EventType.IMPORTANT,
846  startTime: date.getTime(),
847  endTime: date.getTime() + 60 * 60 * 1000
848};
849calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
850  if (err) {
851    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
852  } else {
853    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
854    calendar = data;
855    await calendar.addEvent(event1).then((data: number) => {
856      console.info(`Succeeded in adding the event, id -> ${data}`);
857      id1 = data;
858    }).catch((err: BusinessError) => {
859      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
860    });
861    await calendar.addEvent(event2).then((data: number) => {
862      console.info(`Succeeded in adding the event, id -> ${data}`);
863      id2 = data;
864    }).catch((err: BusinessError) => {
865      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
866    });
867    calendar.deleteEvents([id1, id2]).then(() => {
868      console.info("Succeeded in deleting the events");
869    }).catch((err: BusinessError) => {
870      console.error("Failed to delete events");
871    });
872  }
873});
874```
875
876### updateEvent
877
878updateEvent(event: Event, callback: AsyncCallback\<void>): void
879
880Updates an event. This API uses an asynchronous callback to return the result.
881
882**System capability**: SystemCapability.Applications.CalendarData
883
884**Parameters**
885
886| Name  | Type                | Mandatory| Description       |
887| -------- | -------------------- | ---- | ----------- |
888| event    | [Event](#event)      | Yes  | **Event** object.|
889| callback | AsyncCallback\<void> | Yes  | Callback used to return the result. |
890
891**Example**
892
893```typescript
894import { BusinessError } from '@ohos.base';
895import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
896
897let calendar : calendarManager.Calendar | undefined = undefined;
898const date = new Date();
899const oriEvent: calendarManager.Event = {
900  title: 'update',
901  type: calendarManager.EventType.NORMAL,
902  description: 'updateEventTest',
903  startTime: date.getTime(),
904  endTime: date.getTime() + 60 * 60 * 1000
905};
906calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
907  if (err) {
908    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
909  } else {
910    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
911    calendar = data;
912    await calendar.addEvent(oriEvent).then((data: number) => {
913      console.info(`Succeeded in adding the event, id -> ${data}`);
914      oriEvent.id = data;
915      oriEvent.title = 'newUpdate';
916    }).catch((err: BusinessError) => {
917      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
918    });
919    calendar.updateEvent(oriEvent, (err: BusinessError) => {
920      if (err) {
921        console.error(`Failed to update the event, err -> ${JSON.stringify(err)}`);
922      } else {
923        console.info("Succeeded in updating the event");
924      }
925    });
926  }
927});
928```
929
930### updateEvent
931
932updateEvent(event: Event): Promise\<void>
933
934Updates an event. This API uses a promise to return the result.
935
936**System capability**: SystemCapability.Applications.CalendarData
937
938**Parameters**
939
940| Name| Type           | Mandatory| Description       |
941| ------ | --------------- | ---- | ----------- |
942| event  | [Event](#event) | Yes  | **Event** object.|
943
944**Return value**
945
946| Type          | Description                     |
947| -------------- | ------------------------- |
948| Promise\<void> | Promise that returns no value.|
949
950**Example**
951
952```typescript
953import { BusinessError } from '@ohos.base';
954import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
955
956let calendar : calendarManager.Calendar | undefined = undefined;
957const date = new Date();
958const oriEvent: calendarManager.Event = {
959  title: 'update',
960  type: calendarManager.EventType.NORMAL,
961  description: 'updateEventTest',
962  startTime: date.getTime(),
963  endTime: date.getTime() + 60 * 60 * 1000
964};
965calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
966  if (err) {
967    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
968  } else {
969    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
970    calendar = data;
971    await calendar.addEvent(oriEvent).then((data: number) => {
972      console.info(`Succeeded in adding the event, id -> ${data}`);
973      oriEvent.id = data;
974      oriEvent.title = 'newUpdate';
975    }).catch((err: BusinessError) => {
976      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
977    });
978    calendar.updateEvent(oriEvent).then(() => {
979      console.info(`Succeeded in updating the event`);
980    }).catch((err: BusinessError) => {
981      console.error(`Failed to update event, err -> ${JSON.stringify(err)}`);
982    });
983  }
984});
985```
986
987### getEvents
988
989getEvents(callback: AsyncCallback\<Event[]>): void
990
991Obtains all events in a calendar. This API uses an asynchronous callback to return the result.
992
993**System capability**: SystemCapability.Applications.CalendarData
994
995**Parameters**
996
997| Name  | Type                            | Mandatory| Description                             |
998| -------- | -------------------------------- | ---- | --------------------------------- |
999| callback | AsyncCallback<[Event](#event)[]> | Yes  | Callback used to return an array of events.|
1000
1001**Example**
1002
1003```typescript
1004import { BusinessError } from '@ohos.base';
1005import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1006
1007let calendar : calendarManager.Calendar | undefined = undefined;
1008calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
1009  if (err) {
1010    console.error(`Failed to get calendar: err -> ${JSON.stringify(err)}`);
1011  } else {
1012    console.info(`Succeeded in getting the calendar data -> ${JSON.stringify(data)}`);
1013    calendar = data;
1014    calendar.getEvents((err: BusinessError, data: calendarManager.Event[]) => {
1015      if (err) {
1016        console.error(`Failed to get events, err -> ${JSON.stringify(err)}`);
1017      } else {
1018        console.info(`Succeeded in getting the events, data -> ${JSON.stringify(data)}`);
1019      }
1020    });
1021  }
1022});
1023```
1024
1025### getEvents
1026
1027getEvents(eventFilter: EventFilter, eventKey: (keyof Event)[], callback: AsyncCallback\<Event[]>):void
1028
1029Obtains all events in a calendar that match the filter criteria. This API uses an asynchronous callback to return the result.
1030
1031**System capability**: SystemCapability.Applications.CalendarData
1032
1033**Parameters**
1034
1035| Name     | Type                            | Mandatory| Description                             |
1036| ----------- | -------------------------------- | ---- | --------------------------------- |
1037| eventFilter | [EventFilter](#eventfilter)      | Yes  | Filter criteria.                       |
1038| eventKey    | (keyof [Event](#event))[]        | Yes  | Filter field.                       |
1039| callback    | AsyncCallback<[Event](#event)[]> | Yes  | Callback used to return an array of events.|
1040
1041**Example**
1042
1043```typescript
1044import { BusinessError } from '@ohos.base';
1045import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1046
1047let calendar : calendarManager.Calendar | undefined = undefined;
1048let id1: number = 0;
1049let id2: number = 0;
1050const date = new Date();
1051const event1: calendarManager.Event = {
1052  type: calendarManager.EventType.NORMAL,
1053  startTime: date.getTime(),
1054  endTime: date.getTime() + 60 * 60 * 1000
1055};
1056const event2: calendarManager.Event = {
1057  type: calendarManager.EventType.IMPORTANT,
1058  startTime: date.getTime(),
1059  endTime: date.getTime() + 60 * 60 * 1000
1060};
1061calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
1062  if (err) {
1063    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1064  } else {
1065    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1066    calendar = data;
1067    await calendar.addEvent(event1).then((data: number) => {
1068      console.info(`Succeeded in adding the event, id -> ${data}`);
1069    }).catch((err: BusinessError) => {
1070      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1071    });
1072    await calendar.addEvent(event2).then((data: number) => {
1073      console.info(`Succeeded in adding the event, id -> ${data}`);
1074    }).catch((err: BusinessError) => {
1075      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1076    });
1077    const filter = calendarManager.EventFilter.filterById([id1, id2]);
1078    calendar.getEvents(filter, ['title', 'type', 'startTime', 'endTime'], (err: BusinessError, data: calendarManager.Event[]) => {
1079      if (err) {
1080        console.error(`Failed to get events, err -> ${JSON.stringify(err)}`);
1081      } else {
1082        console.info(`Succeeded in getting the events, data -> ${JSON.stringify(data)}`);
1083      }
1084    });
1085  }
1086});
1087```
1088
1089### getEvents
1090
1091getEvents(eventFilter?: EventFilter, eventKey?: (keyof Event)[]): Promise\<Event[]>
1092
1093Obtains all events in a calendar that match the filter criteria. This API uses a promise to return the result.
1094
1095**System capability**: SystemCapability.Applications.CalendarData
1096
1097**Parameters**
1098
1099| Name     | Type                       | Mandatory| Description      |
1100| ----------- | --------------------------- | ---- | ---------- |
1101| eventFilter | [EventFilter](#eventfilter) | No  | Filter criteria.|
1102| eventKey    | (keyof [Event](#event))[]   | No  | Filter field.|
1103
1104**Return value**
1105
1106| Type                      | Description                               |
1107| -------------------------- | ----------------------------------- |
1108| Promise<[Event](#event)[]> | Promise used to return an array of events.|
1109
1110**Example**
1111
1112```typescript
1113import { BusinessError } from '@ohos.base';
1114import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1115
1116let calendar : calendarManager.Calendar | undefined = undefined;
1117const date = new Date();
1118const event: calendarManager.Event = {
1119  title: 'MyEvent',
1120  type: calendarManager.EventType.IMPORTANT,
1121  startTime: date.getTime(),
1122  endTime: date.getTime() + 60 * 60 * 1000
1123};
1124calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
1125  if (err) {
1126    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1127  } else {
1128    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1129    calendar = data;
1130    await calendar.addEvent(event).then((data: number) => {
1131      console.info(`Succeeded in adding the event, id -> ${data}`);
1132    }).catch((err: BusinessError) => {
1133      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1134    });
1135    const filter = calendarManager.EventFilter.filterByTitle('MyEvent');
1136    calendar.getEvents(filter).then((data: calendarManager.Event[]) => {
1137      console.info(`Succeeded in getting the events, data -> ${JSON.stringify(data)}`);
1138    }).catch((err: BusinessError) => {
1139      console.error(`Failed to get events, err -> ${JSON.stringify(err)}`);
1140    });
1141  }
1142});
1143```
1144
1145### getConfig
1146
1147getConfig(): CalendarConfig
1148
1149Obtains the calendar configuration information.
1150
1151**System capability**: SystemCapability.Applications.CalendarData
1152
1153**Return value**
1154
1155| Type                             | Description          |
1156| --------------------------------- | -------------- |
1157| [CalendarConfig](#calendarconfig) | Calendar configuration information.|
1158
1159**Example**
1160
1161```typescript
1162import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1163
1164let calendar : calendarManager.Calendar | undefined = undefined;
1165calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
1166  if (err) {
1167    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1168  } else {
1169    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1170    calendar = data;
1171    const config = calendar.getConfig();
1172    console.info("get config success");
1173  }
1174});
1175```
1176
1177### setConfig
1178
1179setConfig(config: CalendarConfig, callback: AsyncCallback\<void>): void
1180
1181Sets the calendar configuration information. This API uses an asynchronous callback to return the result.
1182
1183**System capability**: SystemCapability.Applications.CalendarData
1184
1185**Parameters**
1186
1187| Name  | Type                             | Mandatory| Description          |
1188| -------- | --------------------------------- | ---- | -------------- |
1189| config   | [CalendarConfig](#calendarconfig) | Yes  | Calendar configuration information.|
1190| callback | AsyncCallback\<void>              | Yes  | Callback used to return the result.    |
1191
1192**Example**
1193
1194```typescript
1195import { BusinessError } from '@ohos.base';
1196import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1197
1198let calendar : calendarManager.Calendar | undefined = undefined;
1199const config: calendarManager.CalendarConfig = {
1200  enableReminder: true,
1201  color: '#aabbcc'
1202};
1203calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
1204  if (err) {
1205    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1206  } else {
1207    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1208    calendar = data;
1209    calendar.setConfig(config, (err: BusinessError) => {
1210      if (err) {
1211        console.error(`Failed to set the configuration, err -> ${JSON.stringify(err)}`);
1212      } else {
1213        console.info(`Succeeded in setting the configuration, config -> ${JSON.stringify(config)}`);
1214      }
1215    });
1216  }
1217});
1218```
1219
1220### setConfig
1221
1222setConfig(config: CalendarConfig): Promise\<void>
1223
1224Sets the calendar configuration information. This API uses a promise to return the result.
1225
1226**System capability**: SystemCapability.Applications.CalendarData
1227
1228**Parameters**
1229
1230| Name| Type                             | Mandatory| Description          |
1231| ------ | --------------------------------- | ---- | -------------- |
1232| config | [CalendarConfig](#calendarconfig) | Yes  | Calendar configuration information.|
1233
1234**Return value**
1235
1236| Type          | Description                     |
1237| -------------- | ------------------------- |
1238| Promise\<void> | Promise that returns no value.|
1239
1240**Example**
1241
1242```typescript
1243import { BusinessError } from '@ohos.base';
1244import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1245
1246let calendar : calendarManager.Calendar | undefined = undefined;
1247const config: calendarManager.CalendarConfig = {
1248  enableReminder: true,
1249  color: '#aabbcc'
1250};
1251calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
1252  if (err) {
1253    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1254  } else {
1255    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1256    calendar = data;
1257    calendar.setConfig(config).then(() => {
1258      console.info(`Succeeded in setting the configuration, data->${JSON.stringify(config)}`);
1259    }).catch((err: BusinessError) => {
1260      console.error(`Failed to set config, err->${JSON.stringify(err)}`);
1261    });
1262  }
1263});
1264```
1265
1266### getAccount
1267
1268getAccount(): CalendarAccount
1269
1270Obtains the calendar account information.
1271
1272**System capability**: SystemCapability.Applications.CalendarData
1273
1274**Return value**
1275
1276| Type                               | Description          |
1277| ----------------------------------- | -------------- |
1278| [CalendarAccount](#calendaraccount) | Calendar account information.|
1279
1280**Example**
1281
1282```typescript
1283import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1284
1285let calendar : calendarManager.Calendar | undefined = undefined;
1286calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => {
1287  if (err) {
1288    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1289  } else {
1290    console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`);
1291    calendar = data;
1292    const account = calendar.getAccount();
1293    console.info(`get account success, account -> ${JSON.stringify(account)}`);
1294  }
1295});
1296```
1297
1298## CalendarAccount
1299
1300Describes the calendar account information.
1301
1302**System capability**: SystemCapability.Applications.CalendarData
1303
1304| Name       | Type                         | Read-only| Mandatory| Description                                  |
1305| ----------- | ----------------------------- | ---- | ---- | -------------------------------------- |
1306| name        | string                        | Yes  | Yes  | Account name.                            |
1307| type        | [CalendarType](#calendartype) | No  | Yes  | Account type.                            |
1308| displayName | string                        | No  | No  | Display name of the account. If this parameter is not set, an empty string is used.|
1309
1310## CalendarConfig
1311
1312Describes the calendar configuration information.
1313
1314**System capability**: SystemCapability.Applications.CalendarData
1315
1316| Name          | Type                                               | Read-only| Mandatory| Description                                                        |
1317| -------------- | --------------------------------------------------- | ---- | ---- | ------------------------------------------------------------ |
1318| enableReminder | boolean                                             | No  | No  | Whether to enable the reminder for events in the calendar. The value **true** means to enable the reminder for events in the calendar, and **false** means the opposite. The default value is **true**.|
1319| color          | string/number | No  | No  | Calendar color. If this parameter is not set, the default value **'#0A59F7'** is used.               |
1320
1321## Event
1322
1323Describes an **Event** object, including the event title, start time, and end time.
1324
1325**System capability**: SystemCapability.Applications.CalendarData
1326
1327| Name          | Type                             | Read-only| Mandatory| Description                                                        |
1328| -------------- | --------------------------------- | ---- | ---- | ------------------------------------------------------------ |
1329| id             | number                            | No  | No  | Event ID. This parameter does not need to be set in the [addEvent()](#addevent) or [addEvents()](#addevents) API.|
1330| type           | [EventType](#eventtype)           | No  | Yes  | Event type.                                                  |
1331| title          | string                            | No  | No  | Event title. If this parameter is not set, an empty string is used.                            |
1332| location       | [Location](#location)             | No  | No  | Event location. If this parameter is not set, the default null value is used.                              |
1333| startTime      | number                            | No  | Yes  | Start time of the event. The value is a 13-digit timestamp.                                              |
1334| endTime        | number                            | No  | Yes  | End time of the event. The value is a 13-digit timestamp.                                              |
1335| isAllDay       | boolean                           | No  | No  | Whether the event is an all-day event. The value **true** means that the event is an all-day event, and **false** means the opposite. The default value is **false**.|
1336| attendee       | [Attendee](#attendee)[]           | No  | No  | Event attendee. If this parameter is not set, the default null value is used.                            |
1337| timeZone       | string                            | No  | No  | Time zone of the event. If this parameter is not set, the current system time zone is used. You can call the [getTimeZone()](js-apis-system-date-time.md#systemdatetimegettimezone) API to obtain the current system time zone.|
1338| reminderTime   | number[]                          | No  | No  | Amount of time that the reminder occurs before the start of the event, in minutes. For example, if the value is 5, the reminder occurs 5 minutes before the event starts. If this parameter is not set, no reminder is set. The value can be negative.                          |
1339| recurrenceRule | [RecurrenceRule](#recurrencerule) | No  | No  | Recurrence rule of the event. If this parameter is not set, the value does not recur.                          |
1340| description    | string                            | No  | No  | Event description. If this parameter is not set, an empty string is used.                            |
1341| service        | [EventService](#eventservice)     | No  | No  | Event service. If this parameter is not set, no service is available.                          |
1342
1343## CalendarType
1344
1345Enumerates the account types.
1346
1347**System capability**: SystemCapability.Applications.CalendarData
1348
1349| Name      | Value          | Description                |
1350| ---------- | ------------ | -------------------- |
1351| LOCAL      | 'local'      | Local account.          |
1352| EMAIL      | 'email'      | Email account.          |
1353| BIRTHDAY   | 'birthday'   | Birthday account.          |
1354| CALDAV     | 'caldav'     | CalDAV account.|
1355| SUBSCRIBED | 'subscribed' | Subscription account.          |
1356
1357## Location
1358
1359Describes the event location.
1360
1361**System capability**: SystemCapability.Applications.CalendarData
1362
1363| Name     | Type  | Read-only| Mandatory| Description                    |
1364| --------- | ------ | ---- | ---- | ------------------------ |
1365| location  | string | No  | No  | Location. The default value is an empty string.|
1366| longitude | number | No  | No  | Longitude of the location. The default value is **0**.       |
1367| latitude  | number | No  | No  | Latitude of the location. The default value is **0**.       |
1368
1369## EventFilter
1370
1371Implements an event filter.
1372
1373You can use [filterById()](#filterbyid), [filterByTime()](#filterbytime), or [filterByTitle()](#filterbytitle) to obtain an event filter, and then pass the filter in [getEvents()](#getevents) for filtering.
1374
1375### filterById
1376
1377static filterById(ids: number[]): EventFilter
1378
1379Defines an event ID based filter.
1380
1381**System capability**: SystemCapability.Applications.CalendarData
1382
1383**Parameters**
1384
1385| Name| Type    | Mandatory| Description        |
1386| ------ | -------- | ---- | ------------ |
1387| ids    | number[] | Yes  | Array of event IDs.|
1388
1389**Return value**
1390
1391| Type                       | Description                |
1392| --------------------------- | -------------------- |
1393| [EventFilter](#eventfilter) | **EventFilter** object.|
1394
1395**Example**
1396
1397```typescript
1398import { BusinessError } from '@ohos.base';
1399import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1400
1401let calendar : calendarManager.Calendar | undefined = undefined;
1402let id1: number = 0;
1403let id2: number = 0;
1404const date = new Date();
1405const event1: calendarManager.Event = {
1406  type: calendarManager.EventType.NORMAL,
1407  startTime: date.getTime(),
1408  endTime: date.getTime() + 60 * 60 * 1000
1409};
1410const event2: calendarManager.Event = {
1411  type: calendarManager.EventType.IMPORTANT,
1412  startTime: date.getTime(),
1413  endTime: date.getTime() + 60 * 60 * 1000
1414};
1415calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
1416  if (err) {
1417    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1418  } else {
1419    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1420    calendar = data;
1421    await calendar.addEvent(event1).then((data: number) => {
1422      console.info(`Succeeded in adding the event, id -> ${data}`);
1423      id1 = data;
1424    }).catch((err: BusinessError) => {
1425      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1426    });
1427    await calendar.addEvent(event2).then((data: number) => {
1428      console.info(`Succeeded in adding the event, id -> ${data}`);
1429      id2 = data;
1430    }).catch((err: BusinessError) => {
1431      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1432    });
1433    const filter = calendarManager.EventFilter.filterById([id1, id2]);
1434    calendar.getEvents(filter).then((data: calendarManager.Event[]) => {
1435      console.info(`Succeeded in filtering by id, data -> ${JSON.stringify(data)}`);
1436    }).catch((err: BusinessError) => {
1437      console.error(`Failed to filter by id, err -> ${JSON.stringify(err)}`);
1438    });
1439  }
1440});
1441```
1442
1443### filterByTime
1444
1445static filterByTime(start: number, end: number): EventFilter
1446
1447Defines an event time based filter.
1448
1449**System capability**: SystemCapability.Applications.CalendarData
1450
1451**Parameters**
1452
1453| Name| Type  | Mandatory| Description      |
1454| ------ | ------ | ---- | ---------- |
1455| start  | number | Yes  | Start time.|
1456| end    | number | Yes  | End time.|
1457
1458**Return value**
1459
1460| Type                       | Description                |
1461| --------------------------- | -------------------- |
1462| [EventFilter](#eventfilter) | **EventFilter** object.|
1463
1464**Example**
1465
1466```typescript
1467import { BusinessError } from '@ohos.base';
1468import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1469
1470let calendar : calendarManager.Calendar | undefined = undefined;
1471const event1: calendarManager.Event = {
1472  type: calendarManager.EventType.NORMAL,
1473  startTime: 1686931200000,
1474  endTime: 1687017600000
1475};
1476const event2: calendarManager.Event = {
1477  type: calendarManager.EventType.IMPORTANT,
1478  startTime: 1686931200000,
1479  endTime: 1687017600000
1480};
1481calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
1482  if (err) {
1483    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1484  } else {
1485    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1486    calendar = data;
1487    await calendar.addEvent(event1).then((data: number) => {
1488      console.info(`Succeeded in adding the event, id -> ${data}`);
1489    }).catch((err: BusinessError) => {
1490      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1491    });
1492    await calendar.addEvent(event2).then((data: number) => {
1493      console.info(`Succeeded in adding the event, id -> ${data}`);
1494    }).catch((err: BusinessError) => {
1495      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1496    });
1497    const filter = calendarManager.EventFilter.filterByTime(1686931200000, 1687017600000);
1498    calendar.getEvents(filter).then((data: calendarManager.Event[]) => {
1499      console.info(`Succeeded in filtering by time, data -> ${JSON.stringify(data)}`);
1500    }).catch((err: BusinessError) => {
1501      console.error(`Failed to filter by time, err -> ${JSON.stringify(err)}`);
1502    });
1503  }
1504});
1505```
1506
1507### filterByTitle
1508
1509static filterByTitle(title: string): EventFilter
1510
1511Defines an event title based filter.
1512
1513**System capability**: SystemCapability.Applications.CalendarData
1514
1515**Parameters**
1516
1517| Name| Type  | Mandatory| Description      |
1518| ------ | ------ | ---- | ---------- |
1519| title  | string | Yes  | Event title.|
1520
1521**Return value**
1522
1523| Type                       | Description                |
1524| --------------------------- | -------------------- |
1525| [EventFilter](#eventfilter) | **EventFilter** object.|
1526
1527**Example**
1528
1529```typescript
1530import { BusinessError } from '@ohos.base';
1531import {calendarMgr} from '../testability/TestAbility'; // The path is applicable to the test module.
1532
1533let calendar : calendarManager.Calendar | undefined = undefined;
1534const event: calendarManager.Event = {
1535  title: 'MyEvent',
1536  type: calendarManager.EventType.NORMAL,
1537  startTime: 1686931200000,
1538  endTime: 1687017600000
1539};
1540calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => {
1541  if (err) {
1542    console.error(`Failed to get the calendar, err -> ${JSON.stringify(err)}`);
1543  } else {
1544    console.info(`Succeeded in getting the calendar, data -> ${JSON.stringify(data)}`);
1545    calendar = data;
1546    await calendar.addEvent(event).then((data: number) => {
1547      console.info(`Succeeded in adding the event, id -> ${data}`);
1548    }).catch((err: BusinessError) => {
1549      console.error(`Failed to add the event, err -> ${JSON.stringify(err)}`);
1550    });
1551    const filter = calendarManager.EventFilter.filterByTitle('MyEvent');
1552    calendar.getEvents(filter).then((data: calendarManager.Event[]) => {
1553      console.info(`Succeeded in filtering by title, data -> ${JSON.stringify(data)}`);
1554    }).catch((err: BusinessError) => {
1555      console.error(`Failed to filter by title, err -> ${JSON.stringify(err)}`);
1556    });
1557  }
1558});
1559```
1560
1561## EventType
1562
1563Enumerates event types.
1564
1565**System capability**: SystemCapability.Applications.CalendarData
1566
1567| Name     | Value  | Description                |
1568| --------- | ---- | -------------------- |
1569| NORMAL    | 0    | Normal event.          |
1570| IMPORTANT | 1    | Important event. This type of event supports countdown.|
1571
1572## RecurrenceRule
1573
1574Describes the event recurrence rule.
1575
1576**System capability**: SystemCapability.Applications.CalendarData
1577
1578| Name               | Type                                       | Read-only| Mandatory| Description                           |
1579| ------------------- | ------------------------------------------- | ---- | ---- | ------------------------------- |
1580| recurrenceFrequency | [RecurrenceFrequency](#recurrencefrequency) | No  | Yes  | Type of the event recurrence rule.             |
1581| expire              | number                                      | No  | No  | End date of the recurrence period. If this parameter is not set, the default value **0** is used.|
1582
1583## RecurrenceFrequency
1584
1585Enumerates the types of the event recurrence rule.
1586
1587**System capability**: SystemCapability.Applications.CalendarData
1588
1589| Name   | Value  | Description      |
1590| ------- | ---- | ---------- |
1591| YEARLY  | 0    | Yearly.|
1592| MONTHLY | 1    | Monthly.|
1593| WEEKLY  | 2    | Weekly.|
1594| DAILY   | 3    | Daily.|
1595
1596## Attendee
1597
1598Describes the event attendee.
1599
1600**System capability**: SystemCapability.Applications.CalendarData
1601
1602| Name | Type  | Read-only| Mandatory| Description          |
1603| ----- | ------ | ---- | ---- | -------------- |
1604| name  | string | No  | Yes  | Name of the attendee.|
1605| email | string | No  | Yes  | Email address of the attendee.|
1606
1607## EventService
1608
1609Describes the event service.
1610
1611**System capability**: SystemCapability.Applications.CalendarData
1612
1613| Name       | Type                       | Read-only| Mandatory| Description                                 |
1614| ----------- | --------------------------- | ---- | ---- | ------------------------------------- |
1615| type        | [ServiceType](#servicetype) | No  | Yes  | Service type.                           |
1616| uri         | string                      | No  | Yes  | URI of the service. It can be used to redirect the user to a page of another application.|
1617| description | string                      | No  | No  | Description of the service. If this parameter is not set, an empty string is used. |
1618
1619## ServiceType
1620
1621Enumerates the event service types.
1622
1623**System capability**: SystemCapability.Applications.CalendarData
1624
1625| Name           | Value              | Description        |
1626| --------------- | ---------------- | ------------ |
1627| MEETING         | 'Meeting'        | Join a meeting.  |
1628| WATCHING        | 'Watching'       | Watch a video.  |
1629| REPAYMENT       | 'Repayment'      | Make a payment.  |
1630| LIVE            | 'Live'           | Watch live TV.  |
1631| SHOPPING        | 'Shopping'       | Go shopping.  |
1632| TRIP            | 'Trip'           | View the trip.  |
1633| CLASS           | 'Class'          | Join class.  |
1634| SPORTS_EVENTS   | 'SportsEvents'   | Watch a sports event.|
1635| SPORTS_EXERCISE | 'SportsExercise' | Start exercising.  |
1636