Java Calendar Time isFuture(Calendar time)

Here you can find the source of isFuture(Calendar time)

Description

is Future

License

Open Source License

Return

true if time is in or past Future bin

Declaration

public static boolean isFuture(Calendar time) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2009 Tasktop Technologies and others.
 * 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://  ww w.  j a  v  a  2s.  c o m
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

import java.util.Calendar;

public class Main {
    private static int startDay = Calendar.MONDAY;

    /**
     * @return true if time is in or past Future bin
     */
    public static boolean isFuture(Calendar time) {
        if (time != null) {
            Calendar cal = getCalendar();
            cal.add(Calendar.WEEK_OF_MONTH, 2);
            snapStartOfWorkWeek(cal);
            return time.compareTo(cal) > -1;
        }
        return false;
    }

    public static Calendar getCalendar() {
        Calendar cal = Calendar.getInstance();
        cal.setFirstDayOfWeek(startDay);
        cal.getTime();
        return cal;
    }

    public static Calendar snapStartOfWorkWeek(Calendar cal) {
        cal.set(Calendar.DAY_OF_WEEK, startDay);
        snapStartOfDay(cal);
        return cal;
    }

    public static Calendar snapStartOfDay(Calendar cal) {
        cal.set(Calendar.HOUR_OF_DAY, 0);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        cal.getTime();
        return cal;
    }
}

Related

  1. getTimezoneString(Calendar cal)
  2. hasTime(Calendar cal)
  3. hasTimePart(Calendar calendar)
  4. isEquals(Calendar startTime, Calendar timeCurrent, int type)
  5. isFirstMorning(Calendar time, Calendar previous)
  6. isMorning(Calendar time)
  7. isOverTime(Calendar lastTime, Calendar currentTime, Calendar begTime, Calendar endTime)
  8. isSameLocalTime(Calendar cal1, Calendar cal2)
  9. isSameLocalTime(Calendar cal1, Calendar cal2)