Duration between two dates in Groovy

TimeCategory has some methods for getting a duration. You could use it like

use(groovy.time.TimeCategory) {
    def duration = date1 - date2
    print "Days: ${duration.days}, Hours: ${duration.hours}, etc."
}

The use()-Syntax is weird to me. so I prefer it like this:

def duration = groovy.time.TimeCategory.minus(
  new Date(),
  new Date(session.creationTime)
);
def values = [
            "seconds: " + duration.seconds,
            "min: " + duration.minutes,
            "hours: " + duration.hours,
            "days: " + duration.days,
            "ago: " + duration.ago,
];

Tags:

Groovy