Back

read-instant-timestamp (clj)

(source)

function

(read-instant-timestamp cs)
To read an instant as a java.sql.Timestamp, bind *data-readers* to a map with this var as the value for the 'inst key. Timestamp preserves fractional seconds with nanosecond precision. The timezone offset will be used to convert into UTC.

Examples

clojure/core.typed
(deftest read-instant-date-test
  (is-tc-e   (read-instant-date "2014-04-23T10:13Z") java.util.Date
             :requires [[clojure.instant :refer [read-instant-date]]])
  (is-tc-err   (read-instant-date "2014-04-23T10:13Z") String
             :requires [[clojure.instant :refer [read-instant-date]]])
  (is-tc-err   (read-instant-date 201404231013) java.util.Date
             :requires [[clojure.instant :refer [read-instant-date]]]))
           
(deftest read-instant-calendar-test
  (is-tc-e   (read-instant-calendar "2014-04-23T10:13Z") java.util.GregorianCalendar             
             :requires [[clojure.instant :refer [read-instant-calendar]]])
  (is-tc-err   (read-instant-calendar "2014-04-23T10:13Z") String
            :requires [[clojure.instant :refer [read-instant-calendar]]])
  (is-tc-err   (read-instant-calendar 201404231013) java.util.GregorianCalendar
            :requires [[clojure.instant :refer [read-instant-calendar]]]))

(deftest read-instant-timestamp-test
  (is-tc-e   (read-instant-timestamp "2014-04-23T10:13Z") java.sql.Timestamp             
            :requires [[clojure.instant :refer [read-instant-timestamp]]])
  (is-tc-err   (read-instant-timestamp "2014-04-23T10:13Z") String
            :requires [[clojure.instant :refer [read-instant-timestamp]]])
  (is-tc-err   (read-instant-timestamp 201404231013) java.sql.Timestamp            
            :requires [[clojure.instant :refer [read-instant-timestamp]]])) 
typedclojure/typedclojure
(deftest read-instant-date-test
  (is-tc-e (read-instant-date "2014-04-23T10:13Z") java.util.Date
           :requires [[clojure.instant :refer [read-instant-date]]])
  (is-tc-err (read-instant-date "2014-04-23T10:13Z") t/Str
             :requires [[clojure.instant :refer [read-instant-date]]])
  (is-tc-err (read-instant-date 201404231013) java.util.Date
             :requires [[clojure.instant :refer [read-instant-date]]]))
           
(deftest read-instant-calendar-test
  (is-tc-e (read-instant-calendar "2014-04-23T10:13Z") java.util.GregorianCalendar             
           :requires [[clojure.instant :refer [read-instant-calendar]]])
  (is-tc-err (read-instant-calendar "2014-04-23T10:13Z") t/Str
             :requires [[clojure.instant :refer [read-instant-calendar]]])
  (is-tc-err (read-instant-calendar 201404231013) java.util.GregorianCalendar
             :requires [[clojure.instant :refer [read-instant-calendar]]]))

(deftest read-instant-timestamp-test
  (is-tc-e (read-instant-timestamp "2014-04-23T10:13Z") java.sql.Timestamp             
           :requires [[clojure.instant :refer [read-instant-timestamp]]])
  (is-tc-err (read-instant-timestamp "2014-04-23T10:13Z") t/Str
             :requires [[clojure.instant :refer [read-instant-timestamp]]])
  (is-tc-err (read-instant-timestamp 201404231013) java.sql.Timestamp            
             :requires [[clojure.instant :refer [read-instant-timestamp]]])) 
ilevd/toml
(ns toml.core-test
  (:require [clojure.instant :refer [read-instant-timestamp]]
            [clojure.test :refer :all]
            [toml.core :as toml]))


(deftest datetime-test
  (testing "Datetime"
    (is (= (toml/read "mydob = 1975-10-03T16:20:00Z # and a comment, just because")
           {"mydob" (read-instant-timestamp "1975-10-03T16:20:00Z")}))
    ;; this fails
    ;(is (= (toml/read  "mydob = 1975-10-03T16:20:00.999999Z # and a comment, just because")
    ;       {"mydob" (read-instant-timestamp "1975-10-03T16:20:00.999999Z")}))
    (is (= (toml/read "mydob = 1975-10-03T16:20:00-07:00 # and a comment, just because")
           {"mydob" (read-instant-timestamp "1975-10-03T16:20:00-07:00")}))
    ;; this fails
    ;(is (= (toml/read  "mydob = 1975-10-03T16:20:00.999999-07:00 # and a comment, just because")
    ;       {"mydob" (read-instant-timestamp "1975-10-03T16:20:00.999999-07:00")}))
    ))