package org.rundeck.client.api.model;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

/**
 * Created by greg on 5/20/16.
 */

@JsonIgnoreProperties(ignoreUnknown = true)
public class DateInfo {
    public String date;
    public long unixtime;

    public DateInfo(final String date) {
        this.date = date;
    }

    public DateInfo() {
    }

    public Date toDate() throws ParseException {
        return toDate("yyyy-MM-dd'T'HH:mm:ss'Z'");
    }
    public Date toDate(final String format) throws ParseException {
        SimpleDateFormat asdf = new SimpleDateFormat(format, Locale.US);
        return asdf.parse(date);
    }

    public String toRelative() throws ParseException {
        Date now = new Date();
        return toRelative(now);
    }

    public String toRelative(final Date time) throws ParseException {
        long diff = time.getTime() - toDate().getTime();
        return String.format("%dms ago", diff);
    }

    @Override
    public String toString() {
        return "{" +
               date +
               ", unixtime=" + unixtime +
               '}';
    }
}

@@ -93,16 +93,91 @@
 perties;
+%0Aimport org.rundeck.client.util.Env;%0Aimport org.rundeck.client.util.Format;
 %0A%0Aimport
@@ -657,16 +657,322 @@
 ;%0A    %7D%0A
+%0A    /**%0A     * Format using the default or configured date format%0A     * @return%0A     */%0A    public String format() %7B%0A        try %7B%0A            return Format.date(toDate(), Env.getString(%22DATE_FORMAT%22, %22yyyy-MM-ddHH:mm:ssZ%22));%0A        %7D catch (ParseException e) %7B%0A            return %22?%22;%0A        %7D%0A    %7D%0A%0A
     publ

Format date info using default format or env var DATE_FORMAT