1

我有一个方法如下:

public void storeAppointment(int year,
    int monthOfYear,
    int dayOfMonth,
    int hourOfDayFrom,
    int minuteFrom,
    int hourOfDayUntil, int minuteUntil) {

    Calendar appointmentCalendar = Calendar.getInstance();
    appointmentCalendar.set(year, monthOfYear, dayOfMonth);
    TimeZone tz = appointmentCalendar.getTimeZone();
    DateTimeZone jodaTz = DateTimeZone.forID(tz.getID());
    DateTime appointmentDateTime = new DateTime(appointmentCalendar.getTimeInMillis(), jodaTz);
    LocalDate localDate = appointmentDateTime.toLocalDate();

    // At this point I have the appointment date.  

    // Should e.g. throw an exception for invalid time interval
    validate(hourOfDayFrom, minuteFrom, hourOfDayUntil, minuteUntil);

    // set proper times for calendar
    appointmentCalendar.set(Calendar.HOUR, hourOfDay);
    appointmentCalendar.set(Calendar.MINUTE, minute);
    // store date and times  
    // Should I update the localDate instead of the appointmentCalendar?
}    

问题:

  1. 我应该如何验证小时/分钟?应该包括实际日期还是不相关?

  2. 我应该更新localDate而不是更新appointmentCalendar吗?

4

1 回答 1

2
于 2016-12-03T23:33:48.847 回答