Samsung Electronics logo

Adding Events to a Calendar



To create engaging applications with various calendar features, you must learn to add events to calendars:

  1. Retrieve the default system calendar using the getDefaultCalendar() method of the CalendarManager interface.

    With the parameter, specify the calendar type as an event.

    calendar = webapis.calendar.getDefaultCalendar("EVENT");
    
  2. Create a CalendarEvent:CalendarItem object and define the event properties:

    var ev = new webapis.CalendarEvent
    ({
       description:"HTML5 Introduction", 
       summary:"HTML5 Webinar", 
       startDate: new webapis.TZDate(2011, 3, 30, 10, 0), 
       duration: new webapis.TimeDuration(1, "HOURS"),
       location:"Huesca",
    
  3. To make a recurring event, define a recurrence rule.

    In this example, the event repeats once a day for 3 days.

       recurrenceRule: new webapis.CalendarRecurrenceRule("DAILY", {occurrenceCount: 3})
    });
    
  4. Add the CalendarEvent object to the default calendar with the add() method of the Calendar object.

    calendar.add(ev);  /* ev.id attribute is generated */
  5. To add an alarm to the event, create an alarm with the CalendarAlarm interface, and add the alarm to the event:

    /* Alarm is triggered with sound 30 minutes before the event start time */
    var alarm = new webapis.CalendarAlarm(new webapis.TimeDuration(30, "MINS"), "SOUND");
    
    ev.alarms = [alarm];
    
Note
You can add a task item in the same way as described above using the "TASK" calendar type and the CalendarTask:CalendarItem constructor.