Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Timecode line parsing with time interval outputs.
let timecodeParser = timecodeHours
.skip(StartsWith(":"))
.take(timecodeMinutes)
.skip(StartsWith(":"))
.take(timecodeSeconds)
.skip(StartsWith(","))
.take(timecodeMilliseconds)
.map { hours, minutes, seconds, milliseconds -> TimeInterval in
let hoursInSeconds = Double(hours) * 60 * 60
let minutesInSeconds = Double(minutes) * 60
let millisecondsInSeconds = Double(milliseconds) * 1 / 1_000
return hoursInSeconds + minutesInSeconds + Double(seconds) + millisecondsInSeconds
}
let timecodeLineParser = timecodeParser
.skip(StartsWith(" --> "))
.take(timecodeParser) // ⇒ Parser<Substring, (TimeInterval, TimeInterval)>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment