Example usage for java.util Calendar getActualMaximum

List of usage examples for java.util Calendar getActualMaximum

Introduction

In this page you can find the example usage for java.util Calendar getActualMaximum.

Prototype

public int getActualMaximum(int field) 

Source Link

Document

Returns the maximum value that the specified calendar field could have, given the time value of this Calendar.

Usage

From source file:com.mobiquitynetworks.statsutilspig.JsonStructure.java

public Map<String, Object> createDateAndUnit(Tuple eventValues, int eventValuesSize) throws ExecException {

    // format for dates
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
    // timezone for dates
    df.setTimeZone(TimeZone.getTimeZone("UTC"));
    // Map to be returned
    Map<String, Object> mapToReturn = new HashMap<>();
    Date b = new Date();
    Date e = new Date();
    String unit = "";

    // case we only have the year so time unit would be '1y'
    if (eventValuesSize == 2) {

        String startDateStr = (Integer) eventValues.get(1) + "-01-01T00:00:00.000Z";
        String endDateStr = (Integer) eventValues.get(1) + "-12-31T23:59:59.999Z";
        try {/*from w w  w  . j  av a  2 s  .  c o m*/
            b = df.parse(startDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            e = df.parse(endDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        unit = "1y";
    }

    // case we have the year and month so time unit would be '1M'
    else if (eventValuesSize == 3) {

        Calendar mycal = new GregorianCalendar((Integer) eventValues.get(1), (Integer) eventValues.get(1) - 1,
                1);
        int days = mycal.getActualMaximum(Calendar.DAY_OF_MONTH);

        String startDateStr = (Integer) eventValues.get(1) + "-" + (Integer) eventValues.get(2)
                + "-01T00:00:00.000Z";
        String endDateStr = (Integer) eventValues.get(1) + "-" + (Integer) eventValues.get(2) + "-" + days
                + "T23:59:59.999Z";
        try {
            b = df.parse(startDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            e = df.parse(endDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        unit = "1M";
    }

    // case we have the year, month and day so time unit would be '1d'
    else if (eventValuesSize == 4) {

        String startDateStr = (Integer) eventValues.get(1) + "-" + (Integer) eventValues.get(2) + "-"
                + (Integer) eventValues.get(3) + "T00:00:00.000Z";
        String endDateStr = (Integer) eventValues.get(1) + "-" + (Integer) eventValues.get(2) + "-"
                + (Integer) eventValues.get(3) + "T23:59:59.999Z";
        try {
            b = df.parse(startDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            e = df.parse(endDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        unit = "1d";
    }

    // case we have the year, month, day and hour so time unit would be '1h'
    else if (eventValuesSize == 5) {

        String startDateStr = (Integer) eventValues.get(1) + "-" + (Integer) eventValues.get(2) + "-"
                + (Integer) eventValues.get(3) + "T" + (Integer) eventValues.get(4) + ":00:00.000Z";
        String endDateStr = (Integer) eventValues.get(1) + "-" + (Integer) eventValues.get(2) + "-"
                + (Integer) eventValues.get(3) + "T" + (Integer) eventValues.get(4) + ":59:59.999Z";
        try {
            b = df.parse(startDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            e = df.parse(endDateStr);
        } catch (ParseException ex) {
            Logger.getLogger(JsonStructure.class.getName()).log(Level.SEVERE, null, ex);
        }
        unit = "1h";
    }
    mapToReturn.put("b", b);
    mapToReturn.put("e", e);
    mapToReturn.put("u", unit);
    return mapToReturn;
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ?//from   w  w w. j  av a 2  s  .c  om
 * 
 * @param date
 * @return
 */
public static int getDayOfMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    return c.getActualMaximum(Calendar.DAY_OF_MONTH);
}

From source file:gov.utah.dts.det.ccl.actions.reports.ReportsPrintAction.java

@Action(value = "print-license-renewal-list")
public void doPrintLicenseRenewalList() {
    Person person = null;//from ww  w .j av  a 2 s . c  om
    if (specialistId != null) {
        person = personService.getPerson(specialistId);
    }
    if (person == null || person.getId() == null) {
        return;
    }

    try {
        // Default endDate to the last day of the current month
        if (endDate == null) {
            Calendar cal = Calendar.getInstance();
            int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            cal.set(Calendar.DAY_OF_MONTH, maxDay);
            endDate = cal.getTime();
        }

        List<FacilityLicenseView> licenses = facilityService.getRenewalLicensesBySpecialist(endDate,
                specialistId);
        ByteArrayOutputStream ba = LicenseRenewalsListReport.generate(person, endDate, licenses);
        if (ba != null && ba.size() > 0) {
            // This is where the response is set
            String filename = "";
            if (person != null) {
                if (StringUtils.isNotBlank(person.getFirstName())) {
                    filename += person.getFirstName();
                }
                if (StringUtils.isNotBlank(person.getLastName())) {
                    if (filename.length() > 0) {
                        filename += "_";
                    }
                    filename += person.getLastName();
                }
            }
            if (filename.length() > 0) {
                filename += "_";
            }
            filename += "license_renewal_list.pdf";
            sendToResponse(ba, filename);
        }
    } catch (Exception ex) {
        generateErrorPdf();
    }
}

From source file:gov.utah.dts.det.ccl.actions.reports.ReportsPrintAction.java

@Action(value = "print-license-renewal-letters")
public void doPrintLicenseRenewalLetters() {
    Person person = null;/*ww  w  .j a  v a2 s . c o m*/
    if (specialistId != null) {
        person = personService.getPerson(specialistId);
    }
    if (person == null || person.getId() == null) {
        return;
    }

    try {
        // Default endDate to the last day of the current month
        if (endDate == null) {
            Calendar cal = Calendar.getInstance();
            int maxDay = cal.getActualMaximum(Calendar.DAY_OF_MONTH);
            cal.set(Calendar.DAY_OF_MONTH, maxDay);
            endDate = cal.getTime();
        }

        List<FacilityLicenseView> licenses = facilityService.getFosterCareRenewalLicensesBySpecialist(endDate,
                specialistId);
        ByteArrayOutputStream ba = LicenseRenewalLettersReport.generate(licenses);
        if (ba != null && ba.size() > 0) {
            // This is where the response is set
            String filename = "";
            if (person != null) {
                if (StringUtils.isNotBlank(person.getFirstName())) {
                    filename += person.getFirstName();
                }
                if (StringUtils.isNotBlank(person.getLastName())) {
                    if (filename.length() > 0) {
                        filename += "_";
                    }
                    filename += person.getLastName();
                }
            }
            if (filename.length() > 0) {
                filename += "_";
            }
            filename += "license_renewal_letters.pdf";
            sendToResponse(ba, filename);
        }
    } catch (Exception ex) {
        generateErrorPdf();
    }
}

From source file:org.eclipse.smarthome.binding.astro.internal.calc.SunCalc.java

/**
 * Calculates sun radiation data./*from  w  w  w .  j  a  v a2s .co m*/
 */
public void setRadiationInfo(Calendar calendar, double elevation, Double altitude, Sun sun) {
    double sinAlpha = Math.sin(DEG2RAD * elevation);

    int dayOfYear = calendar.get(Calendar.DAY_OF_YEAR);
    int daysInYear = calendar.getActualMaximum(Calendar.DAY_OF_YEAR);

    // Direct Solar Radiation (in W/m) at the atmosphere entry
    // At sunrise/sunset - calculations limits are reached
    double rOut = (elevation > 3) ? SC * (0.034 * Math.cos(DEG2RAD * (360 * dayOfYear / daysInYear)) + 1) : 0;
    double altitudeRatio = (altitude != null) ? 1 / Math.pow((1 - (6.5 / 288) * (altitude / 1000.0)), 5.256)
            : 1;
    double m = (Math.sqrt(1229 + Math.pow(614 * sinAlpha, 2)) - 614 * sinAlpha) * altitudeRatio;

    // Direct radiation after atmospheric layer
    // 0.6 = Coefficient de transmissivit
    double rDir = rOut * Math.pow(0.6, m) * sinAlpha;

    // Diffuse Radiation
    double rDiff = rOut * (0.271 - 0.294 * Math.pow(0.6, m)) * sinAlpha;
    double rTot = rDir + rDiff;

    Radiation radiation = sun.getRadiation();
    radiation.setDirect(rDir);
    radiation.setDiffuse(rDiff);
    radiation.setTotal(rTot);
}

From source file:org.kuali.kfs.module.endow.businessobject.lookup.CalculateProcessDateUsingFrequencyCodeService.java

/**
 * Method to calculate the next processing week date based on the frequency type
 * adds the appropriate number of days to the current date
 * @param dayOfWeek// w w w . j  a v  a2  s .c  om
 * @return next processing date
 */
protected Date calculateNextWeeklyDate(String dayOfWeekFromFrequencyCode, Date currentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);

    int daysToAdd = 0;
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); // today's day of the week
    int maximumDaysInWeek = calendar.getActualMaximum(Calendar.DAY_OF_WEEK);

    if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.MONDAY)) {
        if (dayOfWeek < Calendar.MONDAY)
            daysToAdd = Calendar.MONDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.MONDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.TUESDAY)) {
        if (dayOfWeek < Calendar.TUESDAY)
            daysToAdd = Calendar.TUESDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.TUESDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.WEDNESDAY)) {
        if (dayOfWeek < Calendar.WEDNESDAY)
            daysToAdd = Calendar.WEDNESDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.WEDNESDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.THURSDAY)) {
        if (dayOfWeek < Calendar.THURSDAY)
            daysToAdd = Calendar.THURSDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.THURSDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.FRIDAY)) {
        if (dayOfWeek < Calendar.FRIDAY)
            daysToAdd = Calendar.FRIDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.FRIDAY;
    }

    calendar.add(Calendar.DAY_OF_MONTH, daysToAdd);

    return new java.sql.Date(calendar.getTimeInMillis());
}

From source file:org.kuali.kfs.module.endow.document.service.impl.FrequencyDatesServiceImpl.java

/**
 * Method to calculate the next processing week date based on the frequency type
 * adds the appropriate number of days to the current date
 * @param dayOfWeek/* w w w  . jav a2  s . c om*/
 * @return next processing date
 */
protected Calendar calculateNextWeeklyDate(String dayOfWeekFromFrequencyCode, Date currentDate) {
    Calendar calendar = Calendar.getInstance();
    calendar.setTime(currentDate);

    int daysToAdd = 0;
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); // today's day of the week
    int maximumDaysInWeek = calendar.getActualMaximum(Calendar.DAY_OF_WEEK);

    if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.MONDAY)) {
        if (dayOfWeek < Calendar.MONDAY)
            daysToAdd = Calendar.MONDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.MONDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.TUESDAY)) {
        if (dayOfWeek < Calendar.TUESDAY)
            daysToAdd = Calendar.TUESDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.TUESDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.WEDNESDAY)) {
        if (dayOfWeek < Calendar.WEDNESDAY)
            daysToAdd = Calendar.WEDNESDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.WEDNESDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.THURSDAY)) {
        if (dayOfWeek < Calendar.THURSDAY)
            daysToAdd = Calendar.THURSDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.THURSDAY;
    } else if (dayOfWeekFromFrequencyCode.equalsIgnoreCase(EndowConstants.FrequencyWeekDays.FRIDAY)) {
        if (dayOfWeek < Calendar.FRIDAY)
            daysToAdd = Calendar.FRIDAY - dayOfWeek;
        else
            daysToAdd = maximumDaysInWeek - dayOfWeek + Calendar.FRIDAY;
    }

    calendar.add(Calendar.DAY_OF_MONTH, daysToAdd);

    return calendar;
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ?/*from ww  w .j a  va  2  s  .c om*/
 * 
 * @param date
 * @return
 */
@SuppressWarnings("deprecation")
public static Date getLastDayOfMonth(Date date) {
    Calendar cDay1 = Calendar.getInstance();
    cDay1.setTime(date);
    int lastDay = cDay1.getActualMaximum(Calendar.DAY_OF_MONTH);
    Date lastDate = cDay1.getTime();
    lastDate.setDate(lastDay);
    return lastDate;
}

From source file:cn.mljia.common.notify.utils.DateUtils.java

/**
 * ??/*  w w  w .  j a v a2s. co m*/
 * 
 * @param date
 * @return
 */
public static Date getLastDateOfMonth(Date date) {
    Calendar c = Calendar.getInstance();
    c.setTime(date);
    c.set(Calendar.DAY_OF_MONTH, c.getActualMaximum(Calendar.DAY_OF_MONTH));
    return c.getTime();
}

From source file:com.persistent.cloudninja.service.impl.MeteringTotalsDataServiceImpl.java

/**
 * Returns list of all the dates in the given year and month
 * /*  w  ww  .ja va  2s .c o m*/
 * @param month
 * @param year
 * @return
 */
private List<String> getAllMonthDates(String month, String year) {

    List<String> dateList = new ArrayList<String>();

    String date = month + "/" + 1 + "/" + year;
    SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy");
    Date calDate = null;

    Calendar calendar = Calendar.getInstance();
    try {
        calDate = formatter.parse(date);
    } catch (ParseException e) {
        e.printStackTrace();
    }
    calendar.setTime(calDate);
    // Add first date to list
    dateList.add(formatter.format(calDate));
    // Get number of days in the given month
    int maxDay = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    String dateStr;
    for (int i = 0; i < maxDay - 1; i++) {
        calendar.add(Calendar.DATE, 1);
        Date newDate = calendar.getTime();
        dateStr = formatter.format(newDate);
        dateList.add(dateStr);
    }
    return dateList;
}