Created
July 30, 2018 03:04
-
-
Save karkianish/e46e2acc8edfbdc3c7662e2e91b4cd73 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TimesheetCalculator { | |
constructor(shiftDurations) { | |
this.shiftDurations = shiftDurations; | |
} | |
getCalculatedTime() { | |
const durationsWithMinsInDecimal = this.shiftDurations.split(' '); | |
const durationsWithMins = []; | |
for (let duration of durationsWithMinsInDecimal) { | |
const hourPart = duration.split('.')[0]; | |
let minutes; | |
if (duration.includes('.')) { | |
let minsAsDecimal = duration.split('.')[1]; | |
minutes = Math.round(Number.parseFloat('.' + minsAsDecimal) * 60); | |
const minPartAsString = minutes.toString(); | |
const paddedMinPart = ('00' + minPartAsString).substring(minPartAsString.length); | |
durationsWithMins.push(hourPart + ':' + paddedMinPart); | |
} else { | |
durationsWithMins.push(hourPart + ':00'); | |
} | |
} | |
return durationsWithMins | |
} | |
} | |
const a = new TimesheetCalculator('7.56 8.22 8.08 8.5 9.9'); | |
const b = a.getCalculatedTime(); | |
console.log(b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment