^(((0|1)\d)|(2[0-3])):?[0-5]\d$

No, it’s not a sanitized version of what I would say if I were to hit my thumb with a hammer.

I’ve been doing some computer programming and I’m using a lot of what are called “regular expressions” to ensure the users entered correct data to the program.

A regular expression is a template used by a “regular expression engine” (a computer program) to decide if some text presented to the “engine” matches a user supplied template.

The concept is quite powerful because the characters to check do not need to be known in advance. So, one can do things like “check to see if what was input was a specific number of letters followed by some optional characters, but the set of optional characters depend on something else within the characters being considered. but only if”… well you get the idea.

What I needed to do was to decide if a user provided the computer program with a set of characters that could be considered a valid time of day in 24 hour format.

This is not as easy as it seems. There must be four digits with an optional : character between the second and third digits. No other characters are allowed. But wait, there’s more. If the first character is a 0 or 1, then the second character can be any single digit, but if the first character is a 2, then the second character is limited to values in the range of 0-3. The third character is always limited to values in the range of 0-5 and the final character can be any single digit.

Any violations to the above criteria means the number can not be considered a valid time in 24 hour format.

It took me about 5 minutes to get the above stuff to work and I was pleased with myself.

I still can’t decide if that looks like what I said when I realized that I have a bunch of date-time calculations to do (that is a huge mess) or when I realized that “despite it being ‘only yesterday’ when I was 20…I’m over 60 years old.”

Some Extra Time

Remember saying that you would like more time?  Well, today, your wish will come true.  It isn’t a whole lot, but it’s at least something.

Normally, 6:59:59pm is followed by 7:00:00pm.  Today, in the east coast, 6:59:59pm will be followed by 6:59:60pm and then you’ll get to 7:00:00pm.   If you are on the west coast of the USA, then this will all happen at 3:59:59pm

So today, you get some extra time and it is called a leap second.  Don’t waste it all at once.

NIST Leap Second

tells why this is all needed.