Java Code Examples for java.util.Calendar#WEEK_OF_MONTH

The following examples show how to use java.util.Calendar#WEEK_OF_MONTH . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: das   File: TimeRangeShardLocator.java    License: Apache License 2.0 5 votes vote down vote up
private int upperEndpoint(Calendar cal) {
    if (field == Calendar.DAY_OF_MONTH  ||
        field == Calendar.DAY_OF_YEAR ||
        field == Calendar.WEEK_OF_YEAR ||
        field == Calendar.WEEK_OF_MONTH) {

        return cal.getActualMaximum(field);
    } else {
        return getMaxRange();
    }
}
 
Example 2
Source Project: das   File: TimeRangeShardLocator.java    License: Apache License 2.0 4 votes vote down vote up
TimeRangeShardLocator(TimeRangeStrategy.TIME_PATTERN timePattern) {
    switch (timePattern){
        case WEEK_OF_YEAR:
            field = Calendar.WEEK_OF_YEAR;
            range = Range.atLeast(1);
            period = DAY * 366L;
            break;
        case WEEK_OF_MONTH:
            field = Calendar.WEEK_OF_MONTH;
            range = Range.atLeast(1);
            period = DAY * 31L;
            break;
        case DAY_OF_MONTH:
            field = Calendar.DAY_OF_MONTH;
            range = Range.atLeast(1);
            period = DAY * 31L;
            break;
        case DAY_OF_YEAR:
            field = Calendar.DAY_OF_YEAR;
            range = Range.atLeast(1);
            period = DAY * 366L;
            break;
        case DAY_OF_WEEK:
            field = Calendar.DAY_OF_WEEK;
            range = Range.closed(1, 7);
            period = DAY * 7;
            break;
        case HOUR_OF_DAY:
            field = Calendar.HOUR_OF_DAY;
            range = Range.closed(0, 23);
            period = DAY;
            break;
        case MINUTE_OF_HOUR:
            field = Calendar.MINUTE;
            range = Range.closed(0, 59);
            period = HOUR;
            break;
        case SECOND_OF_MINUTE:
            field = Calendar.SECOND;
            range = Range.closed(0, 59);
            period = MINUTE;
            break;
    }
}
 
Example 3
Source Project: nebula   File: DateHelper.java    License: Eclipse Public License 2.0 4 votes vote down vote up
public static int getCalendarTypeForString(String oneChar) {

		int calType = -1;

		switch (oneChar.charAt(0)) {
			case 'G':
				calType = Calendar.ERA;
				break;
			case 'y':
				calType = Calendar.YEAR;
				break;
			case 'M':
				calType = Calendar.MONTH;
				break;
			case 'd':
				calType = Calendar.DAY_OF_MONTH;
				break;
			case 'E':
				calType = Calendar.DAY_OF_WEEK;
				break;
			case 'D':
				calType = Calendar.DAY_OF_YEAR;
				break;
			case 'F':
				calType = Calendar.DATE;
				break;
			case 'h':
				calType = Calendar.HOUR;
				break;
			case 'm':
				calType = Calendar.MINUTE;
				break;
			case 's':
				calType = Calendar.SECOND;
				break;
			case 'S':
				calType = Calendar.MILLISECOND;
				break;
			case 'w':
				calType = Calendar.WEEK_OF_YEAR;
				break;
			case 'W':
				calType = Calendar.WEEK_OF_MONTH;
				break;
			case 'a':
				calType = Calendar.AM_PM;
				break;
			case 'k':
				calType = Calendar.HOUR_OF_DAY;
				break;
			case 'K':
				// ?
				break;
			case 'z':
				calType = Calendar.ZONE_OFFSET;
				break;
		}

		return calType;
	}
 
Example 4
Source Project: nebula   File: CDateTime.java    License: Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Set the style of this CDateTime to work with dates and / or times as
 * determined by the given pattern. This will set the fields shown in the
 * text box and, if <code>DROP_DOWN</code> style is set, the fields of the
 * drop down component.<br>
 * This method is backed by an implementation of SimpleDateFormat, and as
 * such, any string pattern which is valid for SimpleDateFormat may be used.
 * Examples (US Locale):<br>
 * </code>setPattern("MM/dd/yyyy h:mm a");</code><br />
 * </code>setPattern("'Meeting @' h:mm a 'on' EEEE, MMM dd,
 * yyyy");</code><br />
 * 
 * @param pattern
 *            the pattern to use, if it is invalid, the original is restored
 * @throws IllegalArgumentException
 * @see SimpleDateFormat
 * @see #getPattern()
 * @see #setFormat(int)
 */
public void setPattern(String pattern) throws IllegalArgumentException {
	this.allowedTimezones = null;
	if (isOpen()) {
		setOpen(false);
	}
	df = new SimpleDateFormat(pattern, locale);
	df.setTimeZone(timezone);
	if (updateFields()) {
		this.pattern = pattern;
		this.format = -1;
		boolean wasDate = isDate;
		boolean wasTime = isTime;
		isDate = isTime = false;
		calendarFields = new int[field.length];
		for (int i = 0; i < calendarFields.length; i++) {
			calendarFields[i] = getCalendarField(field[i]);
			switch (calendarFields[i]) {
			case Calendar.AM_PM:
			case Calendar.HOUR:
			case Calendar.HOUR_OF_DAY:
			case Calendar.MILLISECOND:
			case Calendar.MINUTE:
			case Calendar.SECOND:
			case Calendar.ZONE_OFFSET:
				isTime = true;
				break;
			case Calendar.DAY_OF_MONTH:
			case Calendar.DAY_OF_WEEK:
			case Calendar.DAY_OF_WEEK_IN_MONTH:
			case Calendar.DAY_OF_YEAR:
			case Calendar.ERA:
			case Calendar.MONTH:
			case Calendar.WEEK_OF_MONTH:
			case Calendar.WEEK_OF_YEAR:
			case Calendar.YEAR:
				isDate = true;
				break;
			default:
				break;
			}
		}
		if (checkButton() && (isDate != wasDate || isTime != wasTime)) {
			if (defaultButtonImage) {
				if (isDate && isTime) {
					doSetButtonImage(Resources.getIconCalendarClock());
				} else if (isDate) {
					doSetButtonImage(Resources.getIconCalendar());
				} else {
					doSetButtonImage(Resources.getIconClock());
				}
			}
			updateNullText();
		}
		if (checkText()) {
			updateText();
		}
		if (isSimple()) {
			disposePicker();
			createPicker();
		}
	} else {
		throw new IllegalArgumentException(
				"Problem setting pattern: \"" + pattern + "\""); //$NON-NLS-1$ //$NON-NLS-2$
	}
}