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. 4 5- A [CalendarManager](#calendarmanager) object is used to manage [Calendar](#calendar) objects. 6 7- A [Calendar](#calendar) object contains the account information [CalendarAccount](#calendaraccount) and configuration information [CalendarConfig](#calendarconfig). An **Event** object is subordinate to a **Calendar** object. To create an **Event** object, you need to create a **Calendar** object first. A **Calendar** contains multiple **Event** objects, but an **Event** belongs to only one **Calendar**. **CalendarManager** is used to manage calendars, and **EventFilter** is used to manage events. 8 9> **NOTE** 10> 11> 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. 12 13 14## Modules to Import 15 16```typescript 17import { calendarManager } from '@kit.CalendarKit' 18``` 19 20## calendarManager.getCalendarManager 21 22getCalendarManager(context: Context): CalendarManager 23 24Obtains a **CalendarManager** object based on the context. 25 26**Atomic service API**: This API can be used in atomic services since API version 11. 27 28**System capability**: SystemCapability.Applications.CalendarData 29 30**Model restriction**: This API can be used only in the stage model. 31 32**Parameters** 33 34| Name | Type | Mandatory| Description | 35| -------- | --------------------------- | ---- |----------------------------------------------------------------------------------------------------------------| 36| context | Context | Yes | Application context. For details about the application context of the stage model, see [Context](../apis-ability-kit/js-apis-inner-application-uiAbilityContext.md).| 37 38**Return value** 39 40| Type | Description | 41| ------------------------------ | ------------------------------------- | 42| CalendarManager | **CalendarManager** object obtained.| 43 44**Example** 45 46```typescript 47// Obtain an mContext object. 48// Obtain a calendarMgr object. 49// The file is auto-generated: entry/src/main/ets/entryability/EntryAbility.ets 50import { 51 abilityAccessCtrl, 52 AbilityConstant, common, PermissionRequestResult, Permissions, UIAbility, Want } from '@kit.AbilityKit'; 53import { BusinessError } from '@kit.BasicServicesKit'; 54import { calendarManager } from '@kit.CalendarKit'; 55import { window } from '@kit.ArkUI'; 56 57export let calendarMgr: calendarManager.CalendarManager | null = null; 58export let mContext: common.UIAbilityContext | null = null; 59export default class EntryAbility extends UIAbility { 60 onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void { 61 console.info("Ability onCreate"); 62 } 63 64 onDestroy(): void { 65 console.info("Ability onDestroy"); 66 } 67 68 onWindowStageCreate(windowStage: window.WindowStage): void { 69 // Main window is created, set main page for this ability 70 console.info("Ability onWindowStageCreate"); 71 72 windowStage.loadContent('pages/Index', (err, data) => { 73 if (err.code) { 74 console.error(`Failed to load the content. Code: ${err.code}, message: ${err.message}`); 75 return; 76 } 77 console.info(`Succeeded in loading the content. Data: ${JSON.stringify(data)}`); 78 }); 79 mContext = this.context; 80 const permissions: Permissions[] = ['ohos.permission.READ_CALENDAR', 'ohos.permission.WRITE_CALENDAR']; 81 let atManager = abilityAccessCtrl.createAtManager(); 82 atManager.requestPermissionsFromUser(mContext, permissions).then((result: PermissionRequestResult) => { 83 console.info(`get Permission success, result: ${JSON.stringify(result)}`); 84 calendarMgr = calendarManager.getCalendarManager(mContext); 85 }).catch((error: BusinessError) => { 86 console.error(`get Permission error, error. Code: ${error.code}, message: ${error.message}`); 87 }) 88 } 89 90 onWindowStageDestroy(): void { 91 // Main window is destroyed, release UI related resources 92 console.info("Ability onWindowStageDestroy"); 93 } 94 95 onForeground(): void { 96 // Ability has brought to foreground 97 console.info("Ability onForeground"); 98 } 99 100 onBackground(): void { 101 // Ability has back to background 102 console.info("Ability onBackground"); 103 } 104} 105``` 106 107## CalendarManager 108 109Before calling any of the following APIs, you must use [getCalendarManager()](#calendarmanagergetcalendarmanager) to obtain a **CalendarManager** object. 110 111 112### createCalendar 113 114createCalendar(calendarAccount: CalendarAccount, callback: AsyncCallback\<Calendar>): void 115 116Creates a **Calendar** object based on the calendar account information. This API uses an asynchronous callback to return the result. 117 118**Required permissions**: ohos.permission.WRITE_CALENDAR 119 120**System capability**: SystemCapability.Applications.CalendarData 121 122**Parameters** 123 124| Name | Type | Mandatory| Description | 125| --------------- | ------------------------------------- | ---- | ---------------------------------- | 126| calendarAccount | [CalendarAccount](#calendaraccount) | Yes | Calendar account information. | 127| callback | AsyncCallback\<[Calendar](#calendar)> | Yes | Callback used to return the created **Calendar** object.| 128 129**Error codes** 130 131For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 132 133| ID| Error Message | 134| -------- | ------------------------------ | 135| 201 | Permission denied. | 136| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 137| 801 | Capability not supported. | 138 139**Example** 140 141```typescript 142import { BusinessError } from '@kit.BasicServicesKit'; 143import { calendarMgr } from '../entryability/EntryAbility'; 144 145let calendar: calendarManager.Calendar | undefined = undefined; 146const calendarAccount: calendarManager.CalendarAccount = { 147 name: 'CreateMyCalendarByCallBack', 148 type: calendarManager.CalendarType.LOCAL 149}; 150try { 151 calendarMgr?.createCalendar(calendarAccount, (err: BusinessError, data: calendarManager.Calendar) => { 152 if (err) { 153 console.error(`Failed to create calendar. Code: ${err.code}, message: ${err.message}`); 154 } else { 155 console.info(`Succeeded in creating calendar, data -> ${JSON.stringify(data)}`); 156 calendar = data; 157 } 158 }); 159} catch (error) { 160 console.error(`Failed to create calendar. Code: ${error.code}, message: ${error.message}`); 161} 162``` 163 164### createCalendar 165 166createCalendar(calendarAccount: CalendarAccount): Promise\<Calendar> 167 168Creates a **Calendar** object based on the calendar account information. This API uses a promise to return the result. 169 170**Required permissions**: ohos.permission.WRITE_CALENDAR 171 172**System capability**: SystemCapability.Applications.CalendarData 173 174**Parameters** 175 176| Name | Type | Mandatory| Description | 177| --------------- | ----------------------------------- | ---- | -------------- | 178| calendarAccount | [CalendarAccount](#calendaraccount) | Yes | Calendar account information.| 179 180**Return value** 181 182| Type | Description | 183| ------------------------------ | ------------------------------------- | 184| Promise<[Calendar](#calendar)> | Promise used to return the created **Calendar** object.| 185 186**Error codes** 187 188For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 189 190| ID| Error Message | 191| -------- | ------------------------------ | 192| 201 | Permission denied. | 193| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 194| 801 | Capability not supported. | 195 196**Example** 197 198```typescript 199import { BusinessError } from '@kit.BasicServicesKit'; 200import { calendarMgr } from '../entryability/EntryAbility'; 201 202let calendar : calendarManager.Calendar | undefined = undefined; 203const calendarAccount: calendarManager.CalendarAccount = { 204 name: 'CreateMyCalendarByPromise', 205 type: calendarManager.CalendarType.LOCAL, 206 displayName : 'MyApplication' 207}; 208calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => { 209 console.info(`Succeeded in creating calendar data->${JSON.stringify(data)}`); 210 calendar = data; 211}).catch((error : BusinessError) => { 212 console.error(`Failed to create calendar. Code: ${error.code}, message: ${error.message}`); 213}); 214``` 215 216### deleteCalendar 217 218deleteCalendar(calendar: Calendar, callback: AsyncCallback\<void>): void 219 220Deletes a specified **Calendar** object. This API uses an asynchronous callback to return the result. 221 222**Required permissions**: ohos.permission.WRITE_CALENDAR 223 224**System capability**: SystemCapability.Applications.CalendarData 225 226**Parameters** 227 228| Name | Type | Mandatory| Description | 229| -------- | --------------------- | ---- | -------------- | 230| calendar | [Calendar](#calendar) | Yes | **Calendar** object to delete.| 231| callback | AsyncCallback\<void> | Yes | Asynchronous callback that returns no value. | 232 233**Error codes** 234 235For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 236 237| ID| Error Message | 238| -------- | ------------------------------ | 239| 201 | Permission denied. | 240| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 241| 801 | Capability not supported. | 242 243**Example** 244 245```typescript 246import { BusinessError } from '@kit.BasicServicesKit'; 247import { calendarMgr } from '../entryability/EntryAbility'; 248 249const calendarAccount: calendarManager.CalendarAccount = { 250 name: 'DeleteMyCalendarByCallBack', 251 type: calendarManager.CalendarType.LOCAL 252}; 253calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => { 254 console.info(`Succeeded in creating calendar, data -> ${JSON.stringify(data)}`); 255 calendarMgr?.getCalendar(calendarAccount, (err: BusinessError, data: calendarManager.Calendar) => { 256 if (err) { 257 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 258 } else { 259 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 260 calendarMgr?.deleteCalendar(data, (err1: BusinessError) => { 261 if (err1) { 262 console.error(`Failed to delete calendar. Code: ${err1.code}, message: ${err1.message}`); 263 } else { 264 console.info("Succeeded in deleting calendar"); 265 } 266 }); 267 } 268 }); 269}).catch((error: BusinessError) => { 270 console.error(`Failed to create calendar. Code: ${error.code}, message: ${error.message}`); 271}) 272``` 273 274### deleteCalendar 275 276deleteCalendar(calendar: Calendar): Promise\<void> 277 278Deletes a specified **Calendar** object. This API uses a promise to return the result. 279 280**Required permissions**: ohos.permission.WRITE_CALENDAR 281 282**System capability**: SystemCapability.Applications.CalendarData 283 284**Parameters** 285 286| Name | Type | Mandatory| Description | 287| -------- | --------------------- | ---- | -------------- | 288| calendar | [Calendar](#calendar) | Yes | **Calendar** object to delete.| 289 290**Return value** 291 292| Type | Description | 293| -------------- | ------------------------- | 294| Promise\<void> | Promise that returns no value.| 295 296**Error codes** 297 298For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 299 300| ID| Error Message | 301| -------- | ------------------------------ | 302| 201 | Permission denied. | 303| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 304| 801 | Capability not supported. | 305 306**Example** 307 308```typescript 309import { BusinessError } from '@kit.BasicServicesKit'; 310import { calendarMgr } from '../entryability/EntryAbility'; 311 312const calendarAccount: calendarManager.CalendarAccount = { 313 name: 'DeleteMyCalendarByPromise', 314 type: calendarManager.CalendarType.LOCAL 315}; 316calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => { 317 console.info(`Succeeded in creating calendar, data -> ${JSON.stringify(data)}`); 318 calendarMgr?.getCalendar(calendarAccount).then((data: calendarManager.Calendar) => { 319 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 320 calendarMgr?.deleteCalendar(data).then(() => { 321 console.info("Succeeded in deleting calendar"); 322 }).catch((err: BusinessError) => { 323 console.error(`Failed to delete calendar. Code: ${err.code}, message: ${err.message}`); 324 }); 325 }).catch((err: BusinessError) => { 326 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 327 }); 328}).catch((error: BusinessError) => { 329 console.error(`Failed to create calendar. Code: ${error.code}, message: ${error.message}`); 330}) 331``` 332 333### getCalendar 334 335getCalendar(callback: AsyncCallback\<Calendar>): void 336 337Obtains 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. 338 339**Required permissions**: ohos.permission.READ_CALENDAR 340 341**Atomic service API**: This API can be used in atomic services since API version 11. 342 343**System capability**: SystemCapability.Applications.CalendarData 344 345**Parameters** 346 347| Name | Type | Mandatory| Description | 348| -------- | ------------------------------------ | ---- | ------------------------------------ | 349| callback | AsyncCallback<[Calendar](#calendar)> | Yes | Callback used to return the obtained **Calendar** object.| 350 351**Error codes** 352 353For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 354 355| ID| Error Message | 356| -------- | ------------------------------ | 357| 201 | Permission denied. | 358| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 359| 801 | Capability not supported. | 360 361**Example** 362 363```typescript 364import { BusinessError } from '@kit.BasicServicesKit'; 365import { calendarMgr } from '../entryability/EntryAbility'; 366 367let calendar : calendarManager.Calendar | undefined = undefined; 368calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 369 if (err) { 370 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 371 } else { 372 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 373 calendar = data; 374 } 375}); 376``` 377 378### getCalendar 379 380getCalendar(calendarAccount: CalendarAccount, callback: AsyncCallback\<Calendar>): void 381 382Obtains a specified **Calendar** object. This API uses an asynchronous callback to return the result. 383 384**Required permissions**: ohos.permission.READ_CALENDAR 385 386**Atomic service API**: This API can be used in atomic services since API version 11. 387 388**System capability**: SystemCapability.Applications.CalendarData 389 390**Parameters** 391 392| Name | Type | Mandatory| Description | 393| --------------- | ------------------------------------ | ---- | ------------------------------------ | 394| calendarAccount | [CalendarAccount](#calendaraccount) | Yes | Calendar account information. | 395| callback | AsyncCallback<[Calendar](#calendar)> | Yes | Callback used to return the obtained **Calendar** object.| 396 397**Error codes** 398 399For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 400 401| ID| Error Message | 402| -------- | ------------------------------ | 403| 201 | Permission denied. | 404| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 405| 801 | Capability not supported. | 406 407**Example** 408 409```typescript 410import { BusinessError } from '@kit.BasicServicesKit'; 411import { calendarMgr } from '../entryability/EntryAbility'; 412 413let calendar : calendarManager.Calendar | undefined = undefined; 414const calendarAccount: calendarManager.CalendarAccount = { 415 name: 'MyCalendar', 416 type: calendarManager.CalendarType.LOCAL 417}; 418calendarMgr?.createCalendar(calendarAccount).then((data: calendarManager.Calendar) => { 419 console.info(`Succeeded in creating calendar, data -> ${JSON.stringify(data)}`); 420 calendarMgr?.getCalendar(calendarAccount, (err: BusinessError, data: calendarManager.Calendar) => { 421 if (err) { 422 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 423 } else { 424 console.info(`Succeeded in getting calendar data -> ${JSON.stringify(data)}`); 425 calendar = data; 426 } 427 }); 428}).catch((error: BusinessError) => { 429 console.error(`Failed to create calendar. Code: ${error.code}, message: ${error.message}`); 430}) 431``` 432 433### getCalendar 434 435getCalendar(calendarAccount?: CalendarAccount): Promise\<Calendar> 436 437Obtains the default **Calendar** object or a specified **Calendar** object. This API uses a promise to return the result. 438 439**Required permissions**: ohos.permission.READ_CALENDAR 440 441**Atomic service API**: This API can be used in atomic services since API version 11. 442 443**System capability**: SystemCapability.Applications.CalendarData 444 445**Parameters** 446 447| Name | Type | Mandatory| Description | 448| --------------- | ----------------------------------- | ---- | ------------------------------------------------------------ | 449| 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.| 450 451**Return value** 452 453| Type | Description | 454| ------------------------------ | --------------------------------------- | 455| Promise<[Calendar](#calendar)> | Promise used to return the obtained **Calendar** object.| 456 457**Error codes** 458 459For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 460 461| ID| Error Message | 462| -------- | ------------------------------ | 463| 201 | Permission denied. | 464| 401 | Parameter error. Possible causes: Incorrect parameter types. | 465| 801 | Capability not supported. | 466 467**Example** 468 469```typescript 470import { BusinessError } from '@kit.BasicServicesKit'; 471import { calendarMgr } from '../entryability/EntryAbility'; 472 473let calendar : calendarManager.Calendar | undefined = undefined; 474calendarMgr?.getCalendar().then((data: calendarManager.Calendar) => { 475 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 476 calendar = data; 477}).catch((err: BusinessError) => { 478 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 479}); 480``` 481 482### getAllCalendars 483 484getAllCalendars(callback: AsyncCallback\<Calendar[]>): void 485 486Obtains the created and default **Calendar** objects of the current application. This API uses an asynchronous callback to return the result. 487 488**Required permissions**: ohos.permission.READ_CALENDAR 489 490**System capability**: SystemCapability.Applications.CalendarData 491 492**Parameters** 493 494| Name | Type | Mandatory| Description | 495| -------- | -------------------------------------- | ---- | ----------------------------------------- | 496| callback | AsyncCallback<[Calendar](#calendar)[]> | Yes | Callback used to return an array of the obtained **Calendar** objects.| 497 498**Error codes** 499 500For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 501 502| ID| Error Message | 503| -------- | ------------------------------ | 504| 201 | Permission denied. | 505| 401 | Parameter error. Possible causes: 1. Mandatory parameters are left unspecified; 2. Incorrect parameter types. | 506| 801 | Capability not supported. | 507 508**Example** 509 510```typescript 511import { BusinessError } from '@kit.BasicServicesKit'; 512import { calendarMgr } from '../entryability/EntryAbility'; 513 514calendarMgr?.getAllCalendars((err: BusinessError, data: calendarManager.Calendar[]) => { 515 if (err) { 516 console.error(`Failed to get all calendars. Code: ${err.code}, message: ${err.message}`); 517 } else { 518 console.info(`Succeeded in getting all calendars, data -> ${JSON.stringify(data)}`); 519 data.forEach((calendar) => { 520 const account = calendar.getAccount(); 521 console.info(`account -> ${JSON.stringify(account)}`); 522 }) 523 } 524}); 525``` 526 527### getAllCalendars 528 529getAllCalendars(): Promise\<Calendar[]> 530 531Obtains the created and default **Calendar** objects of the current application. This API uses a promise to return the result. 532 533**Required permissions**: ohos.permission.READ_CALENDAR 534 535**System capability**: SystemCapability.Applications.CalendarData 536 537**Return value** 538 539| Type | Description | 540| -------------------------------- | ------------------------------------------- | 541| Promise<[Calendar](#calendar)[]> | Promise used to return an array of obtained **Calendar** objects.| 542 543**Error codes** 544 545For details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 546 547| ID| Error Message | 548| -------- | ------------------------------ | 549| 201 | Permission denied. | 550| 401 | Parameter error. Possible causes: Incorrect parameter types. | 551| 801 | Capability not supported. | 552 553**Example** 554 555```typescript 556import { BusinessError } from '@kit.BasicServicesKit'; 557import { calendarMgr } from '../entryability/EntryAbility'; 558 559calendarMgr?.getAllCalendars().then((data: calendarManager.Calendar[]) => { 560 console.info(`Succeeded in getting all calendars, data -> ${JSON.stringify(data)}`); 561 data.forEach((calendar) => { 562 const account = calendar.getAccount(); 563 console.info(`account -> ${JSON.stringify(account)}`); 564 }) 565}).catch((err: BusinessError) => { 566 console.error(`Failed to get all calendars. Code: ${err.code}, message: ${err.message}`); 567}); 568``` 569 570### editEvent<sup>12+</sup> 571 572editEvent(event: Event): Promise\<number> 573 574Creates a single event. If the input parameter **Event** is not set to the event ID, the event creation screen is displayed when this API is called. This API uses a promise to return the result. Events created using this API cannot be queried or modified by third-party applications, but only by the system calendar. 575 576**Atomic service API**: This API can be used in atomic services since API version 12. 577 578**System capability**: SystemCapability.Applications.CalendarData 579 580**Parameters** 581 582| Name| Type | Mandatory| Description | 583| ------ | --------------- | ---- | ----------- | 584| event | [Event](#event) | Yes | **Event** object.| 585 586**Return value** 587 588| Type | Description | 589| -------------- |-----------------------------------------------------------------------------| 590| Promise<number> | Promise used to return the event ID. The event ID is the unique identifier of an event and is the auto-increment primary key of the database. If the event creation fails, no value is returned; if the value is less than **0**, the event creation is canceled; if the value is greater than **0**, the event creation is successful. The return value cannot be **0**| 591 592**Example** 593 594```typescript 595import { BusinessError } from '@kit.BasicServicesKit'; 596import { calendarMgr } from '../entryability/EntryAbility'; 597 598const date = new Date(); 599const event: calendarManager.Event = { 600 title: 'title', 601 type: calendarManager.EventType.NORMAL, 602 startTime: date.getTime(), 603 endTime: date.getTime() + 60 * 60 * 1000 604}; 605calendarMgr?.editEvent(event).then((eventId: number): void => { 606 console.info(`create Event id = ${eventId}`); 607}).catch((err: BusinessError) => { 608 console.error(`Failed to create Event. Code: ${err.code}, message: ${err.message}`); 609}); 610``` 611 612## Calendar 613 614In the following API examples, you need to use [createCalendar()](#createcalendar) or [getCalendar()](#getcalendar) to obtain a **Calendar** object before calling related APIs. 615 616### Attributes 617 618**Atomic service API**: This API can be used in atomic services since API version 11. 619 620**System capability**: SystemCapability.Applications.CalendarData 621 622| Name| Type | Read Only| Optional| Description | 623| ---- | ------ | ---- |----|--------------------------------------------------------------------------| 624| id | number | Yes | No | Calendar account ID, which is the unique identifier of a calendar account and is the auto-increment primary key of the database. If the value is less than **0**, the account creation fails; if the value is greater than **0**, the account creation succeeds.| 625 626### addEvent 627 628addEvent(event: Event, callback: AsyncCallback\<number>): void 629 630Creates an event, with no event ID specified in **Event**. This API uses an asynchronous callback to return the result. 631 632**Atomic service API**: This API can be used in atomic services since API version 11. 633 634**System capability**: SystemCapability.Applications.CalendarData 635 636**Parameters** 637 638| Name | Type | Mandatory| Description | 639| -------- | ---------------------- | ---- |-----------------------------------------------------------------------| 640| event | [Event](#event) | Yes | **Event** object. | 641| callback | AsyncCallback\<number> | Yes | Callback used to return the event ID. The event ID is the unique identifier of the event and is the auto-increment primary key of the database. If the value is less than **0**, the event creation fails; if the value is greater than **0**, the event creation succeeds.| 642 643**Example** 644 645```typescript 646import { BusinessError } from '@kit.BasicServicesKit'; 647import { calendarMgr } from '../entryability/EntryAbility'; 648 649let calendar : calendarManager.Calendar | undefined = undefined; 650const date = new Date(); 651const event: calendarManager.Event = { 652 type: calendarManager.EventType.NORMAL, 653 startTime: date.getTime(), 654 endTime: date.getTime() + 60 * 60 * 1000 655}; 656calendarMgr?.getCalendar().then((data: calendarManager.Calendar) => { 657 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 658 calendar = data; 659 calendar.addEvent(event, (err: BusinessError, data: number): void => { 660 if (err) { 661 console.error(`Failed to addEvent. Code: ${err.code}, message: ${err.message}`); 662 } else { 663 console.info(`Succeeded in adding event, id -> ${data}`); 664 } 665 }); 666}).catch((err: BusinessError) => { 667 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 668}); 669``` 670 671### addEvent 672 673addEvent(event: Event): Promise\<number> 674 675Creates an event, with no event ID specified in **Event**. This API uses a promise to return the result. 676 677**Atomic service API**: This API can be used in atomic services since API version 11. 678 679**System capability**: SystemCapability.Applications.CalendarData 680 681**Parameters** 682 683| Name| Type | Mandatory| Description | 684| ------ | --------------- | ---- | ----------- | 685| event | [Event](#event) | Yes | **Event** object.| 686 687**Return value** 688 689| Type | Description | 690| ---------------- | --------------------------- | 691| Promise\<number> | Promise used to return the event ID.| 692 693**Example** 694 695```typescript 696import { BusinessError } from '@kit.BasicServicesKit'; 697import { calendarMgr } from '../entryability/EntryAbility'; 698 699let calendar : calendarManager.Calendar | undefined = undefined; 700const date = new Date(); 701const event: calendarManager.Event = { 702 type: calendarManager.EventType.NORMAL, 703 startTime: date.getTime(), 704 endTime: date.getTime() + 60 * 60 * 1000 705}; 706calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 707 if (err) { 708 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 709 } else { 710 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 711 calendar = data; 712 calendar.addEvent(event).then((data: number) => { 713 console.info(`Succeeded in adding event, id -> ${data}`); 714 }).catch((err: BusinessError) => { 715 console.error(`Failed to addEvent. Code: ${err.code}, message: ${err.message}`); 716 }); 717 } 718}); 719``` 720 721### addEvents 722 723addEvents(events: Event[], callback: AsyncCallback\<void>): void 724 725Creates events in batches, with no event ID specified in **Event**. This API uses an asynchronous callback to return the result. 726 727**System capability**: SystemCapability.Applications.CalendarData 728 729**Parameters** 730 731| Name | Type | Mandatory| Description | 732| -------- | -------------------- | ---- | --------------- | 733| events | [Event](#event)[] | Yes | Array of **Event** objects.| 734| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 735 736**Example** 737 738```typescript 739import { BusinessError } from '@kit.BasicServicesKit'; 740import { calendarMgr } from '../entryability/EntryAbility'; 741 742let calendar : calendarManager.Calendar | undefined = undefined; 743const date = new Date(); 744const events: calendarManager.Event[] = [ 745 { 746 type: calendarManager.EventType.NORMAL, 747 startTime: date.getTime(), 748 endTime: date.getTime() + 60 * 60 * 1000 749 }, 750 { 751 type: calendarManager.EventType.NORMAL, 752 startTime: date.getTime(), 753 endTime: date.getTime() + 60 * 60 * 1000 754 } 755]; 756calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 757 if (err) { 758 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 759 } else { 760 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 761 calendar = data; 762 calendar.addEvents(events, (err: BusinessError) => { 763 if (err) { 764 console.error(`Failed to add events. Code: ${err.code}, message: ${err.message}`); 765 } else { 766 console.info("Succeeded in adding events"); 767 } 768 }); 769 } 770}); 771``` 772 773### addEvents 774 775addEvents(events: Event[]): Promise\<void> 776 777Creates events in batches, with no event ID specified in **Event**. This API uses a promise to return the result. 778 779**System capability**: SystemCapability.Applications.CalendarData 780 781**Parameters** 782 783| Name| Type | Mandatory| Description | 784| ------ | ----------------- | ---- | --------------- | 785| events | [Event](#event)[] | Yes | Array of **Event** objects.| 786 787**Return value** 788 789| Type | Description | 790| -------------- | ------------------------- | 791| Promise\<void> | Promise that returns no value.| 792 793**Example** 794 795```typescript 796import { BusinessError } from '@kit.BasicServicesKit'; 797import { calendarMgr } from '../entryability/EntryAbility'; 798 799let calendar : calendarManager.Calendar | undefined = undefined; 800const date = new Date(); 801const events: calendarManager.Event[] = [ 802 { 803 type: calendarManager.EventType.NORMAL, 804 startTime: date.getTime(), 805 endTime: date.getTime() + 60 * 60 * 1000 806 }, 807 { 808 type: calendarManager.EventType.NORMAL, 809 startTime: date.getTime(), 810 endTime: date.getTime() + 60 * 60 * 1000 811 } 812]; 813calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 814 if (err) { 815 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 816 } else { 817 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 818 calendar = data; 819 calendar.addEvents(events).then(() => { 820 console.info("Succeeded in adding events"); 821 }).catch((err: BusinessError) => { 822 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 823 }); 824 } 825}); 826``` 827 828### deleteEvent 829 830deleteEvent(id: number, callback: AsyncCallback\<void>): void 831 832Deletes an event with the specified ID. This API uses an asynchronous callback to return the result. 833 834**System capability**: SystemCapability.Applications.CalendarData 835 836**Parameters** 837 838| Name | Type | Mandatory| Description | 839| -------- | -------------------- | ---- |----------------------------------------| 840| id | number | Yes | Event ID, which is the unique identifier of an event. If the input event ID is a positive integer, the event is created.| 841| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 842 843**Example** 844 845```typescript 846import { BusinessError } from '@kit.BasicServicesKit'; 847import { calendarMgr } from '../entryability/EntryAbility'; 848 849let calendar : calendarManager.Calendar | undefined = undefined; 850let id: number = 0; 851const date = new Date(); 852const event: calendarManager.Event = { 853 type: calendarManager.EventType.NORMAL, 854 startTime: date.getTime(), 855 endTime: date.getTime() + 60 * 60 * 1000 856}; 857calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 858 if (err) { 859 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 860 } else { 861 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 862 calendar = data; 863 calendar.addEvent(event).then((data: number) => { 864 console.info(`Succeeded in adding event, id -> ${data}`); 865 id = data; 866 calendar?.deleteEvent(id, (err: BusinessError) => { 867 if (err) { 868 console.error(`Failed to delete event. Code: ${err.code}, message: ${err.message}`); 869 } else { 870 console.info(`Succeeded in deleting event, err -> ${JSON.stringify(err)}`); 871 } 872 }); 873 }).catch((err: BusinessError) => { 874 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 875 }); 876 } 877}); 878``` 879 880### deleteEvent 881 882deleteEvent(id: number): Promise\<void> 883 884Deletes an event with the specified ID. This API uses a promise to return the result. 885 886**System capability**: SystemCapability.Applications.CalendarData 887 888**Parameters** 889 890| Name| Type | Mandatory| Description | 891| ------ | ------ | ---- | -------- | 892| id | number | Yes | Event ID.| 893 894**Return value** 895 896| Type | Description | 897| -------------- | ------------------------- | 898| Promise\<void> | Promise that returns no value.| 899 900**Example** 901 902```typescript 903import { BusinessError } from '@kit.BasicServicesKit'; 904import { calendarMgr } from '../entryability/EntryAbility'; 905 906let calendar : calendarManager.Calendar | undefined = undefined; 907let id: number = 0; 908const date = new Date(); 909const event: calendarManager.Event = { 910 type: calendarManager.EventType.NORMAL, 911 startTime: date.getTime(), 912 endTime: date.getTime() + 60 * 60 * 1000 913}; 914calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 915 if (err) { 916 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 917 } else { 918 console.info(`Succeeded in getting calendar data->${JSON.stringify(data)}`); 919 calendar = data; 920 await calendar.addEvent(event).then((data: number) => { 921 console.info(`Succeeded in adding event, id -> ${data}`); 922 id = data; 923 }).catch((err: BusinessError) => { 924 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 925 }); 926 calendar.deleteEvent(id).then(() => { 927 console.info("Succeeded in deleting event"); 928 }).catch((err: BusinessError) => { 929 console.error(`Failed to delete event. Code: ${err.code}, message: ${err.message}`); 930 }); 931 } 932}); 933``` 934 935### deleteEvents 936 937deleteEvents(ids: number[], callback: AsyncCallback\<void>): void 938 939Deletes a batch of events with the specified IDs. This API uses an asynchronous callback to return the result. 940 941**System capability**: SystemCapability.Applications.CalendarData 942 943**Parameters** 944 945| Name | Type | Mandatory| Description | 946| -------- | -------------------- | ---- | ------------ | 947| ids | number[] | Yes | Array of event IDs.| 948| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 949 950**Example** 951 952```typescript 953import { BusinessError } from '@kit.BasicServicesKit'; 954import { calendarMgr } from '../entryability/EntryAbility'; 955 956let calendar : calendarManager.Calendar | undefined = undefined; 957let id1: number = 0; 958let id2: number = 0; 959const date = new Date(); 960const event1: calendarManager.Event = { 961 type: calendarManager.EventType.NORMAL, 962 startTime: date.getTime(), 963 endTime: date.getTime() + 60 * 60 * 1000 964}; 965const event2: calendarManager.Event = { 966 type: calendarManager.EventType.IMPORTANT, 967 startTime: date.getTime(), 968 endTime: date.getTime() + 60 * 60 * 1000 969}; 970calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 971 if (err) { 972 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 973 } else { 974 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 975 calendar = data; 976 await calendar.addEvent(event1).then((data: number) => { 977 console.info(`Succeeded in adding event, id -> ${data}`); 978 id1 = data; 979 }).catch((err: BusinessError) => { 980 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 981 }); 982 await calendar.addEvent(event2).then((data: number) => { 983 console.info(`Succeeded in adding event, id -> ${data}`); 984 id2 = data; 985 }).catch((err: BusinessError) => { 986 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 987 }); 988 calendar.deleteEvents([id1, id2], (err: BusinessError) => { 989 if (err) { 990 console.error(`Failed to delete events. Code: ${err.code}, message: ${err.message}`); 991 } else { 992 console.info("Succeeded in deleting events"); 993 } 994 }); 995 } 996}); 997``` 998 999### deleteEvents 1000 1001deleteEvents(ids: number[]): Promise\<void> 1002 1003Deletes a batch of events with the specified IDs. This API uses a promise to return the result. 1004 1005**System capability**: SystemCapability.Applications.CalendarData 1006 1007**Parameters** 1008 1009| Name| Type | Mandatory| Description | 1010| ------ | -------- | ---- | ------------ | 1011| ids | number[] | Yes | Array of event IDs.| 1012 1013**Return value** 1014 1015| Type | Description | 1016| -------------- | ------------------------- | 1017| Promise\<void> | Promise that returns no value.| 1018 1019**Example** 1020 1021```typescript 1022import { BusinessError } from '@kit.BasicServicesKit'; 1023import { calendarMgr } from '../entryability/EntryAbility'; 1024 1025let calendar : calendarManager.Calendar | undefined = undefined; 1026let id1: number = 0; 1027let id2: number = 0; 1028const date = new Date(); 1029const event1: calendarManager.Event = { 1030 type: calendarManager.EventType.NORMAL, 1031 startTime: date.getTime(), 1032 endTime: date.getTime() + 60 * 60 * 1000 1033}; 1034const event2: calendarManager.Event = { 1035 type: calendarManager.EventType.IMPORTANT, 1036 startTime: date.getTime(), 1037 endTime: date.getTime() + 60 * 60 * 1000 1038}; 1039calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1040 if (err) { 1041 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1042 } else { 1043 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1044 calendar = data; 1045 await calendar.addEvent(event1).then((data: number) => { 1046 console.info(`Succeeded in adding event, id -> ${data}`); 1047 id1 = data; 1048 }).catch((err: BusinessError) => { 1049 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1050 }); 1051 await calendar.addEvent(event2).then((data: number) => { 1052 console.info(`Succeeded in adding event, id -> ${data}`); 1053 id2 = data; 1054 }).catch((err: BusinessError) => { 1055 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1056 }); 1057 calendar.deleteEvents([id1, id2]).then(() => { 1058 console.info("Succeeded in deleting events"); 1059 }).catch((err: BusinessError) => { 1060 console.error(`Failed to delete events. Code: ${err.code}, message: ${err.message}`); 1061 }); 1062 } 1063}); 1064``` 1065 1066### updateEvent 1067 1068updateEvent(event: Event, callback: AsyncCallback\<void>): void 1069 1070Updates an event. This API uses an asynchronous callback to return the result. 1071 1072**System capability**: SystemCapability.Applications.CalendarData 1073 1074**Parameters** 1075 1076| Name | Type | Mandatory| Description | 1077| -------- | -------------------- | ---- | ----------- | 1078| event | [Event](#event) | Yes | **Event** object.| 1079| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 1080 1081**Example** 1082 1083```typescript 1084import { BusinessError } from '@kit.BasicServicesKit'; 1085import { calendarMgr } from '../entryability/EntryAbility'; 1086 1087let calendar : calendarManager.Calendar | undefined = undefined; 1088const date = new Date(); 1089const oriEvent: calendarManager.Event = { 1090 title: 'update', 1091 type: calendarManager.EventType.NORMAL, 1092 description: 'updateEventTest', 1093 startTime: date.getTime(), 1094 endTime: date.getTime() + 60 * 60 * 1000 1095}; 1096calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1097 if (err) { 1098 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1099 } else { 1100 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1101 calendar = data; 1102 await calendar.addEvent(oriEvent).then((data: number) => { 1103 console.info(`Succeeded in adding event, id -> ${data}`); 1104 oriEvent.id = data; 1105 oriEvent.title = 'newUpdate'; 1106 }).catch((err: BusinessError) => { 1107 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1108 }); 1109 calendar.updateEvent(oriEvent, (err: BusinessError) => { 1110 if (err) { 1111 console.error(`Failed to update event. Code: ${err.code}, message: ${err.message}`); 1112 } else { 1113 console.info("Succeeded in updating event"); 1114 } 1115 }); 1116 } 1117}); 1118``` 1119 1120### updateEvent 1121 1122updateEvent(event: Event): Promise\<void> 1123 1124Updates an event. This API uses a promise to return the result. 1125 1126**System capability**: SystemCapability.Applications.CalendarData 1127 1128**Parameters** 1129 1130| Name| Type | Mandatory| Description | 1131| ------ | --------------- | ---- | ----------- | 1132| event | [Event](#event) | Yes | **Event** object.| 1133 1134**Return value** 1135 1136| Type | Description | 1137| -------------- | ------------------------- | 1138| Promise\<void> | Promise that returns no value.| 1139 1140**Example** 1141 1142```typescript 1143import { BusinessError } from '@kit.BasicServicesKit'; 1144import { calendarMgr } from '../entryability/EntryAbility'; 1145 1146let calendar : calendarManager.Calendar | undefined = undefined; 1147const date = new Date(); 1148const oriEvent: calendarManager.Event = { 1149 title: 'update', 1150 type: calendarManager.EventType.NORMAL, 1151 description: 'updateEventTest', 1152 startTime: date.getTime(), 1153 endTime: date.getTime() + 60 * 60 * 1000 1154}; 1155calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1156 if (err) { 1157 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1158 } else { 1159 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1160 calendar = data; 1161 await calendar.addEvent(oriEvent).then((data: number) => { 1162 console.info(`Succeeded in adding event, id -> ${data}`); 1163 oriEvent.id = data; 1164 oriEvent.title = 'newUpdate'; 1165 }).catch((err: BusinessError) => { 1166 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1167 }); 1168 calendar.updateEvent(oriEvent).then(() => { 1169 console.info(`Succeeded in updating event`); 1170 }).catch((err: BusinessError) => { 1171 console.error(`Failed to update event. Code: ${err.code}, message: ${err.message}`); 1172 }); 1173 } 1174}); 1175``` 1176 1177### getEvents 1178 1179getEvents(callback: AsyncCallback\<Event[]>): void 1180 1181Obtains all events in the current calendar. 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| callback | AsyncCallback<[Event](#event)[]> | Yes | Callback used to return an array of events.| 1190 1191**Example** 1192 1193```typescript 1194import { BusinessError } from '@kit.BasicServicesKit'; 1195import { calendarMgr } from '../entryability/EntryAbility'; 1196 1197let calendar : calendarManager.Calendar | undefined = undefined; 1198calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 1199 if (err) { 1200 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1201 } else { 1202 console.info(`Succeeded in getting calendar data -> ${JSON.stringify(data)}`); 1203 calendar = data; 1204 calendar.getEvents((err: BusinessError, data: calendarManager.Event[]) => { 1205 if (err) { 1206 console.error(`Failed to get events. Code: ${err.code}, message: ${err.message}`); 1207 } else { 1208 console.info(`Succeeded in getting events, data -> ${JSON.stringify(data)}`); 1209 } 1210 }); 1211 } 1212}); 1213``` 1214 1215### getEvents 1216 1217getEvents(eventFilter: EventFilter, eventKey: (keyof Event)[], callback: AsyncCallback\<Event[]>):void 1218 1219Obtains all events in a calendar that match the filter criteria. This API uses an asynchronous callback to return the result. 1220 1221**System capability**: SystemCapability.Applications.CalendarData 1222 1223**Parameters** 1224 1225| Name | Type | Mandatory| Description | 1226| ----------- | -------------------------------- | ---- | --------------------------------- | 1227| eventFilter | [EventFilter](#eventfilter) | Yes | Filter criteria. | 1228| eventKey | (keyof [Event](#event))[] | Yes | Filter field. | 1229| callback | AsyncCallback<[Event](#event)[]> | Yes | Callback used to return an array of events.| 1230 1231**Example** 1232 1233```typescript 1234import { BusinessError } from '@kit.BasicServicesKit'; 1235import { calendarMgr } from '../entryability/EntryAbility'; 1236 1237let calendar : calendarManager.Calendar | undefined = undefined; 1238let id1: number = 0; 1239let id2: number = 0; 1240const date = new Date(); 1241const event1: calendarManager.Event = { 1242 type: calendarManager.EventType.NORMAL, 1243 startTime: date.getTime(), 1244 endTime: date.getTime() + 60 * 60 * 1000 1245}; 1246const event2: calendarManager.Event = { 1247 type: calendarManager.EventType.IMPORTANT, 1248 startTime: date.getTime(), 1249 endTime: date.getTime() + 60 * 60 * 1000 1250}; 1251calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1252 if (err) { 1253 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1254 } else { 1255 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1256 calendar = data; 1257 await calendar.addEvent(event1).then((data: number) => { 1258 console.info(`Succeeded in adding event, id -> ${data}`); 1259 }).catch((err: BusinessError) => { 1260 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1261 }); 1262 await calendar.addEvent(event2).then((data: number) => { 1263 console.info(`Succeeded in adding event, id -> ${data}`); 1264 }).catch((err: BusinessError) => { 1265 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1266 }); 1267 const filter = calendarManager.EventFilter.filterById([id1, id2]); 1268 calendar.getEvents(filter, ['title', 'type', 'startTime', 'endTime'], (err: BusinessError, data: calendarManager.Event[]) => { 1269 if (err) { 1270 console.error(`Failed to get events. Code: ${err.code}, message: ${err.message}`); 1271 } else { 1272 console.info(`Succeeded in getting events, data -> ${JSON.stringify(data)}`); 1273 } 1274 }); 1275 } 1276}); 1277``` 1278 1279### getEvents 1280 1281getEvents(eventFilter?: EventFilter, eventKey?: (keyof Event)[]): Promise\<Event[]> 1282 1283Obtains all events in a calendar that match the filter criteria. This API uses a promise to return the result. 1284If there is only one input parameter, the filter criteria, corresponding to the type **EventFilter**, must be set as the parameter. 1285 1286**System capability**: SystemCapability.Applications.CalendarData 1287 1288**Parameters** 1289 1290| Name | Type | Mandatory| Description | 1291| ----------- | --------------------------- | ---- | ---------- | 1292| eventFilter | [EventFilter](#eventfilter) | No | Filter criteria.| 1293| eventKey | (keyof [Event](#event))[] | No | Filter field.| 1294 1295**Return value** 1296 1297| Type | Description | 1298| -------------------------- | ----------------------------------- | 1299| Promise<[Event](#event)[]> | Promise used to return the result, which is an array of **Event** objects.| 1300 1301**Example** 1302 1303```typescript 1304import { BusinessError } from '@kit.BasicServicesKit'; 1305import { calendarMgr } from '../entryability/EntryAbility'; 1306 1307let calendar : calendarManager.Calendar | undefined = undefined; 1308const date = new Date(); 1309const event: calendarManager.Event = { 1310 title: 'MyEvent', 1311 type: calendarManager.EventType.IMPORTANT, 1312 startTime: date.getTime(), 1313 endTime: date.getTime() + 60 * 60 * 1000 1314}; 1315calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1316 if (err) { 1317 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1318 } else { 1319 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1320 calendar = data; 1321 await calendar.addEvent(event).then((data: number) => { 1322 console.info(`Succeeded in adding event, id -> ${data}`); 1323 }).catch((err: BusinessError) => { 1324 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1325 }); 1326 // Perform fuzzy query based on MyEvent. If an event of the MyEvent1 type exists, the event can also be queried. 1327 const filter = calendarManager.EventFilter.filterByTitle('MyEvent'); 1328 calendar.getEvents(filter).then((data: calendarManager.Event[]) => { 1329 console.info(`Succeeded in getting events, data -> ${JSON.stringify(data)}`); 1330 }).catch((err: BusinessError) => { 1331 console.error(`Failed to get events. Code: ${err.code}, message: ${err.message}`); 1332 }); 1333 } 1334}); 1335``` 1336 1337### getConfig 1338 1339getConfig(): CalendarConfig 1340 1341Obtains the calendar configuration information. 1342 1343**System capability**: SystemCapability.Applications.CalendarData 1344 1345**Return value** 1346 1347| Type | Description | 1348| --------------------------------- | -------------- | 1349| [CalendarConfig](#calendarconfig) | Calendar configuration information.| 1350 1351**Example** 1352 1353```typescript 1354import { calendarMgr } from '../entryability/EntryAbility'; 1355import { BusinessError } from '@kit.BasicServicesKit'; 1356 1357let calendar : calendarManager.Calendar | undefined = undefined; 1358calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 1359 if (err) { 1360 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1361 } else { 1362 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1363 calendar = data; 1364 const config = calendar.getConfig(); 1365 console.info("Succeeded in getting config"); 1366 } 1367}); 1368``` 1369 1370### setConfig 1371 1372setConfig(config: CalendarConfig, callback: AsyncCallback\<void>): void 1373 1374Sets the calendar configuration information. This API uses an asynchronous callback to return the result. 1375 1376**System capability**: SystemCapability.Applications.CalendarData 1377 1378**Parameters** 1379 1380| Name | Type | Mandatory| Description | 1381| -------- | --------------------------------- | ---- | -------------- | 1382| config | [CalendarConfig](#calendarconfig) | Yes | Calendar configuration information.| 1383| callback | AsyncCallback\<void> | Yes | Callback used to return the result. | 1384 1385**Example** 1386 1387```typescript 1388import { BusinessError } from '@kit.BasicServicesKit'; 1389import { calendarMgr } from '../entryability/EntryAbility'; 1390 1391let calendar : calendarManager.Calendar | undefined = undefined; 1392const config: calendarManager.CalendarConfig = { 1393 enableReminder: true, 1394 color: '#aabbcc' 1395}; 1396calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 1397 if (err) { 1398 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1399 } else { 1400 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1401 calendar = data; 1402 calendar.setConfig(config, (err: BusinessError) => { 1403 if (err) { 1404 console.error(`Failed to set config. Code: ${err.code}, message: ${err.message}`); 1405 } else { 1406 console.info(`Succeeded in setting config, config -> ${JSON.stringify(config)}`); 1407 } 1408 }); 1409 } 1410}); 1411``` 1412 1413### setConfig 1414 1415setConfig(config: CalendarConfig): Promise\<void> 1416 1417Sets the calendar configuration information. This API uses a promise to return the result. 1418 1419**System capability**: SystemCapability.Applications.CalendarData 1420 1421**Parameters** 1422 1423| Name| Type | Mandatory| Description | 1424| ------ | --------------------------------- | ---- | -------------- | 1425| config | [CalendarConfig](#calendarconfig) | Yes | Calendar configuration information.| 1426 1427**Return value** 1428 1429| Type | Description | 1430| -------------- | ------------------------- | 1431| Promise\<void> | Promise that returns no value.| 1432 1433**Example** 1434 1435```typescript 1436import { BusinessError } from '@kit.BasicServicesKit'; 1437import { calendarMgr } from '../entryability/EntryAbility'; 1438 1439let calendar : calendarManager.Calendar | undefined = undefined; 1440const config: calendarManager.CalendarConfig = { 1441 enableReminder: true, 1442 color: '#aabbcc' 1443}; 1444calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 1445 if (err) { 1446 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1447 } else { 1448 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1449 calendar = data; 1450 calendar.setConfig(config).then(() => { 1451 console.info(`Succeeded in setting config, data->${JSON.stringify(config)}`); 1452 }).catch((err: BusinessError) => { 1453 console.error(`Failed to set config. Code: ${err.code}, message: ${err.message}`); 1454 }); 1455 } 1456}); 1457``` 1458 1459### getAccount 1460 1461getAccount(): CalendarAccount 1462 1463Obtains the calendar account information. 1464 1465**System capability**: SystemCapability.Applications.CalendarData 1466 1467**Return value** 1468 1469| Type | Description | 1470| ----------------------------------- | -------------- | 1471| [CalendarAccount](#calendaraccount) | Calendar account information.| 1472 1473**Example** 1474 1475```typescript 1476import { calendarMgr } from '../entryability/EntryAbility'; 1477import { BusinessError } from '@kit.BasicServicesKit'; 1478 1479let calendar : calendarManager.Calendar | undefined = undefined; 1480calendarMgr?.getCalendar((err: BusinessError, data:calendarManager.Calendar) => { 1481 if (err) { 1482 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1483 } else { 1484 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1485 calendar = data; 1486 const account = calendar.getAccount(); 1487 console.info(`succeeded in getting account, account -> ${JSON.stringify(account)}`); 1488 } 1489}); 1490``` 1491 1492### queryEventInstances<sup>18+</sup> 1493 1494queryEventInstances(start: number, end: number, ids?: number[], eventKey?: (keyof Event)[]): Promise\<Event[]> 1495 1496Queries the event instance with a specified event key in a calendar. This API uses a promise to return the result. 1497 1498**System capability**: SystemCapability.Applications.CalendarData 1499 1500**Parameters** 1501 1502| Name | Type | Mandatory | Description | 1503| ----------- | --------------------------- |------|------------| 1504| start | number | Yes | Start time of the event. | 1505| end | number | Yes | End time of the event. | 1506| ids | number[] | No | Array of event IDs. | 1507| eventKey | (keyof [Event](#event))[] | No | Event key for querying events.| 1508 1509**Return value** 1510 1511| Type | Description | 1512| -------------------------- | ----------------------------------- | 1513| Promise<[Event](#event)[]> | Promise used to return the result, which is an array of **Event** objects.| 1514 1515**Example** 1516 1517```typescript 1518import { BusinessError } from '@kit.BasicServicesKit'; 1519import { calendarMgr } from '../entryability/EntryAbility'; 1520 1521let calendar : calendarManager.Calendar | undefined = undefined; 1522const date = new Date(); 1523const event: calendarManager.Event = { 1524 title: 'MyEvent', 1525 type: calendarManager.EventType.IMPORTANT, 1526 startTime: date.getTime(), 1527 endTime: date.getTime() + 60 * 60 * 1000 1528}; 1529calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1530 if (err) { 1531 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1532 } else { 1533 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1534 calendar = data; 1535 await calendar.addEvent(event).then((data: number) => { 1536 console.info(`Succeeded in adding event, id -> ${data}`); 1537 }).catch((err: BusinessError) => { 1538 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1539 }); 1540 calendar?.queryEventInstances(date.getTime(), date.getTime() + 60 * 60 * 1000, undefined, 1541 ["title", "startTime", "endTime", "instanceStartTime", "instanceEndTime",]).then((data: calendarManager.Event[]) => { 1542 console.info(`Succeeded in getting event instances, data -> ${JSON.stringify(data)}`); 1543 }).catch((err: BusinessError) => { 1544 console.error(`Failed to get event instances. Code: ${err.code}, message: ${err.message}`); 1545 }); 1546 } 1547}); 1548``` 1549 1550## CalendarAccount 1551 1552Describes the calendar account information. 1553 1554**Atomic service API**: This API can be used in atomic services since API version 11. 1555 1556**System capability**: SystemCapability.Applications.CalendarData 1557 1558| Name | Type | Read Only| Optional| Description | 1559| ----------- | ----------------------------- | ---- |----|----------------------------------| 1560| name | string | Yes | No | Account name (for developers). | 1561| type | [CalendarType](#calendartype) | No | No | Account type. | 1562| displayName | string | No | Yes | Account name displayed on the calendar application (for users). If this parameter is not set, an empty string is used.| 1563 1564## CalendarConfig 1565 1566Describes the calendar configuration information. 1567 1568**System capability**: SystemCapability.Applications.CalendarData 1569 1570| Name | Type | Read Only | Optional| Description | 1571| -------------- |--------|-------|----| ------------------------------------------------------------ | 1572| enableReminder | boolean | No | Yes | 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**.| 1573| color | number \| string | No | Yes | Calendar color. If this parameter is not set, the default value **'#0A59F7'** is used. | 1574 1575## Event 1576 1577Describes an **Event** object, including the event title, start time, and end time. 1578 1579**System capability**: SystemCapability.Applications.CalendarData 1580 1581| Name | Type | Read Only| Optional| Description | 1582| -------------- | --------------------------------- | ---- |----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 1583| id | number | No | Yes | Event ID. This parameter does not need to be set in the [addEvent()](#addevent) or [addEvents()](#addevents) API.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1584| type | [EventType](#eventtype) | No | No | Event type.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1585| title | string | No | Yes | Event title. If this parameter is not set, an empty string is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1586| location | [Location](#location) | No | Yes | Event location. If this parameter is not set, the default null value is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1587| startTime | number | No | No | Start time of the event. The value is a 13-digit timestamp.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1588| endTime | number | No | No | End time of the event. The value is a 13-digit timestamp.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1589| isAllDay | boolean | No | Yes | 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**.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1590| attendee | [Attendee](#attendee)[] | No | Yes | Attendee information of a conference event. If this parameter is not set, the default null value is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1591| timeZone | string | No | Yes | Time zone of the event. If this parameter is not set, the current system time zone is used. You can call the [getTimeZone()](../apis-basic-services-kit/js-apis-date-time.md#systemdatetimegettimezone) API to obtain the current system time zone.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1592| reminderTime | number[] | No | Yes | 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. A negative value indicates the delay time for sending a notification.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1593| recurrenceRule | [RecurrenceRule](#recurrencerule) | No | Yes | Recurrence rule of an event. If this parameter is not set, the value does not recur.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1594| description | string | No | Yes | Event description. If this parameter is not set, an empty string is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1595| service | [EventService](#eventservice) | No | Yes | <!--RP1-->Event service. If this parameter is not set, no service is available. This function is not supported currently.<!--RP1End--> <br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1596| identifier<sup>12+</sup> | string | No | Yes | A unique ID of an event can be specified. If this parameter is not set, the default null value is used.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1597| isLunar<sup>12+</sup> | boolean | No | Yes | Whether it is a lunar calendar event. The value **true** means that the event is a lunar calendar event, and **false** means the opposite. The default value is **false**.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1598| instanceStartTime<sup>18+</sup> | number | No | Yes | Start time of the event. The value is a 13-digit timestamp. This parameter does not need to be set in [addEvent()](#addevent) or [addEvents()](#addevents).<br>**Atomic service API**: This API can be used in atomic services since API version 18. | 1599| instanceEndTime<sup>18+</sup> | number | No | Yes | End time of the event. The value is a 13-digit timestamp. This parameter does not need to be set in the [addEvent()](#addevent) or [addEvents()](#addevents) API.<br>**Atomic service API**: This API can be used in atomic services since API version 18. | 1600 1601## CalendarType 1602 1603Enumerates the account types. 1604 1605**Atomic service API**: This API can be used in atomic services since API version 11. 1606 1607**System capability**: SystemCapability.Applications.CalendarData 1608 1609| Name | Value | Description | 1610| ---------- | ------------ | -------------------- | 1611| LOCAL | 'local' | Local account. | 1612| EMAIL | 'email' | Email account. | 1613| BIRTHDAY | 'birthday' | Birthday account. | 1614| CALDAV | 'caldav' | CalDAV account.| 1615| SUBSCRIBED | 'subscribed' | Subscription account. | 1616 1617## Location 1618 1619Describes the event location. 1620 1621**Atomic service API**: This API can be used in atomic services since API version 11. 1622 1623**System capability**: SystemCapability.Applications.CalendarData 1624 1625| Name | Type | Read Only| Optional| Description | 1626| --------- | ------ | ---- |----| ------------------------ | 1627| location | string | No | Yes | Location. The default value is an empty string.| 1628| longitude | number | No | Yes | Longitude of the location. The default value is **0**. | 1629| latitude | number | No | Yes | Latitude of the location. The default value is **0**. | 1630 1631## EventFilter 1632 1633Implements an event filter. 1634 1635You can use [filterById()](#filterbyid), [filterByTime()](#filterbytime), or [filterByTitle()](#filterbytitle) to obtain an event filter, and then pass the filter in [getEvents()](#getevents) for filtering. 1636 1637### filterById 1638 1639static filterById(ids: number[]): EventFilter 1640 1641Defines an event ID based filter. 1642 1643**System capability**: SystemCapability.Applications.CalendarData 1644 1645**Parameters** 1646 1647| Name| Type | Mandatory| Description | 1648| ------ | -------- | ---- | ------------ | 1649| ids | number[] | Yes | Array of event IDs.| 1650 1651**Return value** 1652 1653| Type | Description | 1654| --------------------------- | -------------------- | 1655| [EventFilter](#eventfilter) | **EventFilter** object.| 1656 1657**Example** 1658 1659```typescript 1660import { BusinessError } from '@kit.BasicServicesKit'; 1661import { calendarMgr } from '../entryability/EntryAbility'; 1662 1663let calendar : calendarManager.Calendar | undefined = undefined; 1664let id1: number = 0; 1665let id2: number = 0; 1666const date = new Date(); 1667const event1: calendarManager.Event = { 1668 type: calendarManager.EventType.NORMAL, 1669 startTime: date.getTime(), 1670 endTime: date.getTime() + 60 * 60 * 1000 1671}; 1672const event2: calendarManager.Event = { 1673 type: calendarManager.EventType.IMPORTANT, 1674 startTime: date.getTime(), 1675 endTime: date.getTime() + 60 * 60 * 1000 1676}; 1677calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1678 if (err) { 1679 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1680 } else { 1681 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1682 calendar = data; 1683 await calendar.addEvent(event1).then((data: number) => { 1684 console.info(`Succeeded in adding event, id -> ${data}`); 1685 id1 = data; 1686 }).catch((err: BusinessError) => { 1687 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1688 }); 1689 await calendar.addEvent(event2).then((data: number) => { 1690 console.info(`Succeeded in adding event, id -> ${data}`); 1691 id2 = data; 1692 }).catch((err: BusinessError) => { 1693 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1694 }); 1695 const filter = calendarManager.EventFilter.filterById([id1, id2]); 1696 calendar.getEvents(filter).then((data: calendarManager.Event[]) => { 1697 console.info(`Succeeded in getting events filter by id, data -> ${JSON.stringify(data)}`); 1698 }).catch((err: BusinessError) => { 1699 console.error(`Failed to filter by id. Code: ${err.code}, message: ${err.message}`); 1700 }); 1701 } 1702}); 1703``` 1704 1705### filterByTime 1706 1707static filterByTime(start: number, end: number): EventFilter 1708 1709Defines an event time based filter. 1710 1711**System capability**: SystemCapability.Applications.CalendarData 1712 1713**Parameters** 1714 1715| Name| Type | Mandatory| Description | 1716| ------ | ------ | ---- | ---------- | 1717| start | number | Yes | Start time.| 1718| end | number | Yes | End time.| 1719 1720**Return value** 1721 1722| Type | Description | 1723| --------------------------- | -------------------- | 1724| [EventFilter](#eventfilter) | **EventFilter** object.| 1725 1726**Example** 1727 1728```typescript 1729import { BusinessError } from '@kit.BasicServicesKit'; 1730import { calendarMgr } from '../entryability/EntryAbility'; 1731 1732let calendar : calendarManager.Calendar | undefined = undefined; 1733const event1: calendarManager.Event = { 1734 type: calendarManager.EventType.NORMAL, 1735 startTime: 1686931200000, 1736 endTime: 1687017600000 1737}; 1738const event2: calendarManager.Event = { 1739 type: calendarManager.EventType.IMPORTANT, 1740 startTime: 1686931200000, 1741 endTime: 1687017600000 1742}; 1743calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1744 if (err) { 1745 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1746 } else { 1747 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1748 calendar = data; 1749 await calendar.addEvent(event1).then((data: number) => { 1750 console.info(`Succeeded in adding event, id -> ${data}`); 1751 }).catch((err: BusinessError) => { 1752 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1753 }); 1754 await calendar.addEvent(event2).then((data: number) => { 1755 console.info(`Succeeded in adding event, id -> ${data}`); 1756 }).catch((err: BusinessError) => { 1757 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1758 }); 1759 const filter = calendarManager.EventFilter.filterByTime(1686931200000, 1687017600000); 1760 calendar.getEvents(filter).then((data: calendarManager.Event[]) => { 1761 console.info(`Succeeded in getting events filter by time, data -> ${JSON.stringify(data)}`); 1762 }).catch((err: BusinessError) => { 1763 console.error(`Failed to filter by time. Code: ${err.code}, message: ${err.message}`); 1764 }); 1765 } 1766}); 1767``` 1768 1769### filterByTitle 1770 1771static filterByTitle(title: string): EventFilter 1772 1773Filters events by event title. This API supports fuzzy match. 1774 1775**System capability**: SystemCapability.Applications.CalendarData 1776 1777**Parameters** 1778 1779| Name| Type | Mandatory| Description | 1780| ------ | ------ | ---- | ---------- | 1781| title | string | Yes | Event title.| 1782 1783**Return value** 1784 1785| Type | Description | 1786| --------------------------- | -------------------- | 1787| [EventFilter](#eventfilter) | **EventFilter** object.| 1788 1789**Example** 1790 1791```typescript 1792import { BusinessError } from '@kit.BasicServicesKit'; 1793import { calendarMgr } from '../entryability/EntryAbility'; 1794 1795let calendar : calendarManager.Calendar | undefined = undefined; 1796const event: calendarManager.Event = { 1797 title: 'MyEvent', 1798 type: calendarManager.EventType.NORMAL, 1799 startTime: 1686931200000, 1800 endTime: 1687017600000 1801}; 1802calendarMgr?.getCalendar(async (err: BusinessError, data:calendarManager.Calendar) => { 1803 if (err) { 1804 console.error(`Failed to get calendar. Code: ${err.code}, message: ${err.message}`); 1805 } else { 1806 console.info(`Succeeded in getting calendar, data -> ${JSON.stringify(data)}`); 1807 calendar = data; 1808 await calendar.addEvent(event).then((data: number) => { 1809 console.info(`Succeeded in adding event, id -> ${data}`); 1810 }).catch((err: BusinessError) => { 1811 console.error(`Failed to add event. Code: ${err.code}, message: ${err.message}`); 1812 }); 1813 const filter = calendarManager.EventFilter.filterByTitle('MyEvent'); 1814 calendar.getEvents(filter).then((data: calendarManager.Event[]) => { 1815 console.info(`Succeeded in getting events filter by title, data -> ${JSON.stringify(data)}`); 1816 }).catch((err: BusinessError) => { 1817 console.error(`Failed to filter by title. Code: ${err.code}, message: ${err.message}`); 1818 }); 1819 } 1820}); 1821``` 1822 1823## EventType 1824 1825Enumerates event types. 1826 1827**Atomic service API**: This API can be used in atomic services since API version 11. 1828 1829**System capability**: SystemCapability.Applications.CalendarData 1830 1831| Name | Value | Description | 1832| --------- | ---- |-------------------------| 1833| NORMAL | 0 | Normal event, such as conference or an alarm clock. | 1834| IMPORTANT | 1 | Important event, such as wedding anniversary, are not recommended for third-party developers. Important events do not support one-click service redirection and custom reminder time.| 1835 1836## RecurrenceRule 1837 1838Describes the recurrence rule of an event. 1839 1840**System capability**: SystemCapability.Applications.CalendarData 1841 1842| Name | Type | Read Only| Optional| Description | 1843| ------------------- | ------------------------------------------- | ---- |----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| 1844| recurrenceFrequency | [RecurrenceFrequency](#recurrencefrequency) | No | No | Type of the event recurrence rule.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1845| expire | number | No | Yes | End date of the recurrence period. If this parameter is not set, the default value **0** is used.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1846| count<sup>12+</sup> | number | No | Yes | Number of the recurrent event. The value is a non-negative integer. If this parameter is not set, the default value **0** is used, indicating that the number of recurrent events is infinite; if the value is negative, the effect is the same as that of **0**. If both **count** and **expire** exist, **count** is used.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1847| interval<sup>12+</sup> | number | No | Yes | Interval for a recurrent event. The value is a non-negative integer. If this parameter is not set, the default value **0** is used, indicating that the event is repeated based on the recurrence rule without intervals; if the value is negative, the effect is the same as that of **0**. If both **interval** and **expire** exist, **expire** is used.<br>This attribute is related to the **recurrenceFrequency** rule. The recurrence interval varies according to the recurrence rule. For example, if the **interval** value is **2**, the following situations occur:<br>Daily recurrence: The event repeats every two days.<br>Weekly recurrence: The event repeats every two weeks.<br>Monthly recurrence: The event repeats every two months.<br>Yearly recurrence: The event repeats every two years.<br>**Atomic service API**: This API can be used in atomic services since API version 12.| 1848| excludedDates<sup>12+</sup> | number[] | No | Yes | Excluded date of a recurrent event. The value is in the timestamp format. If this parameter is not set, the default value is empty, indicating that no date is excluded; if the value is **0** or a negative number, the effect is the same as that of the empty value.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1849| daysOfWeek<sup>12+</sup> | number[] | No | Yes | Repeats by day of a week. If this parameter is not set, the default value is empty, indicating that there is no recurrence rule. The value ranges from 1 to 7, corresponding to Monday to Sunday. Other values are invalid and have the same effect as the empty value.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1850| daysOfMonth<sup>12+</sup> | number[] | No | Yes | Repeats by day of a month. If this parameter is not set, the default value is empty, indicating that there is no recurrence rule. The value ranges from 1 to 31, corresponding to the first to the last days of each month. Other values are invalid and have the same effect as the empty value. If this month only has 30 days, the value **31** is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1851| daysOfYear<sup>12+</sup> | number[] | No | Yes | Repeats by day of a year. If this parameter is not set, the default value is empty, indicating that there is no recurrence rule. The value ranges from 1 to 366, corresponding to the first to the last days of each year. Other values are invalid and have the same effect as the empty value. If this year only has 365 days, the value **366** is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1852| weeksOfMonth<sup>12+</sup> | number[] | No | Yes | Repeats by week of a month. If this parameter is not set, the default value is empty, indicating that there is no recurrence rule. The value ranges from 1 to 5, corresponding to the first to the last weeks of each month. Other values are invalid and have the same effect as the empty value. If this month only has four weeks, the value **5** is invalid.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1853| weeksOfYear<sup>12+</sup> | number[] | No | Yes | Repeats by week of a year. If this parameter is not set, the default value is empty, indicating that there is no recurrence rule. The value ranges from 1 to 53, corresponding to the first to the last weeks of each year. Other values are invalid and have the same effect as the empty value.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1854| monthsOfYear<sup>12+</sup> | number[] | No | Yes | Repeats by month of a year. If this parameter is not set, the default value is empty, indicating that there is no recurrence rule. The value ranges from 1 to 12, corresponding to the first to the last months of each year. Other values are invalid and have the same effect as the empty value.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1855## RecurrenceFrequency 1856 1857Enumerates the types of the event recurrence rule. 1858 1859**Atomic service API**: This API can be used in atomic services since API version 11. 1860 1861**System capability**: SystemCapability.Applications.CalendarData 1862 1863| Name | Value | Description | 1864| ------- | ---- | ---------- | 1865| YEARLY | 0 | Yearly.| 1866| MONTHLY | 1 | Monthly.| 1867| WEEKLY | 2 | Weekly.| 1868| DAILY | 3 | Daily.| 1869 1870## Attendee 1871 1872Describes the attendee information of a conference event. 1873 1874**System capability**: SystemCapability.Applications.CalendarData 1875 1876| Name | Type | Read Only| Optional| Description | 1877| ----- | ------ | ---- |----|--------------------------------------------------------------------| 1878| name | string | No | No | Name of the attendee.<br>**Atomic service API**: This API can be used in atomic services since API version 11. | 1879| email | string | No | No | Email address of the attendee.<br>**Atomic service API**: This API can be used in atomic services since API version 11.| 1880| role<sup>12+</sup> | [AttendeeRole](#attendeerole12) | No | Yes | Role of the attendee.<br>**Atomic service API**: This API can be used in atomic services since API version 12. | 1881| status<sup>18+</sup> | [AttendeeStatus](#attendeestatus18) | No | Yes| Status of the attendee. If this parameter is not set, the default value is empty.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 1882| type<sup>18+</sup> | [AttendeeType](#attendeetype18) | No | Yes| Type of the attendee. If this parameter is not set, the default value is empty.<br>**Atomic service API**: This API can be used in atomic services since API version 18.| 1883 1884## EventService 1885 1886Describes the event service. 1887 1888**Atomic service API**: This API can be used in atomic services since API version 11. 1889 1890**System capability**: SystemCapability.Applications.CalendarData 1891 1892| Name | Type | Read Only| Optional| Description | 1893| ----------- | --------------------------- | ---- |----|-------------------------------------| 1894| type | [ServiceType](#servicetype) | No | No | Service type. | 1895| uri | string | No | No | Service URI, in the DeepLink format. It can be used to redirect the user to a page of another application.| 1896| description | string | No | Yes | Description of the service. If this parameter is not set, an empty string is used. | 1897 1898## ServiceType 1899 1900Enumerates the event service types. 1901 1902**Atomic service API**: This API can be used in atomic services since API version 11. 1903 1904**System capability**: SystemCapability.Applications.CalendarData 1905 1906| Name | Value | Description | 1907| --------------- | ---------------- | ------------ | 1908| MEETING | 'Meeting' | Join a meeting. | 1909| WATCHING | 'Watching' | Watch a video. | 1910| REPAYMENT | 'Repayment' | Make a payment. | 1911| LIVE | 'Live' | Watch live TV. | 1912| SHOPPING | 'Shopping' | Go shopping. | 1913| TRIP | 'Trip' | View the trip. | 1914| CLASS | 'Class' | Join class. | 1915| SPORTS_EVENTS | 'SportsEvents' | Watch a sports event.| 1916| SPORTS_EXERCISE | 'SportsExercise' | Start exercising. | 1917 1918## AttendeeRole<sup>12+</sup> 1919 1920Enumerates the attendee role types in a conference event. 1921 1922**Atomic service API**: This API can be used in atomic services since API version 12. 1923 1924**System capability**: SystemCapability.Applications.CalendarData 1925 1926| Name | Value | Description | 1927|--------------|---------------|--------| 1928| ORGANIZER | 'organizer' | Conference organizer.| 1929| PARTICIPANT | 'participant' | Conference participant.| 1930 1931## AttendeeStatus<sup>18+</sup> 1932 1933Enumerates the status types of an attendee. 1934 1935**Atomic service API**: This API can be used in atomic services since API version 18. 1936 1937**System capability**: SystemCapability.Applications.CalendarData 1938 1939| Name | Value | Description | 1940|----------------------------|-----|----------| 1941| UNKNOWN | 0 | The attendee status is unknown.| 1942| TENTATIVE | 1 | The attendee status is tentative.| 1943| ACCEPTED | 2 | The attendee has accepted the conference invitation. | 1944| DECLINED | 3 | The attendee has rejected the conference invitation. | 1945| UNRESPONSIVE | 4 | The attendee does not respond. | 1946 1947## AttendeeType<sup>18+</sup> 1948 1949Enumerates the types of attendees invited to a conference event. 1950 1951**Atomic service API**: This API can be used in atomic services since API version 18. 1952 1953**System capability**: SystemCapability.Applications.CalendarData 1954 1955| Name | Value | Description | 1956|------------------------|-----|--------------------| 1957| REQUIRED | 1 | Required attendee. | 1958| OPTIONAL | 2 | Optional attendee. | 1959| RESOURCE | 3 | Resources (such as TVs or projectors) used in a conference.| 1960