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

Commit b6a0256a authored by Wenyi Wang's avatar Wenyi Wang
Browse files

Remove getDayDifference and its test

* The method is not in use after merging contacts and contactsCommon.
* And its test is flaky.

Bug 27346234

Change-Id: If7a9f18bbc57b76a2fc60a8ecc0d0e636547867f
parent 41893b26
Loading
Loading
Loading
Loading
+0 −21
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.contacts.common.util;

import android.content.Context;
import android.text.format.DateFormat;
import android.text.format.Time;


import java.text.ParsePosition;
import java.text.SimpleDateFormat;
@@ -269,23 +267,4 @@ public class DateUtils {
        }
        return anniversary.getTime();
    }

    /**
     * Determine the difference, in days between two dates.  Uses similar logic as the
     * {@link android.text.format.DateUtils.getRelativeTimeSpanString} method.
     *
     * @param time Instance of time object to use for calculations.
     * @param date1 First date to check.
     * @param date2 Second date to check.
     * @return The absolute difference in days between the two dates.
     */
    public static int getDayDifference(Time time, long date1, long date2) {
        time.set(date1);
        int startDay = Time.getJulianDay(date1, time.gmtoff);

        time.set(date2);
        int currentDay = Time.getJulianDay(date2, time.gmtoff);

        return Math.abs(currentDay - startDay);
    }
}
+0 −62
Original line number Diff line number Diff line
/*
 * Copyright (C) 2014 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.contacts.common.util;

import junit.framework.TestCase;

import android.test.suitebuilder.annotation.SmallTest;
import android.text.format.Time;

/**
 * Unit tests for {@link com.android.contacts.common.util.DateUtils}.
 */
@SmallTest
public class DateUtilTests extends TestCase {

    /**
     * Test date differences which are in the same day.
     */
    public void testDayDiffNone() {
        Time time = new Time();
        long date1 = System.currentTimeMillis();
        long date2 = System.currentTimeMillis() + android.text.format.DateUtils.HOUR_IN_MILLIS;
        assertEquals(0, DateUtils.getDayDifference(time, date1, date2));
        assertEquals(0, DateUtils.getDayDifference(time, date2, date1));
    }

    /**
     * Test date differences which are a day apart.
     */
    public void testDayDiffOne() {
        Time time = new Time();
        long date1 = System.currentTimeMillis();
        long date2 = date1 + android.text.format.DateUtils.DAY_IN_MILLIS;
        assertEquals(1, DateUtils.getDayDifference(time, date1, date2));
        assertEquals(1, DateUtils.getDayDifference(time, date2, date1));
    }

    /**
     * Test date differences which are two days apart.
     */
    public void testDayDiffTwo() {
        Time time = new Time();
        long date1 = System.currentTimeMillis();
        long date2 = date1 + 2*android.text.format.DateUtils.DAY_IN_MILLIS;
        assertEquals(2, DateUtils.getDayDifference(time, date1, date2));
        assertEquals(2, DateUtils.getDayDifference(time, date2, date1));
    }
}