This was probably the funniest bug description I’ve encountered. Not as funny as Unit tests fail when run in Australia or We can’t send mail more than 500 miles, but it’s really hard to beat those!

So what exactly went wrong? Our Windows batch script uses the current date and time to compose a file name, which is then passed as an argument to a Java application. So far so good. But why does it fail before 10 a.m? Let’s see how Windows handles dates and times:

$ echo %DATE%

$ echo %TIME%

We get a leading zero for days and a space for one-digit hours! This explains why our script failed:

$ java -jar application.jar 2015-05-08- 9-34.txt

So we just replace leading spaces with zeros, right? Nope. The time/date format is country-dependant and can be fully customized… We are supposed to use something like this instead:

$ wmic os get localdatetime /format:list

This pretty much sums it up:

“It’s a complete nightmare for a BAT programmer.”
PA., StackOverflow