Public Vars

Back

time? (clj)

(source)

function

(time? v)
true if v is a time?

Examples

tick
(ns tick.api-test
  (:require
    [clojure.test
     :refer [deftest is testing run-tests]
     :refer-macros [deftest is testing run-tests]]
    [tick.core :as t]
    [tick.locale-en-us]
    [tick.protocols :as p]
    [cljc.java-time.clock]
    [cljc.java-time.instant]
    [cljc.java-time.day-of-week]
    [cljc.java-time.month]
    [cljc.java-time.year]
    #?@(:cljs [[java.time :refer [Instant]]]))
  #?(:clj
     (:import [java.time Instant])))

(deftest time-construction-test
  (testing "(time)"
    (is (t/time? (t/time))))
  (testing "(midnight)"
    (is (t/time? (t/midnight)))
    (is (= "00:00" (str (t/midnight)))))
  (testing "(noon)"
    (is (t/time? (t/noon)))
    (is (= "12:00" (str (t/noon))))))

(deftest date-construction-test
  (is (= (t/date "2018-01-11")
        (t/date (t/instant 1515691416624))))
  (is (t/date-time? (t/noon (t/today))))
  (t/with-clock (-> (t/date "2018-02-14") (t/at "10:00"))
    (testing "(noon (today))"
      (is (= "2018-02-14T12:00" (str (t/noon (t/today))))))
    (testing "(noon (date))"
      (is (= "2018-02-14T12:00" (str (t/noon (t/date))))))))

(deftest offset-date-time-test
  (let [t "2018-09-24T18:57:08.996+01:00"]
    (testing "offset date time basics"
      (is (t/offset-date-time? (t/offset-date-time (t/now))))
      (is (t/offset-date-time? (t/offset-date-time t)))
      (is (t/offset-date-time? (t/offset-date-time (t/date-time))))
      (is (t/offset-date-time? (t/offset-date-time (t/zoned-date-time)))))))

(deftest zoned-date-time-test
  (is (t/zoned-date-time? (t/zoned-date-time "2020-12-15T12:00:10Z[Europe/London]")))
  (is (t/zoned-date-time? (t/zoned-date-time "2020-12-15T12:00:10+04:00[Europe/London]"))))

(deftest parse-test
  (is (t/date? (t/parse-date "2020/02/02" (t/formatter "yyyy/MM/dd"))))
  (is (t/year? (t/parse-year "20" (t/formatter "yy"))))
  (is (t/year-month? (t/parse-year-month "20/02" (t/formatter "yy/MM"))))
  (is (t/date-time? (t/parse-date-time "2020/02/02:2002" (t/formatter "yyyy/MM/dd:HHmm"))))
  (is (t/time? (t/parse-time "2002" (t/formatter "HHmm"))))
  (is (t/zoned-date-time? (t/parse-zoned-date-time "2020/02/02:2002:Z"
                            (t/formatter "yyyy/MM/dd:HHmm:VV"))))
  (is (t/offset-date-time? (t/parse-offset-date-time "2020/02/02:2002:-08:30"
                             (t/formatter "yyyy/MM/dd:HHmm:VV")))))


(deftest predicates-test
  (is (true? (t/clock? (t/clock))))
  (is (true? (t/day-of-week? t/MONDAY)))
  (is (true? (t/duration? (t/new-duration 1 :minutes))))
  (is (true? (t/instant? (t/instant))))
  (is (true? (t/date? (t/today))))
  (is (true? (t/date-time? (t/at (t/today) (t/new-time 0 0)))))
  (is (true? (t/time? (t/new-time 0 0))))
  (is (true? (t/month? t/MAY)))
  (is (true? (t/offset-date-time? (t/offset-date-time))))
  (is (true? (t/period? (t/new-period 1 :weeks))))
  (is (true? (t/year? (t/year))))
  (is (true? (t/year-month? (t/year-month))))
  (is (true? (t/zone? (t/zone))))
  (is (true? (t/zone-offset? (t/zone-offset (t/zoned-date-time)))))
  (is (true? (t/zoned-date-time? (t/zoned-date-time))))
  (is (false? (t/date? 16)))
  (is (false? (t/month? 16))))
tick
(ns tick.internals-test
  (:require [clojure.test
             :refer [deftest is testing run-tests]
             :refer-macros [deftest is testing run-tests]]
            [tick.core :as t]
            [tick.protocols :as p]))

(deftest parse-test
  (testing "(time \"4pm\")"
    (is (t/time? (p/parse "4pm")))
    (is (= "16:00" (str (p/parse "4pm"))))))
juxt/tick
(ns tick.internals-test
  (:require [clojure.test
             :refer [deftest is testing run-tests]
             :refer-macros [deftest is testing run-tests]]
            [tick.core :as t]
            [tick.protocols :as p]))

(deftest parse-test
  (testing "(time \"4pm\")"
    (is (t/time? (p/parse "4pm")))
    (is (= "16:00" (str (p/parse "4pm"))))))