Java Date Calculate calculateLookbackDate(int lookback)

Here you can find the source of calculateLookbackDate(int lookback)

Description

calculate Lookback Date

License

Open Source License

Declaration

public static Date calculateLookbackDate(int lookback) 

Method Source Code


//package com.java2s;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

public class Main {
    static List<Date> holidayList = new ArrayList<Date>();

    public static Date calculateLookbackDate(int lookback) {

        // today//from   w w  w.ja  va 2  s  .com
        Date dayCounter = new Date();

        int validDatesCounter = lookback;
        while (validDatesCounter > 0) {

            // check for weekends and holiday list         
            dayCounter.setDate(dayCounter.getDate() - 1);

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(dayCounter);

            if (calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY
                    && calendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY && !holidayList.contains(dayCounter)) {
                validDatesCounter--;

            }
        }

        return dayCounter;

    }
}

Related

  1. calculateDate(Date date, int field, int value)
  2. calculateDays(Date startDate, Date endDate)
  3. calculateDurationEndInSec(Date start, int durationInSeconds)
  4. calculateEndDate(Date startDate, int duration)
  5. calculateGestationAge(Date today, Date edd)
  6. calculateMonthIn(Date date1, Date date2)
  7. calculateNextSettleDate(Date date, int addMonth)
  8. calculateOffsetFromGMT(Date date)
  9. calculatePastDate(int days)