Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1.  
  2. // Variables for calculation.
  3. int timeDif; int startTime; int endTime;
  4. int startHour; int startMin; int startSec;
  5. int endHour; int endMin; int endSec;
  6. int startDay; int endDay;
  7.  
  8. // Part of the Extra Credit. Finding the day values.
  9. startDay = stoi(startDateValue.substr(6, 2));
  10. endDay = stoi(dateValue.substr(6, 2));
  11.  
  12. // Start time individual values from string to integer.
  13. startHour = stoi(startDateValue.substr(8, 2));
  14. startMin = stoi(startDateValue.substr(10, 2));
  15. startSec = stoi(startDateValue.substr(12, 2));
  16.  
  17. // Start time in seconds format.
  18. startTime = (((startHour * 60) + startMin) * 60) + startSec;
  19.  
  20. // End time individual values from string to integer.
  21. endHour = stoi(dateValue.substr(8, 2));
  22. endMin = stoi(dateValue.substr(10, 2));
  23. endSec = stoi(dateValue.substr(12, 2));
  24.  
  25. // End time in seconds format.
  26. endTime = (((endHour * 60) + endMin) * 60) + endSec;
  27.  
  28. // Second part of extra credit.
  29. // If the days do not equal each other,
  30. // a days worth of seconds is added to the
  31. // end time to account for calls going over night.
  32. if (startDay != endDay) {
  33. endTime = endTime + 86400;
  34. }
  35.  
  36. // The final calculation of the duration.
  37. timeDif = endTime - startTime;
  38.  
  39. return timeDif;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement