Thursday 31 October 2013

Joda Time - handling of end of February when DateTime.plusMonths() is called

Overheard a colleague at work with an issue re: February and got
curious enough to see what Joda-Time does in handling this scenario:

// if current date is 31st, how will joda-time handle setting month to february?
dt = new DateTime();
println "now: " + dt.toString();
futureDt = dt.plusMonths(4);
println "4 mos in future: " + futureDt.toString();

OUTPUT

now: 2013-10-31T15:29:53.628+11:00
4 mos in future: 2014-02-28T15:29:53.628+11:00

Nice.

The Groovy Shell functionality within IntelliJ IDEA makes quick
playing around like this a breeze!

No comments: