Java Calendar Day afterCurrentDay(Calendar time)

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

Description

after Current Day

License

Open Source License

Declaration

public static boolean afterCurrentDay(Calendar time) 

Method Source Code


//package com.java2s;
/*//from w w w.  jav  a 2 s.  c om
 * Copyright 2009 Yodlee, Inc.  All Rights Reserved.  Your use of this code 
 * requires a license from Yodlee.  Any such license to this code is 
 * restricted to evaluation/illustrative purposes only. It is not intended 
 * for use in a production environment, and Yodlee disclaims all warranties 
 * and/or support obligations concerning this code, regardless of the terms 
 * of any other agreements between Yodlee and you."
 */

import java.util.Calendar;

public class Main {
    public static boolean afterCurrentDay(Calendar time) {
        boolean afterCurrent = false;

        Calendar currentTime = createCalendar(System.currentTimeMillis());
        int yearOfTime = getYear(time);
        int yearOfCurrentTime = getYear(currentTime);

        if (yearOfTime > yearOfCurrentTime)
            afterCurrent = true;
        else if (yearOfTime == yearOfCurrentTime && getDay(time) > getDay(currentTime))
            afterCurrent = true;

        return afterCurrent;
    }

    public static Calendar createCalendar(long timeInMillis) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(timeInMillis);
        calendar.setMinimalDaysInFirstWeek(calculateMinimalDaysInFirstWeek(calendar));
        return calendar;
    }

    public static int getYear(Calendar calendar) {
        return calendar.get(Calendar.YEAR);
    }

    public static int getDay(Calendar calendar) {
        return calendar.get(Calendar.DAY_OF_YEAR);
    }

    public static int calculateMinimalDaysInFirstWeek(Calendar calendar) {

        Calendar temp = (Calendar) calendar.clone();
        temp.set(Calendar.DAY_OF_YEAR, 1);
        int firstDayOfJan = temp.get(Calendar.DAY_OF_WEEK);
        return 8 - firstDayOfJan;
    }
}

Related

  1. absoluteDay(Calendar cal)
  2. absoluteDay(Calendar cal, boolean use1904windowing)
  3. calendarAtStartOfToday()
  4. calendarDayToOrdinalDay(int dow)
  5. calToBeginningOfDay(Calendar c)
  6. ceilAllLessThanDay(Calendar cal)