Skip to content

Instantly share code, notes, and snippets.

@MoralCode
Last active October 25, 2016 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MoralCode/edd2c3b68f240022d4a799c1c3f99645 to your computer and use it in GitHub Desktop.
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 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