Android Yesterday Get isYesterday(long date)

Here you can find the source of isYesterday(long date)

Description

Checks if the given date is yesterday.

Parameter

Parameter Description
date - Date to check.

Return

TRUE if the date is yesterday, FALSE otherwise.

Declaration

public static boolean isYesterday(long date) 

Method Source Code

import android.content.Context;
import android.text.format.DateUtils;
import org.lytsing.android.weibo.R;
import java.text.DateFormatSymbols;
import java.util.Calendar;

public class Main{
    private static String sTimestampLabelYesterday;
    private static String sTimestampLabelToday;
    private static String sTimestampLabelJustNow;
    private static String sTimestampLabelMinutesAgo;
    private static String sTimestampLabelHoursAgo;
    private static String sTimestampLabelHourAgo;
    private static Context sCtx;
    private static DateTimeUtils sInstance = null;
    /**/*from   w ww. j a v a  2  s . c om*/
     * Checks if the given date is yesterday.
     * 
     * @param date
     *            - Date to check.
     * @return TRUE if the date is yesterday, FALSE otherwise.
     */
    public static boolean isYesterday(long date) {

        final Calendar currentDate = Calendar.getInstance();
        currentDate.setTimeInMillis(date);

        final Calendar yesterdayDate = Calendar.getInstance();
        yesterdayDate.add(Calendar.DATE, -1);

        return yesterdayDate.get(Calendar.YEAR) == currentDate
                .get(Calendar.YEAR)
                && yesterdayDate.get(Calendar.DAY_OF_YEAR) == currentDate
                        .get(Calendar.DAY_OF_YEAR);
    }
    /**
     * Singleton contructor. needed to get access to the application context &
     * strings for i18n
     * 
     * @param context
     *            Context
     * @return DateTimeUtils singleton instanec
     * @throws Exception
     */
    public static DateTimeUtils getInstance(Context context) {
        sCtx = context;
        if (sInstance == null) {
            sInstance = new DateTimeUtils();
            sTimestampLabelYesterday = context.getResources().getString(
                    R.string.WidgetProvider_timestamp_yesterday);
            sTimestampLabelToday = context.getResources().getString(
                    R.string.WidgetProvider_timestamp_today);
            sTimestampLabelJustNow = context.getResources().getString(
                    R.string.WidgetProvider_timestamp_just_now);
            sTimestampLabelMinutesAgo = context.getResources().getString(
                    R.string.WidgetProvider_timestamp_minutes_ago);
            sTimestampLabelHoursAgo = context.getResources().getString(
                    R.string.WidgetProvider_timestamp_hours_ago);
            sTimestampLabelHourAgo = context.getResources().getString(
                    R.string.WidgetProvider_timestamp_hour_ago);
        }
        return sInstance;
    }
}

Related

  1. getYestoday(String sourceDate, String format)
  2. getYestoday(String sourceDate, String format)
  3. getFormatYestoday(String format)
  4. getYesterdayFormattedTime()
  5. getYesterday()