Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 64657c43 authored by David Sobreira Marques's avatar David Sobreira Marques Committed by Steve Kondik
Browse files

Fixing counting the number of days in call log screen.



Counting the number of days in call log screen when a
call was made/received within a week is not correct.

Issue 3132: Call Log Reporting Wrong

Change-Id: I99c3cb40267b4b5938ccc4225993b7aac7e2d018
Signed-off-by: default avatarDavid Sobreira Marques <dpsmarques@gmail.com>
parent da416ba8
Loading
Loading
Loading
Loading
+56 −33
Original line number Diff line number Diff line
@@ -497,7 +497,7 @@ public class DateUtils
                }
            }
        } else if (duration < WEEK_IN_MILLIS && minResolution < WEEK_IN_MILLIS) {
            count = duration / DAY_IN_MILLIS;
            count = getNumberOfDaysPassed(time, now);
            if (past) {
                if (abbrevRelative) {
                    resId = com.android.internal.R.plurals.abbrev_num_days_ago;
@@ -521,6 +521,24 @@ public class DateUtils
        return String.format(format, count);
    }
    
    /**
     * Returns the number of days passed between two dates.
     *
     * @param date1 first date
     * @param date2 second date
     * @return number of days passed between to dates.
     */
    private synchronized static long getNumberOfDaysPassed(long date1, long date2) {
        if (sThenTime == null) {
            sThenTime = new Time();
        }
        sThenTime.set(date1);
        int day1 = Time.getJulianDay(date1, sThenTime.gmtoff);
        sThenTime.set(date2);
        int day2 = Time.getJulianDay(date2, sThenTime.gmtoff);
        return Math.abs(day2 - day1);
    }
    
    /**
     * Return string describing the elapsed time since startTime formatted like
     * "[relative time/date], [time]".
@@ -1655,18 +1673,22 @@ public class DateUtils
    public static CharSequence getRelativeTimeSpanString(Context c, long millis,
            boolean withPreposition) {

        String result;
        long now = System.currentTimeMillis();
        long span = now - millis;
        
        synchronized (DateUtils.class) {
            if (sNowTime == null) {
                sNowTime = new Time();
            }
            
            if (sThenTime == null) {
                sThenTime = new Time();
            }
            
            sNowTime.set(now);
            sThenTime.set(millis);
    
        String result;
            int prepositionId;
            if (span < DAY_IN_MILLIS && sNowTime.weekDay == sThenTime.weekDay) {
                // Same day
@@ -1690,6 +1712,7 @@ public class DateUtils
                Resources res = c.getResources();
                result = res.getString(prepositionId, result);
            }
        }
        return result;
    }