Last active
October 25, 2016 01:59
-
-
Save MoralCode/edd2c3b68f240022d4a799c1c3f99645 to your computer and use it in GitHub Desktop.
This is the very core of my MetricTime prank app which can be used/repurposed to convert regular time to Metric Time.
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
//This is the very core of my MetricTime prank app which can be used/repurposed to convert regular time to Metric Time. | |
//See the full app here: https://github.com/DeveloperACE/MetricTime | |
func convertTime(inputTime: (hour: Int, minute: Int, second: Int), toMetric:Bool = true) -> (hour: Int, minute: Int, second: Int) { | |
var millisecondsSinceToday = 0 | |
var convertedTime = (hour: 0, minute: 0, second: 0) | |
if toMetric { | |
millisecondsSinceToday = (inputTime.hour * 3600000 /*milliseconds per hour*/) + (inputTime.minute * 60000 /* milliseconds per minute*/) + (inputTime.second * 1000 /*milliseconds per second*/) | |
} else { | |
millisecondsSinceToday = (inputTime.hour * 8640000 /*metric milliseconds per hour*/) + (inputTime.minute * 86400 /* metric milliseconds per minute*/) + (inputTime.second * 864 /*milliseconds per second*/) | |
} | |
convertedTime.hour = Int(millisecondsSinceToday / 8640000) | |
millisecondsSinceToday -= (convertedTime.hour*8640000) | |
convertedTime.minute = Int(millisecondsSinceToday / 86400) | |
millisecondsSinceToday -= (convertedTime.minute*86400) | |
convertedTime.second = Int(millisecondsSinceToday / 864) | |
//screw milliseconds | |
return convertedTime | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment