So, it’s about 4:30 this morning. I’m lying in bed, drowsing, about ready to get up.
The past several days I’ve been really hard at work on Project Drummond, my side software gig.
There’s this thing I have to do in the software, come up with cumulative durations for time spent working various tasks.
Let’s use the example of taking care of an adult baby. Let’s say from 10:00am to 10:45 you spend time reading them a story, then put them down for a nap, only to find out they’ve horribly misbehaved earlier that day, so when you wake them up at 1pm, you spend a good forty five minutes scolding and spanking them.
I want to add up that time doing both activities, and lots more.
I realized that in the groovy programming language I use, there is already some awesome functionality almost baked into the language to do this.
import groovy.time.*; dateStoryStarted = new Date().parse('hh:mm a', '10:15 am') dateStoryEnded = new Date().parse('hh:mm a', '10:45 am') TimeDuration durationStory = TimeCategory.minus(dateStoryEnded,dateStoryStarted) datePunishmentStarted = new Date().parse('HH:mm a', '01:00 pm') datePunishmentEnded = new Date().parse('HH:mm a', '01:45 pm') TimeDuration durationPunishment = TimeCategory.minus(datePunishmentEnded, datePunishmentStarted) TimeDuration CareTotal = durationStory + durationPunishment
All told, that’s 75 minutes of care, by the way.
So, I realize I can do this, while I’m laying in bed, and when the alarm goes off, I just pop right up out of bed, excited. Time duration and time category are the total boss.
I run some initial experiments with it, and it looks like it’s going to be just what I need.
Now I feel energized to go to work, rocket through my whole day, then come home and finish this thing in my own project.
Awesome. That my friends, is a code green moment.