1 /* 2 * Copyright (C) 2010 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.contacts.common.util; 18 19 import android.text.format.Time; 20 21 /** Utility methods for processing dates. */ 22 public class DateUtils { 23 24 /** 25 * Determine the difference, in days between two dates. Uses similar logic as the {@link 26 * android.text.format.DateUtils.getRelativeTimeSpanString} method. 27 * 28 * @param time Instance of time object to use for calculations. 29 * @param date1 First date to check. 30 * @param date2 Second date to check. 31 * @return The absolute difference in days between the two dates. 32 */ getDayDifference(Time time, long date1, long date2)33 public static int getDayDifference(Time time, long date1, long date2) { 34 time.set(date1); 35 int startDay = Time.getJulianDay(date1, time.gmtoff); 36 37 time.set(date2); 38 int currentDay = Time.getJulianDay(date2, time.gmtoff); 39 40 return Math.abs(currentDay - startDay); 41 } 42 } 43