I am updating a scheduling application with ability to repeat appointment dates into the future.
The appointment future appointment time is figured out by finding the amount of minutes between the original appointment start time and end time. So, for the instance the appointment is 120 mins long. In the below code, a book time is a period of time in which appointments can be made. So, the booktime and the appointments in it are getting copied. This is one iteration of appointment copying.
Calendar beginCalendar = Calendar.getInstance();
beginCalendar.setTime(newBookTime.getStartDate());
beginCalendar.add(Calendar.MINUTE, bookTimeDiffMinutes);
newAppointment.setStartDate(beginCalendar.getTime());
Calendar endCalendar = Calendar.getInstance();
endCalendar.setTime(newAppointment.getStartDate());
endCalendar.add(Calendar.MINUTE, appointmentDiffMinutes);
newAppointment.setStopDate(endCalendar.getTime());
The issue is that on the daylight savings day where CST turns into CDT … if the start time of the appointment is say 11pm on the CST day and then end time on the CDT day say 2am … my appointment ends an hour later or earlier (depending if they clocks are turning back or forward). This is because when I add X mins for the appointment … there is really say 1 less hour that day, because we skip an hour.
So, when I print the dates I can see on the DST day that the time zone changes from CST to CDT:
The book time should be from 20:00-6:00
[STDOUT] The book time start date:Sat Mar 07 20:00:00 CST 2015
[STDOUT] The book time stop date:Sun Mar 08 07:00:00 CDT 2015
whereas on non-daylight savings change day we see:
[STDOUT] The book time start date:Sun Mar 08 20:00:00 CDT 2015
[STDOUT] The book time stop date:Mon Mar 09 06:00:00 CDT 2015
I want to know how I can compensate for this and ensure my appointment and booktime are the correct length on the day that the timezone changes from CST to CDT. If I had a smart way of detecting the change I could add or subtract 60 mins.
Looking for input.
It appears that the goal is to have an appointment of the same duration, regardless of whether the appointment occurs during daylight or standard time, or happens to straddle a time change. Given that, then your code works just fine, the output is reflecting the fact that it’s printing with changed offsets: a 10 hour appointment that started at 20:00:00 CST the night before DST takes effect should end at 07:00:00 CDT the next day, since the time zone will have “sprung forward” an hour.