Add Weekly Event to Calendar

Add Weekly Event to Calendar

You said it showed repeating for Thursday, but what I got was a start day of Thursday with a repeat every Tuesday. So I'm pretty sure the RRULE part is right.

I think all you have to do is set the actual start and end times with Calendar to get the right milliseconds, then user "beginTime" instead of "dtstart" and "endTime" instead of "dtend".

@Override
public void onClick(View v) {

// If you want the start times to show up, you have to set them
Calendar calendar = Calendar.getInstance();

// Here we set a start time of Tuesday the 17th, 6pm
calendar.set(2015, Calendar.MARCH, 17, 18, 0, 0);
calendar.setTimeZone(TimeZone.getDefault());

long start = calendar.getTimeInMillis();
// add three hours in milliseconds to get end time of 9pm
long end = calendar.getTimeInMillis() + 3 * 60 * 60 * 1000;

Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(Events.CONTENT_URI)
.setType("vnd.android.cursor.item/event")
.putExtra(Events.TITLE, "Tuesdays")
.putExtra(Events.DESCRIPTION, "Tuesday Specials")
.putExtra(Events.EVENT_LOCATION, "Lixious Bench")
.putExtra(Events.RRULE, "FREQ=WEEKLY;BYDAY=TU;UNTIL=20150428")

// to specify start time use "beginTime" instead of "dtstart"
//.putExtra(Events.DTSTART, calendar.getTimeInMillis())
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start)
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end)

// if you want to go from 6pm to 9pm, don't specify all day
//.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true)
.putExtra(CalendarContract.Events.HAS_ALARM, 1)
.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY);

startActivity(intent);
}

How to Add recurring events programmatically?

this is my corrected code..working fine :)

public class mainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Uri eventsUri;
if (android.os.Build.VERSION.SDK_INT <= 7) {

eventsUri = Uri.parse("content://calendar/events");
} else {

eventsUri = Uri.parse("content://com.android.calendar/events");
}

Calendar cal = Calendar.getInstance();
ContentValues event = new ContentValues();
event.put("calendar_id", 1);
event.put("title", "Event Title");
event.put("description", "Event Desc");
event.put("eventLocation", "Event Location");
event.put("dtstart",cal.getTimeInMillis());
event.put("rrule", "FREQ=WEEKLY;WKST=SU;BYDAY=WE");
event.put("allDay", 1); // 0 for false, 1 for true
event.put("eventStatus", 1);
event.put("hasAlarm", 1); // 0 for false, 1 for true
event.put("duration","P3600S");
Uri url = getContentResolver().insert(eventsUri, event);
}
}

How to create recurring event with every 2 days/weeks/months/years in Google Calendar API PHP

What you want to create is a recurring event. Creating recurring events is similar to creating a regular (single) event with the event resource's recurrence field set. To learn more about recurrence rule, you can visit this link.

An example of a recurring event is:

$event = new Google_Service_Calendar_Event();
$event->setSummary('Appointment');
$event->setLocation('Somewhere');
$start = new Google_Service_Calendar_EventDateTime();
$start->setDateTime('2011-06-03T10:00:00.000-07:00');
$start->setTimeZone('America/Los_Angeles');
$event->setStart($start);
$end = new Google_Service_Calendar_EventDateTime();
$end->setDateTime('2011-06-03T10:25:00.000-07:00');
$end->setTimeZone('America/Los_Angeles');
$event->setEnd($end);
$event->setRecurrence(array('RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z'));
$attendee1 = new Google_Service_Calendar_EventAttendee();
$attendee1->setEmail('attendeeEmail');

What makes this different from a single event is the following line:

$event->setRecurrence(array('RRULE:FREQ=WEEKLY;UNTIL=20110701T170000Z'));

This line makes the single event occur again every week until July 1.

Another example: An all-day event starting on June 1st, 2015 and repeating every 3 days throughout the month, excluding June 10th but including June 9th and 11th

...
"start": {
"date": "2015-06-01"
},
"end": {
"date": "2015-06-02"
},
"recurrence": [
"EXDATE;VALUE=DATE:20150610",
"RDATE;VALUE=DATE:20150609,20150611",
"RRULE:FREQ=DAILY;UNTIL=20150628;INTERVAL=3"
],

For your case, you may create a recurring event that has an RRULE of FREQ=DAILY;UNTIL=20190229;INTERVAL=3 for every 3 days. Change FREQ to WEEKLY for every 3 weeks and UNTIL to adjust how many cycles.

How to add event in Android calendar, repeated every 3 days?

finally I found the solution.

values.put(Events.DTSTART, startMillis);
values.put(Events.DURATION, "P1800S");
values.put(Events.TITLE, "MyTestNew");
values.put(Events.DESCRIPTION, "Group workout");
values.put(Events.CALENDAR_ID, calID);
values.put(Events.EVENT_TIMEZONE, "India");
values.put(Events.RRULE, "FREQ=DAILY;INTERVAL=3");
uri = cr.insert(Events.CONTENT_URI, values);

Calendar Recurring/Repeating Events - Best Storage Method

Storing "Simple" Repeating Patterns

For my PHP/MySQL based calendar, I wanted to store repeating/recurring event information as efficiently as possibly. I didn't want to have a large number of rows, and I wanted to easily lookup all events that would take place on a specific date.

The method below is great at storing repeating information that occurs at regular intervals, such as every day, every n days, every week, every month every year, etc etc. This includes every Tuesday and Thursday type patterns as well, because they are stored separately as every week starting on a Tuesday and every week starting on a Thursday.

Assuming I have two tables, one called events like this:

ID    NAME
1 Sample Event
2 Another Event

And a table called events_meta like this:

ID    event_id      meta_key           meta_value
1 1 repeat_start 1299132000
2 1 repeat_interval_1 432000

With repeat_start being a date with no time as a unix timestamp, and repeat_interval an amount in seconds between intervals (432000 is 5 days).

repeat_interval_1 goes with repeat_start of the ID 1. So if I have an event that repeats every Tuesday and every Thursday, the repeat_interval would be 604800 (7 days), and there would be 2 repeat_starts and 2 repeat_intervals. The table would look like this:

ID    event_id      meta_key           meta_value
1 1 repeat_start 1298959200 -- This is for the Tuesday repeat
2 1 repeat_interval_1 604800
3 1 repeat_start 1299132000 -- This is for the Thursday repeat
4 1 repeat_interval_3 604800
5 2 repeat_start 1299132000
6 2 repeat_interval_5 1 -- Using 1 as a value gives us an event that only happens once

Then, if you have a calendar that loops through every day, grabbing the events for the day it's at, the query would look like this:

SELECT EV.*
FROM `events` EV
RIGHT JOIN `events_meta` EM1 ON EM1.`event_id` = EV.`id`
RIGHT JOIN `events_meta` EM2 ON EM2.`meta_key` = CONCAT( 'repeat_interval_', EM1.`id` )
WHERE EM1.meta_key = 'repeat_start'
AND (
( CASE ( 1299132000 - EM1.`meta_value` )
WHEN 0
THEN 1
ELSE ( 1299132000 - EM1.`meta_value` )
END
) / EM2.`meta_value`
) = 1
LIMIT 0 , 30

Replacing {current_timestamp} with the unix timestamp for the current date (Minus the time, so the hour, minute and second values would be set to 0).

Hopefully this will help somebody else too!


Storing "Complex" Repeating Patterns

This method is better suited for storing complex patterns such as

Event A repeats every month on the 3rd of the month starting on March 3, 2011

or

Event A repeats Friday of the 2nd week of the month starting on March 11, 2011

I'd recommend combining this with the above system for the most flexibility. The tables for this should like like:

ID    NAME
1 Sample Event
2 Another Event

And a table called events_meta like this:

ID    event_id      meta_key           meta_value
1 1 repeat_start 1299132000 -- March 3rd, 2011
2 1 repeat_year_1 *
3 1 repeat_month_1 *
4 1 repeat_week_im_1 2
5 1 repeat_weekday_1 6

repeat_week_im represents the week of the current month, which could be between 1 and 5 potentially. repeat_weekday in the day of the week, 1-7.

Now assuming you are looping through the days/weeks to create a month view in your calendar, you could compose a query like this:

SELECT EV . *
FROM `events` AS EV
JOIN `events_meta` EM1 ON EM1.event_id = EV.id
AND EM1.meta_key = 'repeat_start'
LEFT JOIN `events_meta` EM2 ON EM2.meta_key = CONCAT( 'repeat_year_', EM1.id )
LEFT JOIN `events_meta` EM3 ON EM3.meta_key = CONCAT( 'repeat_month_', EM1.id )
LEFT JOIN `events_meta` EM4 ON EM4.meta_key = CONCAT( 'repeat_week_im_', EM1.id )
LEFT JOIN `events_meta` EM5 ON EM5.meta_key = CONCAT( 'repeat_weekday_', EM1.id )
WHERE (
EM2.meta_value =2011
OR EM2.meta_value = '*'
)
AND (
EM3.meta_value =4
OR EM3.meta_value = '*'
)
AND (
EM4.meta_value =2
OR EM4.meta_value = '*'
)
AND (
EM5.meta_value =6
OR EM5.meta_value = '*'
)
AND EM1.meta_value >= {current_timestamp}
LIMIT 0 , 30

This combined with the above method could be combined to cover most repeating/recurring event patterns. If I've missed anything please leave a comment.



Related Topics



Leave a reply



Submit