我的用例——我是一名医生。在给定的一天,我有几个小时有空,有一些时间没有空。我想创建一个对象 Period myWorkDay。当有人确定上午 8 点到 9 点的约会时(即 Period patient1Appointment),该时间段将从 myWorkDay 中“删除”。当新患者访问 myWorkDay 时,他只能看到 myWorkDay - patient1Appointment。如果患者 1 释放他的时间段,那么新患者会看到完整的 myWorkDay。
是否可以使用 JodaTime 做到这一点?
有一个不必要的额外要求。但是,如果你知道怎么做,那么请告诉我。
Extra - 在 myWorkDay 中为特定期间定义任务并执行它们。例如。8-9 期间(8-8:30 钻牙,8:30 - 8:45 磨牙,8:45-9:00 做一些文书工作,然后在 9 点欢迎另一位患者)
import org.joda.time.*;
public class PeriodManager {
public static void main(String[]args){
DateTime startTime = new DateTime(2013, 7, 1, 9, 0);//(int year, int monthOfYear, int dayOfMonth, int hourOfDay, int minuteOfHour)
DateTime endTime = new DateTime(2013, 7, 1, 17, 0);// 9 to 5 (or 17) job :)
Period fullDay = new Period(startTime, endTime);
System.out.println("full day - " + fullDay);
startTime = new DateTime(2013, 7, 1, 9, 0);
endTime = new DateTime(2013, 7, 1, 10, 0);
Period patient1Appointment = new Period(startTime, endTime);//9-10
fullDay.minus(patient1Appointment);
System.out.println("full day - pat 1 " + fullDay);
startTime = new DateTime(2013, 7, 1, 9, 0);
endTime = new DateTime(2013, 7, 1, 10, 0);
Period patient1CancelAppointment = new Period(startTime, endTime);
fullDay.plus(patient1CancelAppointment);
System.out.println("full day + pat 1 " + fullDay);
startTime = new DateTime(2013, 7, 1, 9, 0);
endTime = new DateTime(2013, 7, 1, 10, 0);
Period patient2Appointment = new Period(startTime, endTime);
fullDay.minus(patient2Appointment);
System.out.println("full day - pat 2 " + fullDay);
}
}