com.google.gwt.user.datepicker.client.CalendarUtil Java Examples

The following examples show how to use com.google.gwt.user.datepicker.client.CalendarUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NewIssueEditor.java    From proarc with GNU General Public License v3.0 6 votes vote down vote up
private DateItem createDateFrom(String fName, DateRangeValidator dateRangeValidator) {
    DateItem dateStart = new DateItem(fName, i18n.NewIssueEditor_dateFrom_Title());
    dateStart.setTooltip(i18n.NewIssueEditor_dateFrom_Hint());
    dateStart.setUseTextField(true);
    dateStart.setRequired(true);
    dateStart.setStartDate(new Date(1900 - 1900, 1, 1));
    dateStart.addChangedHandler((event) -> {
        Date min = dateStart.getValueAsDate();
        Date max = null;
        if (min != null) {
            max = CalendarUtil.copyDate(min);
            max.setMonth(11);
            max.setDate(31);
        }
        dateRangeValidator.setMin(min);
        dateRangeValidator.setMax(max);
    });
    return dateStart;
}
 
Example #2
Source File: JsMessage.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public JavaScriptObject buildOverlay(Message prev, Message current, Message next) {
    Date nextDate = next != null ? new Date(next.getDate()) : null;
    Date currentDate = new Date(current.getDate());

    boolean showDate;
    String dateDiv = null;
    if (next != null) {
        showDate = !CalendarUtil.isSameDate(nextDate, currentDate);
    } else {
        showDate = true;
    }
    if (showDate) {
        dateDiv = JsMessenger.getInstance().getFormatter().formatMonth(currentDate);
    }

    boolean useCompact = false;
    if (next != null && !showDate) {
        if (next.getSenderId() == current.getSenderId()) {
            if (next.getDate() - current.getDate() < 10 * 60 * 1000) {
                useCompact = true;
            }
        }
    }

    return JsMessageOverlay.create(useCompact, dateDiv);
}
 
Example #3
Source File: PeriodPreferencesWidget.java    From unitime with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
static int weekNumber(int year, int month) {
	Date d = new Date(year - 1900, month - 1, 1);
	while (d.getDay() != CalendarUtil.getStartingDayOfWeek()) d.setDate(d.getDate() - 1);
	int y = d.getYear();
	int week = 0;
	while (d.getYear() == y) { d.setDate(d.getDate() - 7); week += 1; }
	return week;
}
 
Example #4
Source File: SingleDateSelector.java    From unitime with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
static int weekNumber(int year, int month) {
	Date d = new Date(year - 1900, month - 1, 1);
	while (d.getDay() != CalendarUtil.getStartingDayOfWeek()) d.setDate(d.getDate() - 1);
	// ISO 8601: move to the next Thursday
	while (d.getDay() != 4) d.setDate(d.getDate() + 1);
	int y = d.getYear();
	int week = 0;
	while (d.getYear() == y) { d.setDate(d.getDate() - 7); week += 1; }
	return week;
}
 
Example #5
Source File: CubaSimpleDayCell.java    From cuba with Apache License 2.0 4 votes vote down vote up
protected Date getPreviousDate(Date date) {
    Date prev = new Date(date.getTime());
    CalendarUtil.addDaysToDate(prev, -1);
    return prev;
}
 
Example #6
Source File: PeriodPreferencesWidget.java    From unitime with Apache License 2.0 4 votes vote down vote up
static int startingDayOfWeek() {
	return (6 + CalendarUtil.getStartingDayOfWeek()) % 7;
}
 
Example #7
Source File: PeriodPreferencesWidget.java    From unitime with Apache License 2.0 4 votes vote down vote up
static Date getDate(Date firstDate, int offset) {
	Date d = new Date(firstDate.getTime());
	if (offset != 0) CalendarUtil.addDaysToDate(d, offset);
	return d;
}
 
Example #8
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void redrawCalendarPicker() {
	this.monthPicker.getStyle().setDisplay(Display.NONE);
	this.calendarTable.getStyle().clearDisplay();

	this.calendatBody.removeAllChildren();

	int firstDayOfWeek = InputDatePicker.DATE_TIME_FORMAT_INFO.firstDayOfTheWeek();
	int lastDayOfWeek = (firstDayOfWeek + InputDatePicker.DAYS_IN_WEEK) % InputDatePicker.DAYS_IN_WEEK;

	/* Display month */
	this.monthPickerButton.setInnerHTML(InputDatePicker.MONTH_YEAR_FORMAT.format(this.cursor)
		+ "<span class=\"caret\"></span>");

	Date lastMonth = new Date(this.cursor.getTime());
	CalendarUtil.addMonthsToDate(lastMonth, -1);
	this.pagePreviusMonthLi.setAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR, InputDatePicker.ATTRIBUTE_DATE_FORMAT
		.format(lastMonth));
	this.pageTodayLi.setAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR, InputDatePicker.ATTRIBUTE_DATE_FORMAT
		.format(this.today));
	Date nextMonth = new Date(this.cursor.getTime());
	CalendarUtil.addMonthsToDate(nextMonth, 1);
	this.pageNextMonthLi.setAttribute(InputDatePicker.ATTRIBUTE_DATA_CURSOR, InputDatePicker.ATTRIBUTE_DATE_FORMAT
		.format(nextMonth));

	/* Draw daypicker */
	Date dateToDrow = new Date(this.cursor.getTime());
	int selectedMonth = dateToDrow.getMonth();
	int firstMonthToDisplay = (selectedMonth + 11) % 12;
	int lastMonthToDisplay = (selectedMonth + 13) % 12;
	do {
		CalendarUtil.addDaysToDate(dateToDrow, -1);
	} while (firstMonthToDisplay != dateToDrow.getMonth() || dateToDrow.getDay() != firstDayOfWeek);

	// drow calendarTable
	TableRowElement headRow = null;
	while (dateToDrow.getMonth() != lastMonthToDisplay || dateToDrow.getDay() != lastDayOfWeek
		|| dateToDrow.getDate() == 1 && dateToDrow.getDay() == firstDayOfWeek) {
		if (headRow == null || dateToDrow.getDay() == firstDayOfWeek) {
			headRow = Document.get().createTRElement();
			this.calendatBody.appendChild(headRow);
		}
		TableCellElement td = Document.get().createTDElement();
		headRow.appendChild(td);
		DivElement div = Document.get().createDivElement();
		td.appendChild(div);
		div.setInnerText(String.valueOf(dateToDrow.getDate()));
		div.setAttribute(InputDatePicker.ATTRIBUTE_DATA_DATE, InputDatePicker.ATTRIBUTE_DATE_FORMAT.format(dateToDrow));
		if (dateToDrow.getMonth() != selectedMonth) {
			StyleUtils.addStyle(td, InputDatePicker.STYLE_MUTED);
		}
		if (dateToDrow.equals(this.cursor)) {
			StyleUtils.addStyle(td, InputDatePicker.STYLE_SELECTED);
		}
		if (this.today.equals(dateToDrow)) {
			StyleUtils.addStyle(td, InputDatePicker.STYLE_TODAY);
		}
		Event.sinkEvents(div, Event.ONCLICK);

		CalendarUtil.addDaysToDate(dateToDrow, 1);
	}
}
 
Example #9
Source File: InputDatePicker.java    From putnami-web-toolkit with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean handleKeyPress(int keyCode) {
	if (KeyEventUtils.isModifierKeyDown(Event.getCurrentEvent())) {
		return false;
	}
	boolean handleKey = false;
	switch (keyCode) {
		case KeyCodes.KEY_LEFT:
			CalendarUtil.addDaysToDate(this.cursor, -1);
			handleKey = true;
			break;
		case KeyCodes.KEY_RIGHT:
			CalendarUtil.addDaysToDate(this.cursor, 1);
			handleKey = true;
			break;
		case KeyCodes.KEY_UP:
			CalendarUtil.addDaysToDate(this.cursor, -7);
			handleKey = true;
			break;
		case KeyCodes.KEY_DOWN:
			CalendarUtil.addDaysToDate(this.cursor, 7);
			handleKey = true;
			break;
		case KeyCodes.KEY_PAGEUP:
			CalendarUtil.addMonthsToDate(this.cursor, -1);
			handleKey = true;
			break;
		case KeyCodes.KEY_PAGEDOWN:
			CalendarUtil.addMonthsToDate(this.cursor, 1);
			handleKey = true;
			break;
		case KeyCodes.KEY_ENTER:
			this.setValue(this.cursor, true);
			handleKey = true;
			break;
		case KeyCodes.KEY_ESCAPE:
			this.setValue(this.value);
			this.setFocus(false);
			handleKey = true;
			break;
		default:
			break;
	}
	if (handleKey) {
		this.redraw();
	}

	return handleKey;
}