Skip to content

Instantly share code, notes, and snippets.

@hlship
Last active August 29, 2015 14:07
Show Gist options
  • Save hlship/34d93be1f292561a7ac8 to your computer and use it in GitHub Desktop.
Save hlship/34d93be1f292561a7ac8 to your computer and use it in GitHub Desktop.
Force all Dates and Timestamps to use UTC
(ns setup
(:import
[java.util Date Calendar TimeZone]
[java.sql PreparedStatement])
(:require
[clj-time.coerce :as coerce]
[clojure.java.jdbc :as jdbc]))
(extend-type Date
jdbc/ISQLParameter
(set-parameter [val ^PreparedStatement stmt ix]
(let [cal (Calendar/getInstance (TimeZone/getTimeZone "UTC"))]
(.setTimestamp stmt ix (coerce/to-timestamp val) cal))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment