Java Calendar Minute isNow(Calendar cal, Locale locale, boolean minuteCheck)

Here you can find the source of isNow(Calendar cal, Locale locale, boolean minuteCheck)

Description

is Now

License

Open Source License

Declaration

public static boolean isNow(Calendar cal, Locale locale, boolean minuteCheck) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) Emil Crumhorn - Hexapixel.com - emil.crumhorn@gmail.com
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*  w  w w  . j a v a2s .co  m*/
 *    emil.crumhorn@gmail.com - initial API and implementation
 *******************************************************************************/

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

import java.util.Locale;

public class Main {
    private static int _todayYear;
    private static int _todayYearDate;
    private static Locale _locale;

    public static boolean isNow(Calendar cal, Locale locale, boolean minuteCheck) {
        if (isToday(cal)) {
            Calendar today = Calendar.getInstance(locale);

            if (today.get(Calendar.HOUR_OF_DAY) == cal.get(Calendar.HOUR_OF_DAY)) {

                if (!minuteCheck) {
                    return true;
                }

                if (today.get(Calendar.MINUTE) == cal.get(Calendar.MINUTE)) {
                    return true;
                }
            }
        }

        return false;
    }

    public static boolean isToday(Date date) {
        Calendar cal = Calendar.getInstance(_locale);
        cal.setTime(date);

        return isToday(cal);
    }

    /**
     * Remember to ensure the correct locale is set on the calendar before using this method.
     * 
     * @param cal Calendar to check
     * @return true if calendar matches todays date
     */
    public static boolean isToday(Calendar cal) {
        return (cal.get(Calendar.YEAR) == _todayYear && cal.get(Calendar.DAY_OF_YEAR) == _todayYearDate);
    }
}

Related

  1. getMinutes(Calendar cal)
  2. getMinutes(Calendar cal1, Calendar cal2)
  3. getMinutes(String expression, Calendar time)
  4. getMinutesInterval(Calendar start, Calendar end)
  5. getOffsetInMinutes(Calendar cal)
  6. minuteFloor(Calendar calendar)
  7. roundByMinutes(Calendar cal, int interval)
  8. setCalendarHourMinSec(final Calendar originalCalendar, final int hourOfDay, final int minute, final int second)
  9. setCalendarTime(Calendar calendar, int hour, int minute, int second, int millis)