I wanted to export a local calendar to my Google calendar, to be able to import it to my Android phone. This was not as simple as I thought it would be, so I have added some notes here, in case I (or others) need to look them up later.
First I wrote a cron script that filtered out the events I wanted, and put them in a well formed mycal.ics file. This file is served over http by Apache. The script aside, here was the first hurdle. ics calendars are imported as UTF-8 by default, according to RFC 5545. Apache’s default character set for plain text is ISO8859-1. So I had to start by adding something like this to the Apache configuration (in my case, a .htaccess file)
AddType 'text/calendar; charset=UTF-8' .ics
The following is a receipt for adding this ics calendar to Google:
Check that your mycal.ics is available by a normal browser. Below, I will use the URL http://example.com/user/mycal.ics as an example.
Now, importing a calendar by URL is strightforward in the Google calendar webui. Log into your gmail account. Click on the apps squares in the top right corner, and select the Calendar app. In the lower left corner, click on the down arrow by “Other calendars”, and select “Add by URL”. In the URL box, paste the URL to your ics file, for instance http://example.com/user/mycal.ics. The calendar should be imported. If you like to give it a readable name, and a custom color, click on the down arrow by your new calendar in the list in the lower left corner.
At this point, you realize that something went wrong. The calendar has not the correct entries. You need to change it, and you do not want to wait for Google to poll the url – that might take days (and I have not been able to figure out when or how often Google does this). But there is no “update now” or “change url” button.
What you have to do is to remove the calendar, and add it anew. But Google does not give you the option to actually remove the calendar. You only unsubscribe from it. If you reuse the same url, you just re-subscribe to the old calendar, and Google will show you the old content without fetching it anew. This means that your URL has to change every time you want to force a poll, like, when you have changed your ics file on the server.
First unsubscripe from your calendar: Click on the settings gear in the top right corner, and select “Settings”. The click on “calendars” in the top left corner. Find your new calendar in the list at the bottom, and click on “unsubscribe” at the right, and answer “Unsubscribe” to the question.
Now add the calendar anew, as described above, but you either have to change the url, like change the name of the ics file, or, if that is not available for you, add an option that will not change the resource at the server serving the ics file. I use to add ?nocache and a number, like this: http://example.com/user/mycal.ics?nocache01.
Each time you change the ics, and want to force an update, you will have to change to url (I add ?nocache02, ?nocache03, etc).
In android, just subscribe to your Google account as normal. Settings -> Accounts -> Google -> firstname.lastname@example.org -> Sync Calendar. If you want to force a sync of the calendar only, uncheck and recheck Sync Calendar. I use the standard Samsung calendar S Planner. A new Google calendar will be available under Menu -> Calendars -> Display. Note that if you unsubscribe from a calendar in the Google account webui, you might need to reselect it in the S Planner.