private void adjustUserShift(User user, Shift currentShift) { Application application = Application.getInstance(); Calendar currentTime = Calendar.getInstance(); if (user.isClockedIn() != null && user.isClockedIn().booleanValue()) { Shift userShift = user.getCurrentShift(); Date userLastClockInTime = user.getLastClockInTime(); long elaspedTimeSinceLastLogin = Math.abs(currentTime.getTimeInMillis() - userLastClockInTime.getTime()); if (userShift != null) { if (!userShift.equals(currentShift)) { reClockInUser(currentTime, user, currentShift); } else if (userShift.getShiftLength() != null && (elaspedTimeSinceLastLogin >= userShift.getShiftLength())) { reClockInUser(currentTime, user, currentShift); } } else { user.doClockIn(application.getTerminal(), currentShift, currentTime); } } else { user.doClockIn(application.getTerminal(), currentShift, currentTime); } }