Last active
June 11, 2025 13:02
-
-
Save julik/d6c4a3a32a3145d5e7467baa4e1868e2 to your computer and use it in GitHub Desktop.
Generate a timesheet from Apple Calendar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Calendar = Application("Calendar") | |
const calendarName = "My Calendar"; | |
const eventNamePrefix = "Amazing Project 123"; | |
var theCalendar = Calendar.calendars.whose({name: calendarName})[0] | |
var fromDate = new Date(2025, 4, 25) | |
var evts = theCalendar.events.whose( | |
{_and: [ | |
{summary: { _beginsWith: eventNamePrefix }}, | |
{startDate: { _greaterThan: fromDate}} | |
] | |
} | |
); | |
// Resolve the array | |
let totalHours = 0; | |
for (var evtHandleFn of evts()) { | |
let evtHandle = evtHandleFn(); | |
let summary = evtHandle.summary(); | |
let sd = evtHandle.startDate(); | |
let ed = evtHandle.endDate(); | |
let durationMillis = ed - sd; | |
let durationHours = durationMillis / 1000 / 60 / 60; | |
totalHours += durationHours; | |
const [formattedDate] = sd.toISOString().split('T'); | |
console.log(`${formattedDate}: ${summary} took ${durationHours.toFixed(2)} hours`); | |
} | |
console.log(`${totalHours.toFixed(2)} total hours`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment