Example usage for java.util Calendar after

List of usage examples for java.util Calendar after

Introduction

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

Prototype

public boolean after(Object when) 

Source Link

Document

Returns whether this Calendar represents a time after the time represented by the specified Object.

Usage

From source file:org.kuali.coeus.common.budget.impl.personnel.BudgetPersonServiceImpl.java

/**
 * /*  w  w  w  .j a v a2 s. c o m*/
 * Determines if an appointment is applicable to the current budget, currently
 * based solely on whether the budget period matches some part of the appointment
 * period
 * @param budget
 * @param appointment
 * @return true if the appointment start or end date is inside the budget period
 */
protected boolean isAppointmentApplicableToBudget(Budget budget, PersonAppointment appointment) {
    Calendar budgetStart = Calendar.getInstance();
    Calendar budgetEnd = Calendar.getInstance();
    Calendar apptStart = Calendar.getInstance();
    Calendar apptEnd = Calendar.getInstance();
    budgetStart.setTime(budget.getStartDate());
    budgetEnd.setTime(budget.getEndDate());
    if (appointment.getStartDate() != null) {
        apptStart.setTime(appointment.getStartDate());
    } else {
        apptStart.setTime(budget.getStartDate());
    }
    if (appointment.getEndDate() != null) {
        apptEnd.setTime(appointment.getEndDate());
    } else {
        apptEnd.setTime(budget.getEndDate());
    }
    if (budgetStart.before(apptEnd) && budgetEnd.after(apptStart)) {
        return true;
    } else {
        return false;
    }
}

From source file:com.versobit.weatherdoge.WeatherUtil.java

private static String convertYahooCode(String code, String weatherTime, String sunrise, String sunset) {
    Date weatherDate = new Date();
    try {//  w w  w .j a va  2  s  .  c o m
        weatherDate = YAHOO_DATE_FORMAT.parse(weatherTime);
    } catch (ParseException ex) {
        Log.e(TAG, "Yahoo date format failed!", ex);
    }
    Calendar weatherCal = new GregorianCalendar();
    Calendar sunriseCal = new GregorianCalendar();
    Calendar sunsetCal = new GregorianCalendar();
    weatherCal.setTime(weatherDate);
    sunriseCal.setTime(weatherDate);
    sunsetCal.setTime(weatherDate);

    Matcher sunriseMatch = YAHOO_TIME.matcher(sunrise);
    Matcher sunsetMatch = YAHOO_TIME.matcher(sunset);
    if (!sunriseMatch.matches() || !sunsetMatch.matches()) {
        Log.e(TAG, "Failed to find sunrise/sunset. Using defaults.");
        sunriseMatch = YAHOO_TIME.matcher("6:00 am");
        sunsetMatch = YAHOO_TIME.matcher("6:00 pm");
        sunriseMatch.matches();
        sunsetMatch.matches();
    }
    // Set the sunrise to the correct hour and minute of the same day
    sunriseCal.set(Calendar.HOUR, Integer.parseInt(sunriseMatch.group(1)));
    sunriseCal.set(Calendar.MINUTE, Integer.parseInt(sunriseMatch.group(2)));
    sunriseCal.set(Calendar.SECOND, 0);
    sunriseCal.set(Calendar.MILLISECOND, 0);
    sunriseCal.set(Calendar.AM_PM, "am".equals(sunriseMatch.group(3)) ? Calendar.AM : Calendar.PM);

    // Set the sunset to the correct hour and minute of the same day
    sunsetCal.set(Calendar.HOUR, Integer.parseInt(sunsetMatch.group(1)));
    sunsetCal.set(Calendar.MINUTE, Integer.parseInt(sunsetMatch.group(2)));
    sunsetCal.set(Calendar.SECOND, 0);
    sunsetCal.set(Calendar.MILLISECOND, 0);
    sunsetCal.set(Calendar.AM_PM, "am".equals(sunsetMatch.group(3)) ? Calendar.AM : Calendar.PM);

    boolean isDaytime = true;
    if (weatherCal.before(sunriseCal) || weatherCal.after(sunsetCal)) {
        isDaytime = false;
    }

    String owmCode = "01";
    switch (Integer.parseInt(code)) {
    // Thunderstorms
    case 0:
    case 1:
    case 2:
    case 3:
    case 4:
    case 17:
    case 37:
    case 38:
    case 39:
    case 45:
    case 47:
        owmCode = "11";
        break;
    // Snow
    case 5:
    case 7:
    case 13:
    case 14:
    case 15:
    case 16:
    case 18:
    case 41:
    case 42:
    case 43:
    case 46:
        owmCode = "13";
        break;
    // Rain
    case 6:
    case 10:
    case 35:
        owmCode = "09";
        break;
    // Light-ish Rain
    case 8:
    case 9:
    case 11:
    case 12:
    case 40:
        owmCode = "10";
        break;
    // Fog
    case 19:
    case 20:
    case 21:
    case 22:
        owmCode = "50";
        break;
    // Cloudy
    case 27:
    case 28:
        owmCode = "04";
        break;
    // (Other) Cloudy
    case 26:
        owmCode = "03";
        break;
    // Partly Cloudy
    case 23:
    case 24:
    case 25:
    case 29:
    case 30:
    case 44:
        owmCode = "02";
        break;
    // Clear
    case 31:
    case 32:
    case 33:
    case 34:
    case 36:
        owmCode = "01";
        break;
    }
    return owmCode + (isDaytime ? "d" : "n");
}

From source file:org.openmrs.module.lancearmstrong.LafServiceImpl.java

/**
  * Match a target date with a completed date based on 7-day-proximity rule
  * /*  w  w  w  .  ja  va2  s.  c o  m*/
  * @param targetDate
  * @param lastCompleted
  * @return
  */
private boolean matchCompletedDate(Date targetDate, Date lastCompleted) {
    // TODO Auto-generated method stub
    Calendar calTarget1 = Calendar.getInstance();
    calTarget1.setTime(targetDate);
    calTarget1.add(Calendar.DATE, MATCH_DAYS);
    Calendar calTarget2 = Calendar.getInstance();
    calTarget2.setTime(targetDate);
    calTarget2.add(Calendar.DATE, -MATCH_DAYS);

    Calendar calCompl = Calendar.getInstance();
    calCompl.setTime(lastCompleted);

    if (calCompl.before(calTarget1) && calCompl.after(calTarget2)) {
        return true;
    }
    return false;
}

From source file:gov.utah.dts.sdc.actions.CommercialStudentCreateAction.java

/**
 * Checks if date1 is in the between date2 and today date inclusively.
 * @param date1/* ww  w.  java  2 s .co  m*/
 * @param date2
 * @return
 */
private boolean isValidCompletionDate(Date date1, Date date2) {

    Calendar today = Calendar.getInstance();
    Calendar date1Cal = Calendar.getInstance();
    date1Cal.setTime(date1);
    Calendar date2Cal = Calendar.getInstance();
    date2Cal.setTime(date2);

    // set hour, minute, and secod to 0
    today.set(Calendar.HOUR_OF_DAY, 0);
    today.set(Calendar.MINUTE, 0);
    today.set(Calendar.SECOND, 0);
    today.set(Calendar.MILLISECOND, 0);
    date1Cal.set(Calendar.HOUR_OF_DAY, 0);
    date1Cal.set(Calendar.MINUTE, 0);
    date1Cal.set(Calendar.SECOND, 0);
    date1Cal.set(Calendar.MILLISECOND, 0);
    date2Cal.set(Calendar.HOUR_OF_DAY, 0);
    date2Cal.set(Calendar.MINUTE, 0);
    date2Cal.set(Calendar.SECOND, 0);

    if (date2Cal.after(today))
        return false;

    if (date1Cal.equals(date2Cal) || date1Cal.equals(today))
        return true;

    if (date1Cal.before(today) && date1Cal.after(date2Cal))
        return true;

    return false;
}

From source file:org.everit.jira.timetracker.plugin.JiraTimetrackerPluginImpl.java

@Override
public List<Date> getDates(final String selectedUser, final Date from, final Date to, final boolean workingHour,
        final boolean checkNonWorking) throws GenericEntityException {
    List<Date> datesWhereNoWorklog = new ArrayList<Date>();
    Calendar fromDate = Calendar.getInstance();
    fromDate.setTime(from);// ww w .  j a v  a 2s  .c  o  m
    Calendar toDate = Calendar.getInstance();
    toDate.setTime(to);
    while (!fromDate.after(toDate)) {
        String currentDateString = DateTimeConverterUtil.dateToString(fromDate.getTime());
        if (excludeDatesSet.contains(currentDateString)) {
            fromDate.add(Calendar.DATE, 1);
            continue;
        }
        // check includes - not check weekend
        // check weekend - pass
        if (!includeDatesSet.contains(currentDateString)
                && ((fromDate.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY)
                        || (fromDate.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY))) {
            fromDate.add(Calendar.DATE, 1);
            continue;
        }
        // check worklog. if no worklog set result else ++ scanedDate
        boolean isDateContainsWorklog;
        if (workingHour) {
            isDateContainsWorklog = isContainsEnoughWorklog(fromDate.getTime(), checkNonWorking);
        } else {
            isDateContainsWorklog = isContainsWorklog(fromDate.getTime());
        }
        if (!isDateContainsWorklog) {
            datesWhereNoWorklog.add((Date) fromDate.getTime().clone());
        }
        fromDate.add(Calendar.DATE, 1);

    }
    Collections.reverse(datesWhereNoWorklog);
    return datesWhereNoWorklog;
}

From source file:com.nadmm.airports.ActivityBase.java

public void showAirportTitle(Cursor c) {
    View root = findViewById(R.id.airport_title_layout);
    TextView tv = (TextView) root.findViewById(R.id.facility_name);
    String code = c.getString(c.getColumnIndex(Airports.ICAO_CODE));
    if (code == null || code.length() == 0) {
        code = c.getString(c.getColumnIndex(Airports.FAA_CODE));
    }/*  ww w  .ja v a2  s  .  co  m*/
    String tower = c.getString(c.getColumnIndex(Airports.TOWER_ON_SITE));
    int color = tower.equals("Y") ? Color.rgb(48, 96, 144) : Color.rgb(128, 72, 92);
    tv.setTextColor(color);
    String name = c.getString(c.getColumnIndex(Airports.FACILITY_NAME));
    String siteNumber = c.getString(c.getColumnIndex(Airports.SITE_NUMBER));
    String type = DataUtils.decodeLandingFaclityType(siteNumber);
    tv.setText(String.format(Locale.US, "%s %s", name, type));
    tv = (TextView) root.findViewById(R.id.facility_id);
    tv.setTextColor(color);
    tv.setText(code);
    tv = (TextView) root.findViewById(R.id.facility_info);
    String city = c.getString(c.getColumnIndex(Airports.ASSOC_CITY));
    String state = c.getString(c.getColumnIndex(States.STATE_NAME));
    if (state == null) {
        state = c.getString(c.getColumnIndex(Airports.ASSOC_COUNTY));
    }
    tv.setText(String.format(Locale.US, "%s, %s", city, state));
    tv = (TextView) root.findViewById(R.id.facility_info2);
    int distance = c.getInt(c.getColumnIndex(Airports.DISTANCE_FROM_CITY_NM));
    String dir = c.getString(c.getColumnIndex(Airports.DIRECTION_FROM_CITY));
    String status = c.getString(c.getColumnIndex(Airports.STATUS_CODE));
    tv.setText(String.format(Locale.US, "%s, %d miles %s of city center", DataUtils.decodeStatus(status),
            distance, dir));
    tv = (TextView) root.findViewById(R.id.facility_info3);
    float elev_msl = c.getFloat(c.getColumnIndex(Airports.ELEVATION_MSL));
    int tpa_agl = c.getInt(c.getColumnIndex(Airports.PATTERN_ALTITUDE_AGL));
    String est = "";
    if (tpa_agl == 0) {
        tpa_agl = 1000;
        est = " (est.)";
    }
    tv.setText(String.format(Locale.US, "%s MSL elev. - %s MSL TPA %s", FormatUtils.formatFeet(elev_msl),
            FormatUtils.formatFeet(elev_msl + tpa_agl), est));

    String s = c.getString(c.getColumnIndex(Airports.EFFECTIVE_DATE));
    GregorianCalendar endDate = new GregorianCalendar(Integer.valueOf(s.substring(6)),
            Integer.valueOf(s.substring(3, 5)), Integer.valueOf(s.substring(0, 2)));
    // Calculate end date of the 56-day cycle
    endDate.add(GregorianCalendar.DAY_OF_MONTH, 56);
    Calendar now = Calendar.getInstance();
    if (now.after(endDate)) {
        // Show the expired warning
        tv = (TextView) root.findViewById(R.id.expired_label);
        tv.setVisibility(View.VISIBLE);
    }

    CheckBox cb = (CheckBox) root.findViewById(R.id.airport_star);
    cb.setChecked(mDbManager.isFavoriteAirport(siteNumber));
    cb.setTag(siteNumber);
    cb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            CheckBox cb = (CheckBox) v;
            String siteNumber = (String) cb.getTag();
            if (cb.isChecked()) {
                mDbManager.addToFavoriteAirports(siteNumber);
                Toast.makeText(ActivityBase.this, "Added to favorites list", Toast.LENGTH_LONG).show();
            } else {
                mDbManager.removeFromFavoriteAirports(siteNumber);
                Toast.makeText(ActivityBase.this, "Removed from favorites list", Toast.LENGTH_LONG).show();
            }
        }

    });

    ImageView iv = (ImageView) root.findViewById(R.id.airport_map);
    String lat = c.getString(c.getColumnIndex(Airports.REF_LATTITUDE_DEGREES));
    String lon = c.getString(c.getColumnIndex(Airports.REF_LONGITUDE_DEGREES));
    if (lat.length() > 0 && lon.length() > 0) {
        iv.setTag("geo:" + lat + "," + lon + "?z=16");
        iv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                String tag = (String) v.getTag();
                Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(tag));
                startActivity(intent);
            }

        });
    } else {
        iv.setVisibility(View.GONE);
    }
}

From source file:com.ecofactor.qa.automation.newapp.service.DataServiceImpl.java

/**
 * Gets the current base temp.//from  www .  jav  a 2  s  .  com
 * 
 * @param thermostatId
 *            the thermostat id
 * @param mode
 *            the mode
 * @return the current base temp
 * @see com.ecofactor.qa.automation.algorithm.service.DataService#getCurrentBaseTemp(java.lang.Integer,
 *      java.lang.String)
 */
public double getCurrentBaseTemp(Integer thermostatId, String mode) {

    double baseTemp = 0;
    List<ThermostatProgramLog> programList = tstatProgLogDao.listUTCCurrentDayLog(thermostatId,
            DateUtil.getUTCDayOfWeek());
    for (ThermostatProgramLog tstatProgramLog : programList) {

        Date startTimeUTC = tstatProgramLog.getStartTimeUTC();
        Date endTimeUTC = tstatProgramLog.getEndTimeUTC();

        DateTime startTimeJoda = new DateTime(startTimeUTC);
        DateTime endTimeJoda = new DateTime(endTimeUTC);

        Calendar startCalendar = DateUtil.convertTimeToUTCCalendar(startTimeJoda);
        Calendar endCalendar = DateUtil.convertTimeToUTCCalendar(endTimeJoda);
        Calendar utcCalendar = DateUtil.getUTCCalendar();

        if (!endCalendar.before(utcCalendar) && !startCalendar.after(utcCalendar)) {

            if (mode.equalsIgnoreCase("Cool")) {
                baseTemp = tstatProgramLog.getCoolSetting();
            } else if (mode.equalsIgnoreCase("Heat")) {
                baseTemp = tstatProgramLog.getHeatSetting();
            }
            break;
        }
    }

    DriverConfig.setLogString("Base Temp from Program Log table : " + baseTemp, true);
    LOGGER.debug("Base Temp from Program Log table : " + baseTemp, true);
    return baseTemp;
}

From source file:com.wdullaer.materialdatetimepicker.date.DatePickerDialog.java

private boolean isAfterMax(Calendar calendar) {
    return mMaxDate != null && calendar.after(mMaxDate);
}

From source file:org.richfaces.component.UICalendar.java

public Date[] getPreloadDateRange() {
    Date dateRangeBegin = getAsDate(this.getPreloadDateRangeBegin());
    Date dateRangeEnd = getAsDate(this.getPreloadDateRangeEnd());

    if (dateRangeBegin == null && dateRangeEnd == null) {
        return null;
    } else {/*from   w  w w  . ja  va  2  s .c o  m*/
        if (dateRangeBegin.after(dateRangeEnd)) {
            // XXX add message
            FacesMessage message = new FacesMessage(
                    "preloadDateRangeBegin is greater than preloadDateRangeEnd");
            message.setSeverity(FacesMessage.SEVERITY_ERROR);
            FacesContext context = FacesContext.getCurrentInstance();
            context.addMessage(getClientId(context), message);
            throw new IllegalArgumentException();
        }

        List<Date> dates = new ArrayList<Date>();

        Calendar calendar = Calendar.getInstance(this.getTimeZone(), getAsLocale(this.getLocale()));
        Calendar calendar2 = (Calendar) calendar.clone();
        calendar.setTime(dateRangeBegin);
        calendar2.setTime(dateRangeEnd);

        do {
            dates.add(calendar.getTime());
            calendar.add(Calendar.DATE, 1);
        } while (!calendar.after(calendar2));

        return (Date[]) dates.toArray(new Date[dates.size()]);
    }
}

From source file:org.kuali.ole.pdp.service.impl.PaymentFileValidationServiceImpl.java

/**
 * Checks the payment date is not more than 30 days past or 30 days coming
 * /*from  w w w .j  av a2s . co m*/
 * @param paymentGroup <code>PaymentGroup</code> being checked
 * @param warnings <code>List</code> list of accumulated warning messages
 */
protected void checkGroupPaymentDate(PaymentGroup paymentGroup, List<String> warnings) {
    Timestamp now = dateTimeService.getCurrentTimestamp();

    Calendar nowPlus30 = Calendar.getInstance();
    nowPlus30.setTime(now);
    nowPlus30.add(Calendar.DATE, 30);

    Calendar nowMinus30 = Calendar.getInstance();
    nowMinus30.setTime(now);
    nowMinus30.add(Calendar.DATE, -30);

    if (paymentGroup.getPaymentDate() != null) {
        Calendar payDate = Calendar.getInstance();
        payDate.setTime(paymentGroup.getPaymentDate());

        if (payDate.before(nowMinus30)) {
            addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_PAYDATE_OVER_30_DAYS_PAST,
                    dateTimeService.toDateString(paymentGroup.getPaymentDate()));
        }

        if (payDate.after(nowPlus30)) {
            addWarningMessage(warnings, PdpKeyConstants.MESSAGE_PAYMENT_LOAD_PAYDATE_OVER_30_DAYS_OUT,
                    dateTimeService.toDateString(paymentGroup.getPaymentDate()));
        }
    } else {
        try {
            paymentGroup.setPaymentDate(dateTimeService.convertToSqlDate(now));
        } catch (ParseException e) {
            throw new RuntimeException("Unable to parse current timestamp into sql date " + e.getMessage());
        }
    }
}