package utils;

import org.joda.time.*;

import java.util.*;

public class JodaDateUtil {
    public static Date today() {
        return LocalDate.now().toDate();
    }

    public static Date now() {
        return DateTime.now().toDate();
    }

    public static Duration ago(DateTime time) {
        return new Duration(time, DateTime.now());
    }

    public static Duration ago(Date time) {
        return new Duration(new DateTime(time), DateTime.now());
    }

    public static Duration ago(Long time){
        return new Duration(new DateTime(new Date(time)), DateTime.now());
    }

    public static Date before(int days){
        return new DateTime(today()).minusDays(days).toDate();
    }

    public static String momentFromNow(Long time) {
        return momentFromNow(time, Constants.DEFAULT_LANGUAGE);
    }

    public static String momentFromNow(Long time, String language) {
        JSInvocable moment = MomentUtil.newMoment(time, language);
        return moment.invoke("fromNow");
    }

    public static String momentFromNow(Date time) {
        return momentFromNow(time, Constants.DEFAULT_LANGUAGE);
    }

    public static String momentFromNow(Date time, String language) {
        JSInvocable moment = MomentUtil.newMoment(time.getTime(), language);
        return moment.invoke("fromNow");
    }

}

@@ -24,70 +24,513 @@
 org.
-joda.time.*;%0A%0Aimport java.util.*;%0A%0Apublic class JodaDateUtil %7B
+apache.commons.lang3.StringUtils;%0Aimport org.joda.time.*;%0A%0Aimport java.text.SimpleDateFormat;%0Aimport java.util.*;%0A%0Apublic class JodaDateUtil %7B%0A    public static String getDateString(Date date) %7B%0A        return getDateString(date, null);%0A    %7D%0A    public static String getDateString(Date date, String format) %7B%0A        if(StringUtils.isEmpty(format)) %7B%0A            format = %22yyyy-MM-dd hh:mm:ss%22;%0A        %7D%0A        SimpleDateFormat sdf = new SimpleDateFormat(format);%0A        return sdf.format(date);%0A    %7D
 %0A   

add date string method