Last active
January 29, 2018 14:39
-
-
Save imixtron/0eed4809e1cf40ac2a33c2fb8f6be7ed to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Time Difference takes input in Hours Format | |
* Author: imixtron | |
* Accepts: String Values (HH:MM) | |
* Max: 24:00, Min: 00:00 | |
* | |
* example timeDifference("10:37","12:35") | |
*/ | |
timeDifference(from, to) { | |
let _from = from.split(':'); | |
let _to = to.split(':'); | |
//TODO: ERROR HANDLING FOR MAX / MIN | |
let _fromHours = _from[0]; | |
let _toHours = _to[0]; | |
let _fromMinutes = _from[1]; | |
let _toMinutes = _to[1]; | |
let diffHours = _toHours - _fromHours; | |
let diffMinutes = _toMinutes - _fromMinutes; | |
let extraHours = diffMinutes < 0 ? 1 : 0; | |
diffMinutes = diffMinutes < 0 ? diffMinutes + 60 : diffMinutes; | |
return (diffHours - extraHours) + ':' + (diffMinutes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment