Example usage for com.google.gwt.user.datepicker.client CalendarUtil getDaysBetween

List of usage examples for com.google.gwt.user.datepicker.client CalendarUtil getDaysBetween

Introduction

In this page you can find the example usage for com.google.gwt.user.datepicker.client CalendarUtil getDaysBetween.

Prototype

public static int getDaysBetween(Date start, Date finish) 

Source Link

Document

Returns the number of days between the two dates.

Usage

From source file:com.gwtmodel.table.DateUtil.java

License:Apache License

public static int noDays(final Date from, Date to) {
    return CalendarUtil.getDaysBetween(from, to);
}

From source file:fr.gael.dhus.gwt.client.page.statistics.StatisticsConnections.java

License:Open Source License

private static void refreshScale() {
    DateTimeFormat dtf = DateTimeFormat.getFormat("yyyy-MM-dd");
    Date start = dtf.parse(startDate.getValue());
    Date end = dtf.parse(endDate.getValue());
    int nbDays = CalendarUtil.getDaysBetween(start, end) + 1;
    dayLabel.getElement().setInnerText("Per day (" + nbDays + " results)");
    hourLabel.getElement().setInnerText("Per hour (" + nbDays * 24 + " results)");
}

From source file:nz.co.iswe.craftgarden.formdisplay.client.views.ChildSectionViewImpl.java

License:Open Source License

private void calcAge(Date date) {
    Date today = new Date();
    int days = CalendarUtil.getDaysBetween(date, today);
    int age = days / 366;
    ageLabel.setInnerText(age + " years old.");
}

From source file:org.cruxframework.crux.widgets.client.datepicker.DatePicker.java

License:Apache License

/**
 * Add a style name to the given dates.//from www  .  ja  v  a  2s  .co m
 */
public void addStyleToDates(String styleName, Date initDate, Date finalDate) {
    Date currentDate = CalendarUtil.copyDate(initDate);
    int days = CalendarUtil.getDaysBetween(initDate, finalDate);
    for (int i = 0; i < days; i++) {
        CalendarUtil.addDaysToDate(currentDate, 1);
        addStyleToDates(styleName, currentDate);
    }
}

From source file:org.geosdi.geoplatform.gui.client.form.binding.UserPropertiesBinding.java

License:Open Source License

private void handleFieldsUpdateUser() {
    GPUserManageDetail user = super.getModel();

    this.nameField.setValidator(this.validatorUpdateName());
    this.nameField.setAllowBlank(true);

    this.emailField.setValidator(this.validatorUpdateEmail());
    this.emailField.setAllowBlank(true);

    this.usernameField.disable();

    this.passwordField.setFieldLabel(UserModuleConstants.INSTANCE.UserPropertiesBinding_resetPasswordText());
    this.passwordField
            .setToolTip(UserModuleConstants.INSTANCE.UserPropertiesBinding_resetPasswordTooltipText());
    this.passwordField.setAllowBlank(true);

    this.passwordRepeatField.disable();
    this.passwordRepeatField.setValidator(this.validatorUpdateConfirmPassword());
    this.passwordRepeatField.setAllowBlank(true);

    this.creationDateLabelField.setTitle(UserModuleMessages.INSTANCE.creationDateMessage(DateTimeFormat
            .getFormat(DateTimeFormat.PredefinedFormat.DATE_LONG).format(user.getCreationDate())));

    if (!user.isTemporary()) {
        this.temporaryField.setReadOnly(false);
        this.temporaryField.setToolTip(
                UserModuleConstants.INSTANCE.UserPropertiesBinding_temporaryFieldCheckedTooltipText());
    } else {//w  w w.  j  a  v  a  2  s . co  m
        this.temporaryField.setReadOnly(false);
        this.temporaryField.setToolTip(
                UserModuleConstants.INSTANCE.UserPropertiesBinding_temporaryFieldDecheckedTooltipText());

        if (user.isExpired()) {
            this.expiredLabelField.setTitle("<span style='color:red'>"
                    + UserModuleConstants.INSTANCE.UserPropertiesBinding_userExpiredText() + "</span>");
        } else {
            Date today = new Date();
            CalendarUtil.addDaysToDate(today, -10);
            this.expiredLabelField.setTitle(UserModuleMessages.INSTANCE.userBeetweenExpirationDateMessage(
                    CalendarUtil.getDaysBetween(today, user.getCreationDate())));
        }
    }

    this.userRoleComboBox.setValidator(this.validatorUpdateRole());
    this.trustedLevelComboBox.setValidator(this.validatorUpdateTrustedLevel());
}

From source file:org.jboss.errai.common.client.logging.util.StringFormat.java

License:Apache License

@SuppressWarnings("deprecation")
private static String processDate(Date date, boolean upper, char suffix) {
    String retVal = null;//  w ww  .j  ava 2 s .  c  o  m
    switch (suffix) {
    case 'k':
        retVal = String.valueOf(date.getHours());
        break;
    case 'H':
        retVal = String.valueOf(padInt(date.getHours(), 2));
        break;
    case 'l':
        retVal = String.valueOf(date.getHours() % 12);
        break;
    case 'I':
        retVal = String.valueOf(padInt(date.getHours() % 12, 2));
        break;
    case 'M':
        retVal = String.valueOf(padInt(date.getMinutes(), 2));
        break;
    case 'S':
        retVal = String.valueOf(padInt(date.getSeconds(), 2));
        break;
    case 'L':
        retVal = String.valueOf(padInt((int) (date.getTime() % 1000), 3));
        break;
    case 'N':
        retVal = String.valueOf(padInt((int) ((date.getTime() % 1000) * 1000000), 9));
        break;
    case 'p':
        retVal = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().ampms()[date.getHours() / 12];
        break;
    case 's':
        retVal = String.valueOf(date.getTime() / 1000);
        break;
    case 'Q':
        retVal = String.valueOf(date.getTime());
        break;
    case 'C':
        retVal = String.valueOf(padInt((date.getYear() + 1900) / 100, 2));
        break;
    case 'Y':
        retVal = String.valueOf(padInt(date.getYear() + 1900, 4));
        break;
    case 'y':
        retVal = String.valueOf(padInt(date.getYear() % 100, 2));
        break;
    case 'j':
        final Date lastYear = new Date(date.getTime());
        lastYear.setYear(date.getYear() - 1);
        lastYear.setMonth(11);
        lastYear.setDate(31);

        retVal = String.valueOf(padInt(CalendarUtil.getDaysBetween(lastYear, date), 3));
        break;
    case 'z':
        retVal = TimeZone.createTimeZone(date.getTimezoneOffset()).getRFCTimeZoneString(date);
        break;
    case 'm':
        retVal = String.valueOf(padInt(date.getMonth() + 1, 2));
        break;
    case 'd':
        retVal = String.valueOf(padInt(date.getDate(), 2));
        break;
    case 'e':
        retVal = String.valueOf(date.getDate());
        break;
    case 'R':
        retVal = processDate(date, false, 'H') + ":" + processDate(date, false, 'M');
        break;
    case 'T':
        retVal = processDate(date, false, 'R') + ":" + processDate(date, false, 'S');
        break;
    case 'r':
        retVal = processDate(date, false, 'I') + ":" + processDate(date, false, 'M') + ":"
                + processDate(date, upper, 'S') + " " + processDate(date, true, 'p');
        break;
    case 'D':
        retVal = processDate(date, false, 'm') + "/" + processDate(date, false, 'd') + "/"
                + processDate(date, false, 'y');
        break;
    case 'F':
        retVal = processDate(date, false, 'Y') + "-" + processDate(date, false, 'm') + "-"
                + processDate(date, false, 'd');
        break;
    case 'Z':
        retVal = TimeZone.createTimeZone(date.getTimezoneOffset()).getShortName(date);
        break;
    case 'B':
        retVal = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsFull()[date.getMonth()];
        break;
    case 'b':
    case 'h':
        retVal = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().monthsShort()[date.getMonth()];
        break;
    case 'A':
        retVal = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysFull()[date.getDay()];
        break;
    case 'a':
        retVal = LocaleInfo.getCurrentLocale().getDateTimeFormatInfo().weekdaysShort()[date.getDay()];
        break;
    case 'c':
        retVal = processDate(date, false, 'a') + " " + processDate(date, false, 'b') + " "
                + processDate(date, false, 'd') + " " + processDate(date, false, 'T') + " "
                + processDate(date, false, 'Z') + " " + processDate(date, false, 'Y');
        break;
    default:
        throw new IllegalArgumentException("Invalid date suffix: " + suffix);
    }

    if (upper)
        return retVal.toUpperCase();
    else
        return retVal;
}

From source file:org.jbpm.console.ng.gc.client.util.DateUtils.java

License:Apache License

@SuppressWarnings("deprecation")
private static DateRange getDateRangeStartingOnMonday(Date dateWithinTheWeek, int nrOfDaysTotal) {
    Date startDate = new Date(dateWithinTheWeek.getTime());
    int day = startDate.getDay() - 1;
    int daysAfterMonday = day;
    if (day == -1) {
        // corner case when the date within the week in Sunday and thus getDay() == 0 (and day == -1), so we need Monday
        // from that week, which is 6 days back
        daysAfterMonday = 6;/*from  www  . j  a  va  2 s  .c o m*/
    }
    CalendarUtil.addDaysToDate(startDate, -daysAfterMonday);
    Date endDate = new Date(startDate.getTime());
    CalendarUtil.addDaysToDate(endDate, nrOfDaysTotal - 1);
    return new DateRange(startDate, endDate, CalendarUtil.getDaysBetween(startDate, endDate));
}

From source file:org.jbpm.console.ng.gc.client.util.DateUtils.java

License:Apache License

/**
 * Returns a {@link DateRange} starting on first day of month in which the specified date is and ending on last day of that
 * month.//from   www.jav a 2  s .  co m
 *
 * @param date date from which to get the month date range
 * @return {@link DateRange} representing the month in which the specified date is
 */
@SuppressWarnings("deprecation")
public static DateRange getMonthDateRange(Date date) {
    Date startDate = new Date(date.getTime());
    CalendarUtil.setToFirstDayOfMonth(startDate);
    // the above method will set hours to 12
    startDate.setHours(0);

    Date endDate = new Date(date.getTime());
    CalendarUtil.setToFirstDayOfMonth(endDate);
    CalendarUtil.addMonthsToDate(endDate, 1);
    CalendarUtil.addDaysToDate(endDate, -1);
    endDate.setHours(0);

    return new DateRange(startDate, endDate, CalendarUtil.getDaysBetween(startDate, endDate));
}

From source file:org.jbpm.console.ng.ht.client.util.CalendarPicker.java

License:Apache License

/**
 * Adjust the date (back or to future) based on current view type (day/week/month).
 *
 * @param back flag that indicates if the date should be adjusted to future (+) or back (-)
 *///w  w  w. ja  v  a2s . c  om
private void adjustDate(boolean back) {
    int dayDiff = 0;
    switch (viewType) {
    case DAY:
        dayDiff = 1;
        break;

    case WEEK:
        dayDiff = 7;
        break;

    case MONTH:
        Date nextMonthSameDate = new Date(currentDate.getTime());
        CalendarUtil.addMonthsToDate(nextMonthSameDate, 1);
        dayDiff = CalendarUtil.getDaysBetween(currentDate, nextMonthSameDate);
        break;
    case GRID:
        dayDiff = 0;
        break;

    }
    if (back) {
        CalendarUtil.addDaysToDate(currentDate, -dayDiff);
    } else {
        CalendarUtil.addDaysToDate(currentDate, dayDiff);
    }
    propagateDateChanges();
}

From source file:org.pentaho.mantle.client.dialogs.scheduling.validators.DateRangeEditorValidator.java

License:Open Source License

public boolean isValid() {
    boolean isValid = true;

    if (null == dateRangeEditor.getStartDate()) {
        isValid = false;//from   www .j  av a 2  s  .  c o m
    } else {
        if (CalendarUtil.getDaysBetween(new Date(), dateRangeEditor.getStartDate()) < 0) {
            isValid = false;
        }
    }

    if (dateRangeEditor.isEndBy() && (null == dateRangeEditor.getEndDate())) {
        isValid = false;
    }
    return isValid;
}