DateCalc released

February 18, 2008 · Posted in Java · 1 Comment 

DateCalc is a small stand-alone Java program that provides simple command-line date expression calculations such as
yes> java -jar datecalc-2.0.jar today yesterday.day.end today.day(12) "today.format(d MMMM yyyy)" date(2006-10-03).day.end month(-1).month.end.day.start today.month.name tomorrow.day.name2008-02-18 13:38:40
2008-02-17 23:59:59
2008-03-01 13:38:40
18 februari 2008
2006-10-03 23:59:59
2008-01-31 00:00:00
februari
tisdag

A few years ago I was working with a shell script that was a batch front-end for a complex system handling monitoring data. This script was intended to be run from cron every month to create a monthly summary report. Typically, it executed early morning the 1st of every month, producing a report for the last month.

The problem was to compute date-time of the first and last seconds of the previous month. I needed a simple way to express dates such as “give me the end time of the last day of the previous month “. As a well-known fact months can be 28, 30, 31 (and 29) days long. I couldn’t find a convenient command that gave me the answers. Unix date was of no help.

That problem inspired me to create a small Java class that solved the immediate problem. Later I refined it and made it more versatile.

When I was about to release the first public version, I started to scrutinize my design and realized it could be better. I therefor re-wrote all of it and improved the simplicity of the operators and the separation of concerns in the design.