The venerable Dr. Drang got wind of my AppleScript Date-Time experiment and presented a different technique using modular arithmetic (the modulo operation) instead of a search technique.
It’s incredibly elegant. He also shows how to do the same thing using a very cool Python library. I know very little about Python, so it never would have even occurred to me to implement a shell script in Python for the job.
Anyway. Definitely worth a read.