newValue = buffer.toString();
void setTextField(int fieldName, int value, boolean commit, boolean adjustMonth) {	if (commit) {		int max = calendar.getActualMaximum(fieldName);		int min = calendar.getActualMinimum(fieldName);		if (fieldName == Calendar.YEAR) {			/* Special case: don't allow more than 4-digit years. */			max = 9999;			/* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */			if (value < 30) value += 2000;			else if (value <= 99) value += 1900;		}		if (value > max) value = min; // wrap		if (value < min) value = max; // wrap	}	int start = fieldIndices[currentField].x;	int end = fieldIndices[currentField].y;	text.setSelection(start, end);	String newValue;	if (fieldName == Calendar.AM_PM) {		newValue = value == Calendar.AM ? "AM" : "PM";		calendar.roll(Calendar.HOUR_OF_DAY, 12);	} else {		if (fieldName == Calendar.HOUR && value == 0) {			newValue = String.valueOf(12); // TODO: if we add setFormat, then this is not generic enough		} else {			newValue = String.valueOf(fieldName == Calendar.MONTH && adjustMonth ? value + 1 : value);		}		StringBuffer buffer = new StringBuffer(newValue);		int prependCount = end - start - buffer.length();		for (int i = 0; i < prependCount; i++) {			buffer.insert(0, ' ');		}		newValue = buffer.toString();	}	ignoreVerify = true;	text.insert(newValue);	ignoreVerify = false;	selectField(currentField);	if (commit) setField(fieldName, value);}