下面列出了怎么用org.joda.time.DateTimeFieldType的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Constructor.
*
* @param type the field type
* @param unitMillis the average duration unit milliseconds
*/
public ImpreciseDateTimeField(DateTimeFieldType type, long unitMillis) {
// start of generated patch
super(type);
if(type==null){
throw new IllegalArgumentException("The type must not be null");
}
iUnitMillis=unitMillis;
iDurationField=new LinkedDurationField(type.getDurationType());
// end of generated patch
/* start of original code
super(type);
iUnitMillis = unitMillis;
iDurationField = new LinkedDurationField(type.getDurationType());
end of original code*/
}
public long getDateTimeMillis(
int year, int monthOfYear, int dayOfMonth,
int hourOfDay, int minuteOfHour, int secondOfMinute, int millisOfSecond)
throws IllegalArgumentException {
Chronology base;
if ((base = getBase()) != null) {
return base.getDateTimeMillis(year, monthOfYear, dayOfMonth,
hourOfDay, minuteOfHour, secondOfMinute, millisOfSecond);
}
FieldUtils.verifyValueBounds(DateTimeFieldType.hourOfDay(), hourOfDay, 0, 23);
FieldUtils.verifyValueBounds(DateTimeFieldType.minuteOfHour(), minuteOfHour, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.secondOfMinute(), secondOfMinute, 0, 59);
FieldUtils.verifyValueBounds(DateTimeFieldType.millisOfSecond(), millisOfSecond, 0, 999);
return getDateMidnightMillis(year, monthOfYear, dayOfMonth)
+ hourOfDay * DateTimeConstants.MILLIS_PER_HOUR
+ minuteOfHour * DateTimeConstants.MILLIS_PER_MINUTE
+ secondOfMinute * DateTimeConstants.MILLIS_PER_SECOND
+ millisOfSecond;
}
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param type the field type this field actually uses
* @param offset offset to add to field values
* @param minValue minimum allowed value
* @param maxValue maximum allowed value
* @throws IllegalArgumentException if offset is zero
*/
public OffsetDateTimeField(DateTimeField field, DateTimeFieldType type, int offset,
int minValue, int maxValue) {
super(field, type);
if (offset == 0) {
throw new IllegalArgumentException("The offset cannot be zero");
}
iOffset = offset;
if (minValue < (field.getMinimumValue() + offset)) {
iMin = field.getMinimumValue() + offset;
} else {
iMin = minValue;
}
if (maxValue > (field.getMaximumValue() + offset)) {
iMax = field.getMaximumValue() + offset;
} else {
iMax = maxValue;
}
}
private static DateTimeFormatter basicOrdinalDate() {
if (bod == null) {
return new DateTimeFormatterBuilder()
.appendYear(4, 4)
.appendFixedDecimal(DateTimeFieldType.dayOfYear(), 3)
.toFormatter();
}
return bod;
}
@Override
public int getMaximumValue(ReadablePartial partial) {
if (partial.isSupported(DateTimeFieldType.monthOfYear())) {
int month = partial.get(DateTimeFieldType.monthOfYear());
return this.daysInMonth[month - 1]; // Months are 1-based
}
return this.getMaximumValue();
}
private void fillSummaryWithInfo(LocalizedString title, LocalizedString summaryText, Integer studentsNumber,
Boolean isExtraLesson, Professorship professorship, String teacherName, Teacher teacher, Shift shift, Lesson lesson,
YearMonthDay day, Space room, Partial hour, ShiftType type, Boolean taught, Boolean onlineLesson) {
setShift(shift);
setSummaryDateYearMonthDay(day);
setExecutionCourse(shift.getExecutionCourse());
setTitle(title);
setSummaryText(summaryText);
setIsExtraLesson(isExtraLesson);
checkSpecialParameters(isExtraLesson, professorship, teacherName, teacher, lesson, hour, type);
checkIfInternalTeacherHasProfessorhipInExecutionCourse(teacher, shift.getExecutionCourse());
checkIfSummaryDateIsValid(day, shift.getExecutionPeriod(), lesson, isExtraLesson);
setStudentsNumber(studentsNumber);
setProfessorship(professorship);
setTeacherName(teacherName);
setTeacher(teacher);
setLastModifiedDateDateTime(new DateTime());
setSummaryType(type);
setTaught(taught);
setOnlineLesson(onlineLesson);
if (isExtraLesson) {
super.setLessonInstance(null);
setRoom(room);
HourMinuteSecond hourMinuteSecond =
new HourMinuteSecond(hour.get(DateTimeFieldType.hourOfDay()), hour.get(DateTimeFieldType.minuteOfHour()), 0);
setSummaryHourHourMinuteSecond(hourMinuteSecond);
} else {
setRoom(lesson.getSala());
setSummaryHourHourMinuteSecond(lesson.getBeginHourMinuteSecond());
lessonInstanceManagement(lesson, day, lesson.getSala());
if (getLessonInstance() == null) {
throw new DomainException("error.Summary.empty.LessonInstances");
}
}
}
/**
* See {@link android.text.format.DateUtils#isToday} for full docs.
*
* @return true if the supplied when is today else false
*/
public static boolean isToday(ReadablePartial time) {
if (!time.isSupported(DateTimeFieldType.dayOfMonth())
|| !time.isSupported(DateTimeFieldType.monthOfYear())
|| !time.isSupported(DateTimeFieldType.year())) {
throw new IllegalArgumentException("isToday() must be passed a ReadablePartial that supports day of " +
"month, month of year and year.");
}
LocalDate localDate = time instanceof LocalDate ? (LocalDate) time : new LocalDate(time);
return LocalDate.now().compareTo(localDate) == 0;
}
private static DateTimeFormatter weekyearElement() {
if (WE == null) {
return new DateTimeFormatterBuilder()
.appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4)
.toFormatter();
}
return WE;
}
public PhdGratuityPaymentPeriod(int dayStart, int monthStart, int dayEnd, int monthEnd, int dayLastPayment,
int monthLastPayment) {
super();
init(new Partial().with(DateTimeFieldType.monthOfYear(), monthStart).with(DateTimeFieldType.dayOfYear(), dayStart),
new Partial().with(DateTimeFieldType.monthOfYear(), monthEnd).with(DateTimeFieldType.dayOfYear(), dayEnd),
new Partial().with(DateTimeFieldType.monthOfYear(), monthLastPayment).with(DateTimeFieldType.dayOfYear(),
dayLastPayment));
}
private static DateTimeFormatter yearElement() {
if (ye == null) {
return new DateTimeFormatterBuilder()
.appendFixedSignedDecimal(DateTimeFieldType.year(), 4) // ES change, was .appendYear(4, 9)
.toFormatter();
}
return ye;
}
private static DateTimeFormatter monthElement() {
if (mye == null) {
return new DateTimeFormatterBuilder()
.appendLiteral('-')
.appendFixedSignedDecimal(DateTimeFieldType.monthOfYear(), 2) // ES change, was .appendMonthOfYear(2)
.toFormatter();
}
return mye;
}
private static DateTimeFormatter weekyearElement() {
if (we == null) {
return new DateTimeFormatterBuilder()
.appendFixedSignedDecimal(DateTimeFieldType.weekyear(), 4) // ES change, was .appendWeekyear(4, 9)
.toFormatter();
}
return we;
}
private static DateTimeFormatter weekElement() {
if (wwe == null) {
return new DateTimeFormatterBuilder()
.appendLiteral("-W")
.appendFixedSignedDecimal(DateTimeFieldType.weekOfWeekyear(), 2) // ES change, was .appendWeekOfWeekyear(2)
.toFormatter();
}
return wwe;
}
private static DateTimeFormatter hourElement() {
if (hde == null) {
return new DateTimeFormatterBuilder()
.appendFixedSignedDecimal(DateTimeFieldType.hourOfDay(), 2) // ES change, was .appendHourOfDay(2)
.toFormatter();
}
return hde;
}
public Interval getWeeklyWorkLoadInterval() {
final DateTime beginningOfSemester = new DateTime(getBegginingOfLessonPeriod());
final DateTime firstMonday = beginningOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1);
final DateTime endOfSemester = new DateTime(getEndOfExamsPeriod());
final DateTime nextLastMonday = endOfSemester.withField(DateTimeFieldType.dayOfWeek(), 1).plusWeeks(1);
return new Interval(firstMonday, nextLastMonday);
}
/**
* Constructor.
*
* @param type the field type
* @param durationField the duration to use
*/
private UnsupportedDateTimeField(DateTimeFieldType type, DurationField durationField) {
// start of generated patch
if(type==null||durationField==null){
throw new IllegalArgumentException("The type must not be null");
}
// end of generated patch
/* start of original code
if (type == null || durationField == null) {
throw new IllegalArgumentException();
}
end of original code*/
iType = type;
iDurationField = durationField;
}
@Override
public Object provide(Object source, Object currentValue) {
List<Partial> result = new ArrayList<Partial>();
for (int i = 1; i <= 12; i++) {
result.add(new Partial(DateTimeFieldType.monthOfYear(), i));
}
return result;
}
/**
* Returns a basic formatter for a full date as four digit weekyear, two
* digit week of weekyear, and one digit day of week (xxxx'W'wwe).
*
* @return a formatter for xxxx'W'wwe
*/
public static DateTimeFormatter basicWeekDate() {
if (bwd == null) {
bwd = new DateTimeFormatterBuilder()
.appendWeekyear(4, 4)
.appendLiteral('W')
.appendFixedDecimal(DateTimeFieldType.weekOfWeekyear(), 2)
.appendFixedDecimal(DateTimeFieldType.dayOfWeek(), 1)
.toFormatter();
}
return bwd;
}
/**
* Restricted constructor.
*
* @param leapMonth the month of year that leaps
*/
BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth) {
super(DateTimeFieldType.monthOfYear(), chronology.getAverageMillisPerMonth());
iChronology = chronology;
iMax = iChronology.getMaxMonth();
iLeapMonth = leapMonth;
}
/**
* Constructor.
*
* @param field the field to wrap, like "year()".
* @param type the field type this field will actually use
* @param divisor divisor, such as 100 years in a century
* @throws IllegalArgumentException if divisor is less than two
*/
public DividedDateTimeField(DateTimeField field,
DateTimeFieldType type, int divisor) {
super(field, type);
if (divisor < 2) {
throw new IllegalArgumentException("The divisor must be at least 2");
}
DurationField unitField = field.getDurationField();
if (unitField == null) {
iDurationField = null;
} else {
iDurationField = new ScaledDurationField(
unitField, type.getDurationType(), divisor);
}
iDivisor = divisor;
int i = field.getMinimumValue();
int min = (i >= 0) ? i / divisor : ((i + 1) / divisor - 1);
int j = field.getMaximumValue();
int max = (j >= 0) ? j / divisor : ((j + 1) / divisor - 1);
iMin = min;
iMax = max;
}
/**
* Gets the milliseconds for a date at midnight.
*
* @param year the year
* @param monthOfYear the month
* @param dayOfMonth the day
* @return the milliseconds
*/
long getDateMidnightMillis(int year, int monthOfYear, int dayOfMonth) {
FieldUtils.verifyValueBounds(DateTimeFieldType.year(), year, getMinYear(), getMaxYear());
FieldUtils.verifyValueBounds(DateTimeFieldType.monthOfYear(), monthOfYear, 1, getMaxMonth(year));
if ((!(10 == monthOfYear)) && (((31) - (2)) != (dayOfMonth))) {
FieldUtils.verifyValueBounds(DateTimeFieldType.dayOfMonth(), dayOfMonth, 1, getDaysInYearMonth(year, monthOfYear));
}
return getYearMonthDayMillis(year, monthOfYear, dayOfMonth);
}
/**
* Restricted constructor.
*
* @param leapMonth the month of year that leaps
*/
BasicMonthOfYearDateTimeField(BasicChronology chronology, int leapMonth) {
super(DateTimeFieldType.monthOfYear(), chronology.getAverageMillisPerMonth());
iChronology = chronology;
iMax = iChronology.getMaxMonth();
iLeapMonth = leapMonth;
}
public void testFormat_time_partial() {
Partial dt = new Partial(
new DateTimeFieldType[] {DateTimeFieldType.hourOfDay(), DateTimeFieldType.minuteOfHour(),
DateTimeFieldType.secondOfMinute(), DateTimeFieldType.millisOfSecond()},
new int[] {10, 20, 30, 40});
assertEquals("10:20:30.040", ISODateTimeFormat.time().print(dt));
}
/**
* Instructs the printer to emit a remainder of time as a decimal fraction,
* without decimal point. For example, if the field is specified as
* minuteOfHour and the time is 12:30:45, the value printed is 75. A
* decimal point is implied, so the fraction is 0.75, or three-quarters of
* a minute.
*
* @param fieldType type of field to append
* @param minDigits minimum number of digits to print.
* @param maxDigits maximum number of digits to print or parse.
* @return this DateTimeFormatterBuilder, for chaining
* @throws IllegalArgumentException if field type is null
*/
public DateTimeFormatterBuilder appendFraction(
DateTimeFieldType fieldType, int minDigits, int maxDigits) {
if (fieldType == null) {
throw new IllegalArgumentException("Field type must not be null");
}
if (maxDigits < minDigits) {
maxDigits = minDigits;
}
if (minDigits < 0 || maxDigits <= 0) {
throw new IllegalArgumentException();
}
return append0(new Fraction(fieldType, minDigits, maxDigits));
}
public void test_getType() {
BaseDateTimeField field = new PreciseDateTimeField(
DateTimeFieldType.secondOfDay(),
ISOChronology.getInstanceUTC().millis(),
ISOChronology.getInstanceUTC().hours()
);
assertEquals(DateTimeFieldType.secondOfDay(), field.getType());
}
private static DateTimeFormatter dayOfYearElement() {
if (DYE == null) {
return new DateTimeFormatterBuilder()
.appendLiteral('-')
.appendFixedSignedDecimal(DateTimeFieldType.dayOfYear(), 3)
.toFormatter();
}
return DYE;
}
protected Fraction(DateTimeFieldType fieldType, int minDigits, int maxDigits) {
super();
iFieldType = fieldType;
// Limit the precision requirements.
if (maxDigits > 18) {
maxDigits = 18;
}
iMinDigits = minDigits;
iMaxDigits = maxDigits;
}
public void test_toString() {
BaseDateTimeField field = new PreciseDateTimeField(
DateTimeFieldType.secondOfDay(),
ISOChronology.getInstanceUTC().millis(),
ISOChronology.getInstanceUTC().hours()
);
assertEquals("DateTimeField[secondOfDay]", field.toString());
}
private static Map<String, DateTimeFieldType> getMap() {
Map<String, DateTimeFieldType> ret = new HashMap<>();
ret.put(DateTimeFieldType.centuryOfEra().getName(), DateTimeFieldType.centuryOfEra());
ret.put(DateTimeFieldType.clockhourOfDay().getName(), DateTimeFieldType.clockhourOfDay());
ret.put(DateTimeFieldType.clockhourOfHalfday().getName(), DateTimeFieldType.clockhourOfHalfday());
ret.put(DateTimeFieldType.dayOfMonth().getName(), DateTimeFieldType.dayOfMonth());
ret.put(DateTimeFieldType.dayOfWeek().getName(), DateTimeFieldType.dayOfWeek());
ret.put(DateTimeFieldType.dayOfYear().getName(), DateTimeFieldType.dayOfYear());
ret.put(DateTimeFieldType.era().getName(), DateTimeFieldType.era());
ret.put(DateTimeFieldType.halfdayOfDay().getName(), DateTimeFieldType.halfdayOfDay());
ret.put(DateTimeFieldType.hourOfDay().getName(), DateTimeFieldType.hourOfDay());
ret.put(DateTimeFieldType.hourOfHalfday().getName(), DateTimeFieldType.hourOfHalfday());
ret.put(DateTimeFieldType.millisOfDay().getName(), DateTimeFieldType.millisOfDay());
ret.put(DateTimeFieldType.millisOfSecond().getName(), DateTimeFieldType.millisOfSecond());
ret.put(DateTimeFieldType.minuteOfDay().getName(), DateTimeFieldType.minuteOfDay());
ret.put(DateTimeFieldType.minuteOfHour().getName(), DateTimeFieldType.minuteOfHour());
ret.put(DateTimeFieldType.secondOfDay().getName(), DateTimeFieldType.secondOfDay());
ret.put(DateTimeFieldType.secondOfMinute().getName(), DateTimeFieldType.secondOfMinute());
ret.put(DateTimeFieldType.weekOfWeekyear().getName(), DateTimeFieldType.weekOfWeekyear());
ret.put(DateTimeFieldType.weekyear().getName(), DateTimeFieldType.weekyear());
ret.put(DateTimeFieldType.weekyearOfCentury().getName(), DateTimeFieldType.weekyearOfCentury());
ret.put(DateTimeFieldType.year().getName(), DateTimeFieldType.year());
ret.put(DateTimeFieldType.yearOfCentury().getName(), DateTimeFieldType.yearOfCentury());
ret.put(DateTimeFieldType.yearOfEra().getName(), DateTimeFieldType.yearOfEra());
return ret;
}
ChartWindow(String name, String format,
ReadablePeriod start, int window, ReadablePeriod increment,
String axeFormat, DateTimeFieldType axeType, int axeMod, int axeValue, int minutes, String base,
String oracleFormat, String oracleCondition, String mySqlFormat, String mySqlCondition) {
iName = name;
iFormat = new SimpleDateFormat(format, Locale.US);
iStart = start; iWindow = window; iIncrement = increment;
iAxeFormat = axeFormat; iAxeType = axeType; iAxeMod = axeMod; iAxeValue = axeValue;
iMinutes = minutes; iBase = base;
iOracleFormat = oracleFormat; iOracleCondition = oracleCondition;
iMySqlFormat = mySqlFormat; iMySqlCondition = mySqlCondition;
}