Preface: This program is for a school assignment. When I run the program on my machine everything seems to function properly. However, the evaluators encounter issues with timestamp conversions.
public abstract class TimeUtil {
private static final Locale loc = Locale.getDefault();
private static final ZoneId localZoneId = ZoneId.systemDefault();
private static final ZoneId utcZoneId = ZoneId.of("Etc/UTC");
private static final ZoneId estZoneId = ZoneId.of("America/New_York");
public static final DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
public static final LocalTime openHour = LocalTime.of(8, 0, 0);
public static final LocalTime closeHour = LocalTime.of(22, 0, 0);
public static LocalDateTime utcNow(){ return LocalDateTime.now(utcZoneId); }
public static LocalDateTime localNow(){ return LocalDateTime.now(localZoneId); }
public static LocalDateTime utcToLocal(LocalDateTime ldt){ return ldt.atZone(utcZoneId).withZoneSameInstant(localZoneId).toLocalDateTime(); }
public static LocalDateTime localToUtc(LocalDateTime ldt) { return ldt.atZone(localZoneId).withZoneSameInstant(utcZoneId).toLocalDateTime(); }
public static LocalDateTime utcToEst(LocalDateTime ldt) { return ldt.atZone(utcZoneId).withZoneSameInstant(estZoneId).toLocalDateTime(); }
public static LocalDateTime localToEst(LocalDateTime ldt) { return ldt.atZone(localZoneId).withZoneSameInstant(estZoneId).toLocalDateTime(); }
LocalDateTime start = TimeUtil.localToUtc(LocalDateTime.of(startDate.getValue() ,LocalTime.of(Integer.parseInt(startHour.getSelectionModel().getSelectedItem()),
Integer.parseInt(startMin.getSelectionModel().getSelectedItem()), 0)));
LocalDateTime end = TimeUtil.localToUtc(LocalDateTime.of(endDate.getValue(), LocalTime.of(Integer.parseInt(endHour.getSelectionModel().getSelectedItem()),
Integer.parseInt(endMin.getSelectionModel().getSelectedItem()), 0)));
if (TimeUtil.isValid(Integer.parseInt(apptId.getText()), start, end)) {
Like I mentioned, I've tried the program dozens of times and each time I get expected behavior. I am unable to reproduce the behavior as seen by the evaluators. I checked the question regarding timestamps, timezones, locales, and servers but couldn't really find anything that helped. Thanks in advance for the help!
I have discovered the issue. I was using ?connectionTimeZone = SERVER in my database connection string, which was converting times automatically and then I was converting them again.