Created
December 5, 2017 20:43
-
-
Save rafaelrinaldi/494cecf90496350cfc0f9f470a9a9b30 to your computer and use it in GitHub Desktop.
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
(ns api-fetchers.utils | |
(:require [clj-time.format :as format-time] | |
[taoensso.timbre :as timbre :refer [info]]) | |
(:import java.text.SimpleDateFormat | |
[java.time Duration Instant] | |
java.util.zip.ZipInputStream)) | |
(defn unzip | |
"Returns a `ZipInputStream` with the contents of `input-stream`" | |
[input-stream] | |
(-> input-stream | |
(ZipInputStream.) | |
(.getNextEntry))) | |
(defn clean-up | |
[tmp-file] | |
(info "Removing" (str (.getAbsolutePath tmp-file) "...")) | |
(.delete tmp-file) | |
(info "Tempfile removed.")) | |
(defn format-date | |
"Converts `date` from string to a Java `Date` instance. | |
Optionally pass in a date pattern as a second argument." | |
([date] (format-date date "yyyy-MM-dd")) | |
([date format] | |
(-> (SimpleDateFormat. format) (.parse date)))) | |
(defn format-date-iso | |
"Converts `date` from string to a ISO 8601 compliant date format. | |
Optionally pass in a date pattern as a second argument." | |
([date] (format-date-iso date "yyyy-MM-dd")) | |
([date format] | |
(-> (format-time/parse (format-time/formatter format) date) (.toString)))) | |
(defn now [] | |
(Instant/now)) | |
(defn duration [start end] | |
(-> (Duration/between start end) | |
(.toMillis) | |
(Integer/valueOf))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment