Back

read-instant-date (clj)

(source)

function

(read-instant-date cs)
To read an instant as a java.util.Date, bind *data-readers* to a map with this var as the value for the 'inst key. The timezone offset will be used to convert into UTC.

Examples

babashka/babashka
(ns babashka.impl.clojure.instant
  (:require [clojure.instant :as i]
            [sci.core :as sci]))

(def instant-namespace
  {'read-instant-date (sci/copy-var i/read-instant-date ins)
   'parse-timestamp (sci/copy-var i/parse-timestamp ins)})
ajk/specialist-server
(ns specialist-server.type-test
  (:require [clojure.test :refer :all]
            [clojure.spec.alpha :as s]
            [clojure.instant :refer [read-instant-date]]
            [clojure.pprint :refer [pprint]]
            [specialist-server.type :as t]
            [specialist-server.introspection :as i])
  (:import (java.text SimpleDateFormat)))


(t/defscalar
  date
  {:name "Date" :description "Custom date scalar."}
  (fn [v]
    (if (inst? v)
      v
      (try
        (read-instant-date v)
        (catch Exception _ ::s/invalid)))))
untangled-web/sql-datomic
(ns sql-datomic.parser-test
  (:require [clojure.test :refer :all]
            [sql-datomic.parser :as prs]
            [instaparse.core :as insta]
            [clj-time.core :as tm]
            [clojure.instant :as inst]))

(deftest transform-tests
  (testing "SELECT AST -> IR"
    (is (= (prs/transform
            [:sql_data_statement
             [:select_statement
              [:select_list
               [:qualified_asterisk "a_table"]
               [:column_name "b_table" "zebra_id"]]
              [:from_clause
               [:table_ref [:table_name "a_table"]]
               [:table_ref [:table_name "b_table"]]]
              [:where_clause
               [:search_condition
                [:boolean_term
                 [:boolean_term
                  [:boolean_term
                   [:boolean_factor
                    [:boolean_test
                     [:binary_comparison
                      [:column_name "a_table" "id"]
                      "="
                      [:column_name "b_table" "id"]]]]]
                  [:boolean_factor
                   [:boolean_test
                    [:binary_comparison
                     [:column_name "b_table" "zebra_id"]
                     ">"
                     [:long_literal "9000"]]]]]
                 [:boolean_factor
                  [:boolean_test
                   [:binary_comparison
                    [:column_name "b_table" "hired_on"]
                    "<"
                    [:date_literal "2011-11-11"]]]]]]]]])
           {:type :select
            :fields [:a_table/*
                     {:table "b_table" :column "zebra_id"}]
            :tables [{:name "a_table"} {:name "b_table"}]
            :where [(list :=
                          {:table "a_table" :column "id"}
                          {:table "b_table" :column "id"})
                    (list :>
                          {:table "b_table" :column "zebra_id"}
                          9000)
                    (list :<
                          {:table "b_table" :column "hired_on"}
                          (->> (tm/date-time 2011 11 11)
                               str
                               inst/read-instant-date))]
            }))