Remembering how much holiday I have

Like many people (in the UK at least) I have a certain number of paid holiday days from work per year.

I already have a personal calendar and a work calendar. When I book time off my personal calendar would get an event for the reason I'm off "Josh's amazing holiday" while my work calendar would be used to record the days I've booked off, with events like "booked off".

This may already be too granular for most people and seen as an unnecessary duplication. But I prefer this method to make it easier to count up how many days I've booked off. But even doing this it was tricky to get a quick overview of how many days I had booked off vs how many days I had left.

So I started thinking, how could I make this easier for my lazy self?

I use Google (for better or worse) for my email and calendar. I decided I'd make a little page that would simply display how many holiday days I had left. I'd use their API to read my work calendar and count up all the events.

A read through the docs later I had a sort of working example, I struggled with connecting the specific calendar up with the API. It took some hoop jumping and some counter intuitive steps to be able to read the calendar but I got there.

The next problem for me was that it asked me to login every session, to authenticate my Google account. This would be fine if I was making an app or website for public use as you'd want users to authenticate their own account. But for this I wanted to read my calendar and only my calendar, without having to login every time.

Looking deeper at the docs there was a way to 'hard code' this authentication to one account and have it persist across sessions. So some changes to my code were needed to use a 'service account' for the API instead of authenticating as an end user.

With this set up I was returning JSON data for my calendar, I had to parse the data and get the information I wanted.

I asked the API to return all events on the calendar with the title "[booked off]" and counted them up.

Done. A super quick way for me to see how much holiday I've used and how much I have left.

60 lines of PHP to talk to the Google API

A slight hiccup came a while later when I booked some days off for next year. I'd forgotten to date limit the event search! So I updated my API call to get events for the current year only.

Done, again. I could have got more fancy and added more data or features, but that's not what this is meant for. If I want more info I can check the calendar itself. This super simple tool does exactly what I want it to.