Groovier date diff

HackerNews has weird habit of displaying date of the older comment in days, which sometimes is annoying especially when you see something like "1320 days ago | comments".

Worry not, Groovy to the rescue! On terminal, just write: 

$ groovy -e "println new Date() - 1320"


Which nicely tells you this (well depends on when you execute the commad :-)

Thu Jul 22 00:04:53 IST 2010

That said, it is my first instinct to use Groovy but you could do the same with date command as well

$ date -v-1320d

While we are on Date and Groovy, that just reminded me of a question that I answered on StackOverflow just a few days back. Iterating over a date rage with a week at a time :

(startDate..endDate).step(7) { println it }

No comments: