Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //calculateTotalHours()
- public static String calculateTotalHours(Cell inTime, Cell outTime, Cell breakStart, Cell breakEnd)
- {
- System.out.println(LOG + "calculateTotalHours");
- SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm");
- Date in, out, start, end;
- if(null != inTime && null != outTime && null != breakStart && null != breakEnd)
- {
- try
- {
- in = timeFormat.parse(inTime.getStringCellValue());
- out = timeFormat.parse(outTime.getStringCellValue());
- start = timeFormat.parse(breakStart.getStringCellValue());
- end = timeFormat.parse(breakEnd.getStringCellValue());
- long lunchTotal = end.getTime() - start.getTime();
- long totalWork = out.getTime() - in.getTime();
- long totalTime = totalWork - lunchTotal;
- long diffHours = totalTime/HOURS % 24;
- totalTime -= diffHours;
- long diffMinutes = totalTime/MINUTES % 60;
- totalTime -= diffMinutes;
- return String.format("%02d:%02d", diffHours, diffMinutes);
- }
- catch (ParseException e) {e.printStackTrace();}
- }
- else
- {
- try
- {
- if(null == breakStart || null == breakEnd) {
- in = timeFormat.parse(inTime.getStringCellValue());
- out = timeFormat.parse(outTime.getStringCellValue());
- long totalTime = out.getTime() - in.getTime();
- long diffHours = totalTime/HOURS % 24;
- totalTime -= diffHours;
- long diffMinutes = totalTime/MINUTES % 60;
- totalTime -= diffMinutes;
- return String.format("%02d:%02d", diffHours, diffMinutes);
- }
- else if(null == inTime.getStringCellValue())
- {
- System.out.println(LOG + "inTime is blank");
- return "-1";
- }
- }
- catch (ParseException e) {e.printStackTrace();}
- }
- return "-1";
- }
Add Comment
Please, Sign In to add comment