Created
June 25, 2026 14:40
-
-
Save whamtet/e5f863c413aaece617353a3f36e42a68 to your computer and use it in GitHub Desktop.
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
| #!/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