
package org.missionassetfund.apps.android.utils;

import java.util.Calendar;
import java.util.Date;

public class MAFDateUtils {
    private static final long ONE_DAY_IN_MILLIS = 24 * 60 * 60 * 1000;

    public static int getDaysSince(Date date) {
        if (date == null) {
            return 0;
        }
        return (int) ((getCurrentEpochTime() - date.getTime()) / ONE_DAY_IN_MILLIS);
    }

    private static long getCurrentEpochTime() {
        return new Date().getTime();
    }

    public static int getDaysTo(Date date) {
        return (int) ((date.getTime() - getCurrentEpochTime()) / ONE_DAY_IN_MILLIS);
    }

    public static Date addDaysToDate(Date date, int days) {
        long epochTime = date.getTime() + (days * ONE_DAY_IN_MILLIS);
        return new Date(epochTime);
    }
    
    public static boolean isSameWeek(Date date) {
        Calendar beginningOfTheWeek = Calendar.getInstance();
        beginningOfTheWeek.set(Calendar.DAY_OF_WEEK, beginningOfTheWeek.getFirstDayOfWeek());
        beginningOfTheWeek.set(Calendar.HOUR, 0);
        beginningOfTheWeek.set(Calendar.MINUTE, 0);

        Calendar endOfTheWeek = Calendar.getInstance();
        endOfTheWeek.set(Calendar.DAY_OF_WEEK, endOfTheWeek.getFirstDayOfWeek());
        endOfTheWeek.add(Calendar.DAY_OF_WEEK, 7);
        endOfTheWeek.set(Calendar.HOUR, 23);
        endOfTheWeek.set(Calendar.MINUTE, 59);

        return date.after(beginningOfTheWeek.getTime()) && date.before(endOfTheWeek.getTime());
    }
    
    public static boolean isSameDay(Date date1, Date date2) {
        Calendar cal1 = Calendar.getInstance();
        Calendar cal2 = Calendar.getInstance();

        cal1.setTime(date1);
        cal2.setTime(date2);

        return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) &&
                cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR);
    }

}

@@ -95,16 +95,55 @@
 .Date;%0A%0A
+import android.text.format.DateUtils;%0A%0A
 public c
@@ -827,37 +827,33 @@
 ochTime);%0A    %7D%0A
-    
 %0A
+
     public stati
@@ -1533,13 +1533,9 @@
   %7D%0A
-    
 %0A
+
     
@@ -1906,10 +1906,246 @@
 %0A    %7D%0A%0A
+    public static String getRelativeDate(Date date) %7B%0A        return DateUtils.getRelativeTimeSpanString(date.getTime(), new Date().getTime(),%0A                DateUtils.DAY_IN_MILLIS, DateUtils.FORMAT_ABBREV_RELATIVE).toString();%0A    %7D%0A
 %7D%0A

Add getRelativeDate method