Workflow Example: Nearest Quarter Hour

This workflow provides an example of working with times and rounding them off. Not simply up or down but to the nearest quarter of an hour.

The workflow begins by capturing a (date and) time. This can be the current (date and )time or one that you specify. This is then reformatted to a short time format.

The resulting time is split (by colon) into two parts - the hours and minutes. The hours are stored in a variable whereas the minutes are then run through a set of calculation operations. The minutes are divided by 15 and rounded to zero decimal places. This will give a value between 0 and 4. That figure is then multiplied by 15 which will give 0, 15, 30, 45 or 60 as a result.

If the minutes are 60 then the workflow sets the minutes to 0 and increments the hours by 1. If the hours are already set to 23 this will be set as 00 rather than 24.

The minutes are then formatted to two digits and the result is displayed via a Quick Look action.

/assets/workflow-examples/Example - Nearest Quarter Hour.png

Tags: | workflow |