Java Code Examples for java.util.Calendar#AM_PM

The following examples show how to use java.util.Calendar#AM_PM . 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: CalendarDataUtility.java    From j2objc with Apache License 2.0 6 votes vote down vote up
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);
    }
}
 
Example 2
Source File: DateUtilsRoundingTest.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests DateUtils.round()-method with Calendar.AM_PM
 * Includes rounding the extremes of both AM and PM of one day 
 * Includes rounding to January 1
 * 
 * @throws Exception
 * @since 3.0
 */
@Test
public void testRoundAmPm() throws Exception {
    final int calendarField = Calendar.AM_PM;
    Date roundedUpDate, roundedDownDate, lastRoundedDownDate;
    Date minDate, maxDate;

    //AM
    roundedUpDate = dateTimeParser.parse("June 1, 2008 12:00:00.000");
    roundedDownDate = targetAmDate;
    lastRoundedDownDate = dateTimeParser.parse("June 1, 2008 5:59:59.999");
    baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate,  calendarField);

    //PM
    roundedUpDate = dateTimeParser.parse("June 2, 2008 0:00:00.000");
    roundedDownDate = targetPmDate;
    lastRoundedDownDate = dateTimeParser.parse("June 1, 2008 17:59:59.999");
    baseRoundTest(roundedUpDate, roundedDownDate, lastRoundedDownDate,  calendarField);

    //round to January 1
    minDate = dateTimeParser.parse("December 31, 2007 18:00:00.000");
    maxDate = dateTimeParser.parse("January 1, 2008 5:59:59.999");
    roundToJanuaryFirst(minDate, maxDate, calendarField);
}
 
Example 3
Source File: FastDateParser.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: DateTimeTextProvider.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 5
Source File: DateUtilsRoundingTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test DateUtils.truncate()-method with Calendar.AM_PM
 * Includes truncating the extremes of both AM and PM of one day 
 * 
 * @throws Exception
 * @since 3.0
 */
public void testTruncateAmPm() throws Exception {
    final int calendarField = Calendar.AM_PM;
    
    //AM
    Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 11:59:59.999");
    baseTruncateTest(targetAmDate, lastTruncateDate, calendarField);

    //PM
    lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
    baseTruncateTest(targetPmDate, lastTruncateDate, calendarField);
}
 
Example 6
Source File: DateUtilsRoundingTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test DateUtils.truncate()-method with Calendar.AM_PM
 * Includes truncating the extremes of both AM and PM of one day 
 * 
 * @throws Exception
 * @since 3.0
 */
public void testTruncateAmPm() throws Exception {
    final int calendarField = Calendar.AM_PM;
    
    //AM
    Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 11:59:59.999");
    baseTruncateTest(targetAmDate, lastTruncateDate, calendarField);

    //PM
    lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
    baseTruncateTest(targetPmDate, lastTruncateDate, calendarField);
}
 
Example 7
Source File: FastDateParser.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 8
Source File: FastDateParser.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
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;
}
 
Example 9
Source File: DateUtilsRoundingTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test DateUtils.truncate()-method with Calendar.AM_PM
 * Includes truncating the extremes of both AM and PM of one day 
 * 
 * @throws Exception
 * @since 3.0
 */
@Test
public void testTruncateAmPm() throws Exception {
    final int calendarField = Calendar.AM_PM;
    
    //AM
    Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 11:59:59.999");
    baseTruncateTest(targetAmDate, lastTruncateDate, calendarField);

    //PM
    lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
    baseTruncateTest(targetPmDate, lastTruncateDate, calendarField);
}
 
Example 10
Source File: DateTimeTextProvider.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 11
Source File: DateTimeTextProvider.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: Lang_10_FastDateParser_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 13
Source File: Cardumen_00154_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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 (field < (pattern.length())) {
        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;
}
 
Example 14
Source File: DateTimeTextProvider.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 15
Source File: DateTimeTextProvider.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: DateUtilsRoundingTest.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test DateUtils.truncate()-method with Calendar.AM_PM
 * Includes truncating the extremes of both AM and PM of one day 
 * 
 * @throws Exception
 * @since 3.0
 */
@Test
public void testTruncateAmPm() throws Exception {
    final int calendarField = Calendar.AM_PM;
    
    //AM
    Date lastTruncateDate = dateTimeParser.parse("June 1, 2008 11:59:59.999");
    baseTruncateTest(targetAmDate, lastTruncateDate, calendarField);

    //PM
    lastTruncateDate = dateTimeParser.parse("June 1, 2008 23:59:59.999");
    baseTruncateTest(targetPmDate, lastTruncateDate, calendarField);
}
 
Example 17
Source File: Cardumen_00205_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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;
}
 
Example 18
Source File: DateTimeFormatter.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
/**
  * Inserts a sequence of characters in the input buffer. The current content
  * of the buffer is override. The new position of the cursor is computed and
  * returned.
  *
  * @param txt String of characters to insert
  * @param p Starting position of insertion
  * @return New position of the cursor
  */
private int insert(String txt, int p) {
	FieldDesc fd = null;
	int i = 0, from = 0, t;
   char c, m, o;
	while ( i < txt.length() ) {
     c = txt.charAt(i);
     if ( p < inputMask.length() ) {
       m = inputMask.charAt(p);
 			if ( m == '*' && inputCache.charAt(p) == c ) {
 				from = p;
 				i++;
 				p++;
 				fd = null;
 				continue;
 			}
     } else {
     	m = inputMask.charAt(inputMask.length() - 1);
     }
		if ( fd == null ) {
			fd = getField(p, from);
			for (int j = fd.pos; j < p; j++) {
				if ( inputCache.charAt(j) == SPACE ) {
					inputCache.setCharAt(j, '0');
				}
			}
		}
		t = Character.getType(c);
		if ( t == Character.DECIMAL_DIGIT_NUMBER && fd.field != Calendar.AM_PM ) {
			o = '#';
			if ( m != '*' && p < inputMask.length() ) {
				o = inputCache.charAt(p);
				inputCache.setCharAt(p, c);
			} else if ( fd.curLen < fd.maxLen ) {
				inputCache.insert(p, c);
				inputMask.insert(p, inputMask.charAt(fd.pos));
				fd.curLen++;
			} else {
				beep();
				return p;
			}
			if ( ! updateFieldValue(fd, true) ) {
				if ( o != '#' ) {
					inputCache.setCharAt(p, o);
				} else {
					inputCache.deleteCharAt(p);
					inputMask.deleteCharAt(p);
					fd.curLen--;
				}
				beep();
				return p;
			}
			i++;
			p++;
		} else if ( fd.field == Calendar.AM_PM
								&& (t == Character.UPPERCASE_LETTER
										|| t == Character.LOWERCASE_LETTER) ) {
			String[] ampm = sdfDisplay.getDateFormatSymbols().getAmPmStrings();
			if ( Character.toLowerCase(c) == Character.toLowerCase(ampm[0].charAt(0)) ) {
				t = 0;
			} else if ( Character.toLowerCase(c) == Character.toLowerCase(ampm[1].charAt(0)) ) {
				t = 1;
			} else {
				beep();
				return p;
			}
			inputCache.replace(fd.pos, fd.pos + fd.curLen, ampm[t]);
			while ( fd.curLen < ampm[t].length() ) {
				inputMask.insert(p, m);
				fd.curLen++;
			}
			while ( fd.curLen > ampm[t].length() ) {
				inputMask.deleteCharAt(p);
				fd.curLen--;
			}
			updateFieldValue(fd, false);
			i++;
			p = fd.pos + fd.curLen;
		} else {
			t = fd.pos + fd.curLen;
			if ( t < inputCache.length() && c == inputCache.charAt(t) && i == txt.length() - 1 ) {
				p = getNextFieldPos(fd);
			} else {
				beep();
			}
			return p;
		}
	}
	if ( fd != null && p == fd.pos + fd.curLen && fd.curLen == fd.maxLen ) {
		p = getNextFieldPos(fd);
	}
	return p;
}
 
Example 19
Source File: AnalogTimePicker.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public int[] getFields() {
	return new int[] { Calendar.HOUR_OF_DAY, Calendar.HOUR, Calendar.MINUTE,
			Calendar.SECOND, Calendar.AM_PM };
}
 
Example 20
Source File: AnalogTimePicker.java    From nebula with Eclipse Public License 2.0 4 votes vote down vote up
public void setFields(int[] calendarFields) {
	is24Hour = false;
	hourHand = false;
	minHand = false;
	secHand = false;
	am_pm = false;
	for (int field : calendarFields) {
		if (field == Calendar.HOUR_OF_DAY) {
			is24Hour = true;
		} else if (field == Calendar.HOUR) {
			hourHand = true;
		} else if (field == Calendar.MINUTE) {
			minHand = true;
		} else if (field == Calendar.SECOND) {
			secHand = true;
		} else if (field == Calendar.AM_PM) {
			am_pm = true;
		}
	}
	if ((cdt.style & CDT.CLOCK_12_HOUR) != 0) {
		is24Hour = false;
		hourHand = true;
		am_pm = true;
	} else if ((cdt.style & CDT.CLOCK_24_HOUR) != 0) {
		is24Hour = true;
	}
	if (is24Hour) {
		hourHand = true;
		am_pm = false;
	}
	timeAmPm.setVisible(am_pm);
	boolean sepOK = false;
	pattern = ""; //$NON-NLS-1$
	String cdtPattern = cdt.getPattern();
	for (int i = 0; i < cdtPattern.length(); i++) {
		char c = cdtPattern.charAt(i);
		if ("Hhmsa".indexOf(c) > -1) { //$NON-NLS-1$
			pattern += c;
			sepOK = true;
		} else {
			if (sepOK && ":., ".indexOf(c) > -1) { //$NON-NLS-1$
				pattern += c;
			}
			sepOK = false;
		}
	}
	if (digitalClock != null) {
		digitalClock.setPattern(pattern);
	}
	updateLabels();
}