Skip to content

Instantly share code, notes, and snippets.

@whamtet
Created June 25, 2026 14:40
Show Gist options
  • Select an option

  • Save whamtet/e5f863c413aaece617353a3f36e42a68 to your computer and use it in GitHub Desktop.

Select an option

Save whamtet/e5f863c413aaece617353a3f36e42a68 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bb
(ns srt.core
(:require [clojure.string :as str])
(:import
[java.time LocalTime]
[java.time.format DateTimeFormatter]
[java.time.temporal ChronoUnit]))
(def fmt (DateTimeFormatter/ofPattern "HH:mm:ss,SSS"))
(def divider " --> ")
(defn inc-str [s inc]
(-> (LocalTime/parse s fmt)
(.plus inc ChronoUnit/SECONDS)
(.format fmt)))
(defn inc-strs [s inc]
(let [[a b] (str/split s (re-pattern (java.util.regex.Pattern/quote divider)))]
(str (inc-str a inc)
divider
(inc-str b inc))))
(defn map-line [line inc]
(if (str/includes? line divider)
(inc-strs line inc)
line))
(defn -main [& [inc]]
(let [inc (Long/parseLong inc)]
(->> (line-seq (java.io.BufferedReader. *in*))
(map #(map-line % inc))
(str/join "\n")
print)))
(when (= *file* (System/getProperty "babashka.file"))
(apply -main *command-line-args*))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment