java.util.Calendar#DAY_OF_WEEK源码实例Demo

下面列出了java.util.Calendar#DAY_OF_WEEK 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: j2objc   文件: CalendarDataUtility.java
private static String[] getNames(String id, int field, int style, Locale locale) {
    int context = toContext(style);
    int width = toWidth(style);
    DateFormatSymbols symbols = getDateFormatSymbols(id, locale);
    switch (field) {
        case Calendar.MONTH:
            return symbols.getMonths(context, width);
        case Calendar.ERA:
            switch (width) {
                case DateFormatSymbols.NARROW:
                    return symbols.getNarrowEras();
                case DateFormatSymbols.ABBREVIATED:
                    return symbols.getEras();
                case DateFormatSymbols.WIDE:
                    return symbols.getEraNames();
                default:
                    throw new UnsupportedOperationException("Unknown width: " + width);
            }
        case Calendar.DAY_OF_WEEK:
            return symbols.getWeekdays(context, width);
        case Calendar.AM_PM:
            return symbols.getAmPmStrings();
        default:
            throw new UnsupportedOperationException("Unknown field: " + field);
    }
}
 
源代码2 项目: phone   文件: DateUtil.java
/**
 * 获取第一时间点 当前年,不可变更
 * 
 * @param field
 *            Calendar.field
 * @return
 */
public static Calendar getFirstDate(int field, Date date) {
	if (field == Calendar.DAY_OF_WEEK) {
		return getWeekFirstDate(date);
	}
	Calendar calendar = Calendar.getInstance();
	calendar.setTime(date);
	switch (field) {
	case Calendar.YEAR:
		calendar.set(Calendar.MONTH, 0);
	case Calendar.MONTH:
		calendar.set(Calendar.DAY_OF_MONTH, 1);
	case Calendar.DAY_OF_MONTH:
		calendar.set(Calendar.HOUR_OF_DAY, 0);
	case Calendar.HOUR_OF_DAY:
		calendar.set(Calendar.MINUTE, 0);
	case Calendar.MINUTE:
		calendar.set(Calendar.SECOND, 0);
	case Calendar.SECOND:
		calendar.set(Calendar.MILLISECOND, 0);
	default:
		break;
	}
	return calendar;
}
 
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
源代码4 项目: coming   文件: Cardumen_0096_s.java
/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @return A sorted array of the field key / value pairs
 */
KeyValue[] getDisplayNames(int field) {
    Integer fieldInt = Integer.valueOf(field);
    KeyValue[] fieldKeyValues= nameValues.get(fieldInt);
    if(fieldKeyValues==null) {
        DateFormatSymbols symbols= DateFormatSymbols.getInstance(locale);
        switch(field) {
        case Calendar.ERA:
            // DateFormatSymbols#getEras() only returns AD/BC or translations
            // It does not work for the Thai Buddhist or Japanese Imperial calendars.
            // see: https://issues.apache.org/jira/browse/TRINIDAD-2126
            Calendar c = Calendar.getInstance(locale);
            // N.B. Some calendars have different short and long symbols, e.g. ja_JP_JP
            String[] shortEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.SHORT, locale));
            String[] longEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.LONG, locale));
            fieldKeyValues= createKeyValues(longEras, shortEras);
            break;
        case Calendar.DAY_OF_WEEK:
            fieldKeyValues= createKeyValues(symbols.getWeekdays(), symbols.getShortWeekdays());
            break;
        case Calendar.AM_PM:
            fieldKeyValues= createKeyValues(symbols.getAmPmStrings(), null);
            break;
        case Calendar.MONTH:
            fieldKeyValues= createKeyValues(symbols.getMonths(), symbols.getShortMonths());
            break;
        default:
            throw new IllegalArgumentException("Invalid field value "+field);
        }
        KeyValue[] prior = nameValues.putIfAbsent(fieldInt, fieldKeyValues);
        if(prior!=null) {
            fieldKeyValues= prior;
        }
    }
    return fieldKeyValues;
}
 
源代码5 项目: dragonwell8_jdk   文件: DateTimeTextProvider.java
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
源代码6 项目: coming   文件: Cardumen_0096_t.java
/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @return A sorted array of the field key / value pairs
 */
KeyValue[] getDisplayNames(int field) {
    Integer fieldInt = Integer.valueOf(field);
    KeyValue[] fieldKeyValues= nameValues.get(fieldInt);
    if(fieldKeyValues==null) {
        DateFormatSymbols symbols= DateFormatSymbols.getInstance(locale);
        switch(field) {
        case Calendar.ERA:
            // DateFormatSymbols#getEras() only returns AD/BC or translations
            // It does not work for the Thai Buddhist or Japanese Imperial calendars.
            // see: https://issues.apache.org/jira/browse/TRINIDAD-2126
            Calendar c = Calendar.getInstance(locale);
            // N.B. Some calendars have different short and long symbols, e.g. ja_JP_JP
            String[] shortEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.SHORT, locale));
            String[] longEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.LONG, locale));
            fieldKeyValues= createKeyValues(longEras, shortEras);
            break;
        case Calendar.DAY_OF_WEEK:
            fieldKeyValues= createKeyValues(symbols.getWeekdays(), symbols.getShortWeekdays());
            break;
        case Calendar.AM_PM:
            fieldKeyValues= createKeyValues(symbols.getAmPmStrings(), null);
            break;
        case Calendar.MONTH:
            fieldKeyValues= createKeyValues(symbols.getMonths(), symbols.getShortMonths());
            break;
        default:
            throw new IllegalArgumentException("Invalid field value "+field);
        }
        KeyValue[] prior = nameValues.putIfAbsent(fieldInt, fieldKeyValues);
        if(prior!=null) {
            fieldKeyValues= prior;
        }
    }
    return fieldKeyValues;
}
 
源代码7 项目: jdk8u60   文件: DateTimeTextProvider.java
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
源代码8 项目: coming   文件: Cardumen_00205_s.java
/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @return A sorted array of the field key / value pairs
 */
KeyValue[] getDisplayNames(int field) {
    Integer fieldInt = Integer.valueOf(field);
    KeyValue[] fieldKeyValues= nameValues.get(fieldInt);
    if(fieldKeyValues==null) {
        DateFormatSymbols symbols= DateFormatSymbols.getInstance(locale);
        switch(field) {
        case Calendar.ERA:
            // DateFormatSymbols#getEras() only returns AD/BC or translations
            // It does not work for the Thai Buddhist or Japanese Imperial calendars.
            // see: https://issues.apache.org/jira/browse/TRINIDAD-2126
            Calendar c = Calendar.getInstance(locale);
            // N.B. Some calendars have different short and long symbols, e.g. ja_JP_JP
            String[] shortEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.SHORT, locale));
            String[] longEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.LONG, locale));
            fieldKeyValues= createKeyValues(longEras, shortEras);
            break;
        case Calendar.DAY_OF_WEEK:
            fieldKeyValues= createKeyValues(symbols.getWeekdays(), symbols.getShortWeekdays());
            break;
        case Calendar.AM_PM:
            fieldKeyValues= createKeyValues(symbols.getAmPmStrings(), null);
            break;
        case Calendar.MONTH:
            fieldKeyValues= createKeyValues(symbols.getMonths(), symbols.getShortMonths());
            break;
        default:
            throw new IllegalArgumentException("Invalid field value "+field);
        }
        KeyValue[] prior = nameValues.putIfAbsent(fieldInt, fieldKeyValues);
        if(prior!=null) {
            fieldKeyValues= prior;
        }
    }
    return fieldKeyValues;
}
 
源代码9 项目: coming   文件: Lang_10_FastDateParser_t.java
/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @return A sorted array of the field key / value pairs
 */
KeyValue[] getDisplayNames(int field) {
    Integer fieldInt = Integer.valueOf(field);
    KeyValue[] fieldKeyValues= nameValues.get(fieldInt);
    if(fieldKeyValues==null) {
        DateFormatSymbols symbols= DateFormatSymbols.getInstance(locale);
        switch(field) {
        case Calendar.ERA:
            // DateFormatSymbols#getEras() only returns AD/BC or translations
            // It does not work for the Thai Buddhist or Japanese Imperial calendars.
            // see: https://issues.apache.org/jira/browse/TRINIDAD-2126
            Calendar c = Calendar.getInstance(locale);
            // N.B. Some calendars have different short and long symbols, e.g. ja_JP_JP
            String[] shortEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.SHORT, locale));
            String[] longEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.LONG, locale));
            fieldKeyValues= createKeyValues(longEras, shortEras);
            break;
        case Calendar.DAY_OF_WEEK:
            fieldKeyValues= createKeyValues(symbols.getWeekdays(), symbols.getShortWeekdays());
            break;
        case Calendar.AM_PM:
            fieldKeyValues= createKeyValues(symbols.getAmPmStrings(), null);
            break;
        case Calendar.MONTH:
            fieldKeyValues= createKeyValues(symbols.getMonths(), symbols.getShortMonths());
            break;
        default:
            throw new IllegalArgumentException("Invalid field value "+field);
        }
        KeyValue[] prior = nameValues.putIfAbsent(fieldInt, fieldKeyValues);
        if(prior!=null) {
            fieldKeyValues= prior;
        }
    }
    return fieldKeyValues;
}
 
源代码10 项目: coming   文件: Lang_9_FastDateParser_t.java
/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @return A sorted array of the field key / value pairs
 */
KeyValue[] getDisplayNames(int field) {
    Integer fieldInt = Integer.valueOf(field);
    KeyValue[] fieldKeyValues= nameValues.get(fieldInt);
    if(fieldKeyValues==null) {
        DateFormatSymbols symbols= DateFormatSymbols.getInstance(locale);
        switch(field) {
        case Calendar.ERA:
            // DateFormatSymbols#getEras() only returns AD/BC or translations
            // It does not work for the Thai Buddhist or Japanese Imperial calendars.
            // see: https://issues.apache.org/jira/browse/TRINIDAD-2126
            Calendar c = Calendar.getInstance(locale);
            // N.B. Some calendars have different short and long symbols, e.g. ja_JP_JP
            String[] shortEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.SHORT, locale));
            String[] longEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.LONG, locale));
            fieldKeyValues= createKeyValues(longEras, shortEras);
            break;
        case Calendar.DAY_OF_WEEK:
            fieldKeyValues= createKeyValues(symbols.getWeekdays(), symbols.getShortWeekdays());
            break;
        case Calendar.AM_PM:
            fieldKeyValues= createKeyValues(symbols.getAmPmStrings(), null);
            break;
        case Calendar.MONTH:
            fieldKeyValues= createKeyValues(symbols.getMonths(), symbols.getShortMonths());
            break;
        default:
            throw new IllegalArgumentException("Invalid field value "+field);
        }
        KeyValue[] prior = nameValues.putIfAbsent(fieldInt, fieldKeyValues);
        if(prior!=null) {
            fieldKeyValues= prior;
        }
    }
    return fieldKeyValues;
}
 
源代码11 项目: Bytecoder   文件: DateTimeTextProvider.java
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
 
源代码12 项目: SimFix   文件: 1_FastDateParser.java
/**
 * Get the short and long values displayed for a field
 * @param field The field of interest
 * @return A sorted array of the field key / value pairs
 */
KeyValue[] getDisplayNames(int field) {
    Integer fieldInt = Integer.valueOf(field);
    KeyValue[] fieldKeyValues= nameValues.get(fieldInt);
    if(fieldKeyValues==null) {
        DateFormatSymbols symbols= DateFormatSymbols.getInstance(locale);
        switch(field) {
        case Calendar.ERA:
            // DateFormatSymbols#getEras() only returns AD/BC or translations
            // It does not work for the Thai Buddhist or Japanese Imperial calendars.
            // see: https://issues.apache.org/jira/browse/TRINIDAD-2126
            Calendar c = Calendar.getInstance(locale);
            // N.B. Some calendars have different short and long symbols, e.g. ja_JP_JP
            String[] shortEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.SHORT, locale));
            String[] longEras = toArray(c.getDisplayNames(Calendar.ERA, Calendar.LONG, locale));
            fieldKeyValues= createKeyValues(longEras, shortEras);
            break;
        case Calendar.DAY_OF_WEEK:
            fieldKeyValues= createKeyValues(symbols.getWeekdays(), symbols.getShortWeekdays());
            break;
        case Calendar.AM_PM:
            fieldKeyValues= createKeyValues(symbols.getAmPmStrings(), null);
            break;
        case Calendar.MONTH:
            fieldKeyValues= createKeyValues(symbols.getMonths(), symbols.getShortMonths());
            break;
        default:
            throw new IllegalArgumentException("Invalid field value "+field);
        }
        KeyValue[] prior = nameValues.putIfAbsent(fieldInt, fieldKeyValues);
        if(prior!=null) {
            fieldKeyValues= prior;
        }
    }
    return fieldKeyValues;
}
 
源代码13 项目: tomee   文件: EJBCronTrigger.java
private void initialize(final Matcher m) throws ParseException {

            for (final String value : m.group().split("[,]")) {

                final Matcher rangeMatcher = RANGE.matcher(value);
                final Matcher weekDayMatcher = WEEKDAY.matcher(value);
                final Matcher daysToLastMatcher = DAYS_TO_LAST.matcher(value);

                if (value.equals(LAST_IDENTIFIER)) {
                    daysFromLastDayExpressions.add(new DaysFromLastDayExpression());
                    continue;
                } else if (daysToLastMatcher.matches()) {
                    daysFromLastDayExpressions.add(new DaysFromLastDayExpression(daysToLastMatcher));
                    continue;
                } else if (weekDayMatcher.matches()) {
                    weekDayExpressions.add(new WeekdayExpression(weekDayMatcher));
                    continue;
                } else if (rangeMatcher.matches()) {

                    final RangeExpression rangeExpression = new RangeExpression(rangeMatcher, field);

                    if (rangeExpression.isDynamicRangeExpression()) {
                        weekDayRangeExpressions.add(new RangeExpression(rangeMatcher, field));
                        continue;
                    }

                    values.addAll(rangeExpression.getAllValuesInRange(null));

                } else {
                    int individualValue = convertValue(value);

                    if (field == Calendar.DAY_OF_WEEK && individualValue == 8) {
                        individualValue = 1;
                    }

                    values.add(individualValue);
                }
            }

        }
 
源代码14 项目: hortonmachine   文件: Summary.java
public void setPeriod(String period) {
    if (period.equals(WEEKLY)) {
        field = Calendar.DAY_OF_WEEK;
    } else if (period.equals(MONTHLY)) {
        field = Calendar.DAY_OF_MONTH;
    } else if (period.equals(YEARLY)) {
        field = Calendar.DAY_OF_YEAR;
    } else {
        throw new IllegalArgumentException(period);
    }
}
 
源代码15 项目: ActivityDiary   文件: DateHelper.java
public static Calendar startOf(int field, long timeRef){
    Calendar result = Calendar.getInstance();
    result.setTimeInMillis(timeRef);
    result.set(Calendar.HOUR_OF_DAY, 0); // ! clear would not reset the hour of day !
    result.clear(Calendar.MINUTE);
    result.clear(Calendar.SECOND);
    result.clear(Calendar.MILLISECOND);
    switch(field){
        case Calendar.DAY_OF_MONTH:
        case Calendar.DAY_OF_WEEK:
        case Calendar.DAY_OF_WEEK_IN_MONTH:
        case Calendar.DAY_OF_YEAR:
            /* nothing to do, as HOUR_OF_DAY is already 0 */
            break;
        case Calendar.WEEK_OF_YEAR:
            result.set(Calendar.DAY_OF_WEEK, result.getFirstDayOfWeek());
            break;
        case Calendar.MONTH:
            result.set(Calendar.DAY_OF_MONTH, 1);
            break;
        case Calendar.YEAR:
            result.set(Calendar.DAY_OF_YEAR, 1);
            break;
        default:
            throw new RuntimeException("date field not supported: " + field);
    }
    return result;
}
 
源代码16 项目: Telegram-FOSS   文件: FastDateParser.java
private static String[] getDisplayNameArray(int field, boolean isLong, Locale locale) {
    DateFormatSymbols dfs = new DateFormatSymbols(locale);
    switch (field) {
        case Calendar.AM_PM:
            return dfs.getAmPmStrings();
        case Calendar.DAY_OF_WEEK:
            return isLong ? dfs.getWeekdays() : dfs.getShortWeekdays();
        case Calendar.ERA:
            return dfs.getEras();
        case Calendar.MONTH:
            return isLong ? dfs.getMonths() : dfs.getShortMonths();
    }
    return null;
}
 
源代码17 项目: tomee   文件: EJBCronTrigger.java
/**
 * Works similarly to getFireTimeAfter() but backwards.
 */
@Override
public Date getFinalFireTime() {
    final Calendar calendar = new GregorianCalendar(timezone);
    //calendar.setLenient(false);
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);

    if (getEndTime() == null) {
        // If the year field has been left default, there is no end time
        if (expressions[0] instanceof AsteriskExpression) {
            return null;
        }
        resetFields(calendar, 0, true);
        calendar.set(Calendar.MILLISECOND, 0);
    } else {
        calendar.setTime(getEndTime());
    }

    // Calculate time to give up scheduling
    final Calendar stopCalendar = new GregorianCalendar(timezone);
    if (getStartTime() != null) {
        stopCalendar.setTime(getStartTime());
    } else {
        stopCalendar.setTimeInMillis(0);
    }

    int currentFieldIndex = 0;
    while (currentFieldIndex <= 6 && calendar.after(stopCalendar)) {
        final FieldExpression expr = expressions[currentFieldIndex];
        final Integer value = expr.getPreviousValue(calendar);
        if (value != null) {
            final int oldValue = calendar.get(expr.field);
            if (oldValue != value) {
                // The value has changed, so update the calendar and reset all
                // less significant fields
                calendar.set(expr.field, value);
                resetFields(calendar, expr.field, true);

                // If the weekday changed, the day of month changed too
                if (expr.field == Calendar.DAY_OF_WEEK) {
                    currentFieldIndex--;
                } else {
                    currentFieldIndex++;
                }
            } else {
                currentFieldIndex++;
            }
        } else if (currentFieldIndex >= 1) {
            // No suitable value was found, so move back to the previous field
            // and decrease the value
            final int maxAffectedFieldType = upadteCalendar(calendar, expressions[currentFieldIndex - 1].field, -1);
            currentFieldIndex = CALENDAR_FIELD_TYPE_ORDERED_INDEX_MAP.get(maxAffectedFieldType);
            resetFields(calendar, maxAffectedFieldType, true);
        } else {
            return null; // The job will never be run
        }
    }

    return calendar.after(stopCalendar) ? calendar.getTime() : null;


}
 
public AlternatingDinerMenuIterator(MenuItem[] items) {
	this.items = items;
	position = Calendar.DAY_OF_WEEK % 2;
}
 
源代码19 项目: nebula   文件: DateHelper.java
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;
	}
 
源代码20 项目: opencps-v2   文件: DueDateUtils.java
private void _setHourTimeWorkingByDay(int day) {

		String startAM = "00:00";
		String endAM = "00:00";
		String startPM = "00:00";
		String endPM = "00:00";

		try {

			int checkDay = day % Calendar.DAY_OF_WEEK;

			for (WorkTime workTime : this.workTimes) {

				if (workTime.getDay() == Calendar.MONDAY ||
					workTime.getDay() == checkDay) {

					// workTime.hours = 07:00-11:30,13:30-17:00
					String am = workTime.getHours().split(StringPool.COMMA)[0];
					String pm = workTime.getHours().split(StringPool.COMMA)[1];
					startAM = am.split(StringPool.DASH)[0];
					endAM = am.split(StringPool.DASH)[1];
					startPM = pm.split(StringPool.DASH)[0];
					endPM = pm.split(StringPool.DASH)[1];
					if (workTime.getDay() == checkDay) {
						break;
					}
				}
			}
		}
		catch (Exception e) {

			_log.error(e);
		}

		this.startAMStr = startAM;
		this.endAMStr = endAM;
		this.startPMStr = startPM;
		this.endPMStr = endPM;
		this.startAM = SupportUtils._stringToNumberHourColon(startAM);
		this.endAM = SupportUtils._stringToNumberHourColon(endAM);
		this.startPM = SupportUtils._stringToNumberHourColon(startPM);
		this.endPM = SupportUtils._stringToNumberHourColon(endPM);
		this.tongThoiGianCanBoLamViecTrongNgay =
			SupportUtils.subTime(this.endAM, this.startAM) +
				SupportUtils.subTime(this.endPM, this.startPM);
		this.gioCanBoNghiLamViec = Math.max(this.endAM, this.endPM);
		this.thoiGianCanBoNghiTrua =
			Math.max(0, SupportUtils.subTime(this.startPM, this.endAM));

	}