Created
January 25, 2021 02:05
-
-
Save jasdev/638aae403661a5fee8afa725f4770052 to your computer and use it in GitHub Desktop.
Timecode line parsing with time interval outputs.
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
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