Public Vars

Back

minutes (clj)

(source)

function

(minutes v)
extract minutes from 'v'

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 addition-test
  (is (= (t/new-duration 5 :seconds) (t/+ (t/new-duration 2 :seconds) (t/new-duration 3 :seconds))))
  (is (= (t/new-duration 2 :minutes) (t/+ (t/new-duration 90 :seconds) (t/new-duration 30 :seconds)))))

  (let [now (t/instant)
        from (t/<< now (t/new-duration 10 :seconds))
        to (t/>> now (t/new-duration 10 :seconds))]
    (is (= (t/new-duration 20 :seconds) (t/between from to) ))
    (is (= 20 (t/between from to :seconds))))
  (is
    (= (t/new-duration 48 :hours)
      (t/between (t/beginning (t/today)) (t/end (t/tomorrow)))))
  (let [start (t/date-time "2020-01-01T12:00") 
        end (t/date-time "2020-01-01T12:02")]
    (is
      (=
        (t/new-duration 2 :minutes)
        (t/between start end))
      (= 2 (t/between start end :minutes))))
  (is
    (=
      (t/new-duration 30 :minutes)
      (t/between (t/new-time 11 0 0) (t/new-time 11 30 0))))
  (testing "LocalDate"
    (let [start (t/date "2020-01-01")
          end (t/date "2020-01-02")]
      (is (= (t/new-period 1 :days)
            (t/between start end)))
      (is (= 1 (t/between start end :days))))))

(deftest truncate-test
  (let [dates [(t/instant) (t/zoned-date-time) (t/date-time)
               (t/offset-date-time) (t/time)]
        truncate-tos [:nanos
                     :micros
                     :millis
                     :seconds
                     :minutes
                     :hours
                     :half-days
                     :days     ]]
    (doseq [date dates
            truncate-to truncate-tos]
      (is (t/truncate date truncate-to)))))

;; Durations. Convenience functions to create durations of specific
;; units.
(deftest duration-functions-test
  (is (= (t/of-nanos 10) (t/new-duration 10 :nanos)))
  (is (= (t/of-micros 10) (t/new-duration 10 :micros))) ;java.time.Duration doesn't have ofMicros method
  (is (= (t/of-millis 10) (t/new-duration 10 :millis)))
  (is (= (t/of-seconds 10) (t/new-duration 10 :seconds)))
  (is (= (t/of-minutes 10) (t/new-duration 10 :minutes)))
  (is (= (t/of-hours 10) (t/new-duration 10 :hours))))


(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))))
borgeby/jarl
(ns jarl.builtins.http-test
  (:require [jarl.builtins.http :refer [builtin-http-send content-type create-request parse-timeout]]
            [jarl.exceptions :as errors]
            [jarl.types :refer [rego-equal?]]
            [jarl.http-client :as http-client]
            [jarl.time :as time]
            #?(:clj  [clojure.test :refer [deftest is testing]]
               :cljs [cljs.test :refer [deftest is testing]])
            [tick.core :as t]))

  (testing "cache from response headers, expires"
    (let [counter (atom 0)
          req {"method" "get" "url" "http://borge.by/jarl" "cache" true}]
      (with-redefs [http-client/send-request
                    (fn [_]
                      (swap! counter inc)
                      {:status 200
                       :headers {"content-type" "application/json"
                                 "date" "Sat, 01 Jan 2022 15:10:05 GMT"
                                 "expires" "Sat, 01 Jan 2022 15:40:05 GMT"}
                       :body "{\"foo\":\"bar\"}"})]
        (let [res {"body" {"foo" "bar"}
                   "headers" {"content-type" "application/json"
                              "date" "Sat, 01 Jan 2022 15:10:05 GMT"
                              "expires" "Sat, 01 Jan 2022 15:40:05 GMT"}
                   "raw_body" "{\"foo\":\"bar\"}" "status" "200 OK" "status_code" 200}
              now   (t/instant (t/zoned-date-time "2022-01-01T15:10:05Z"))
              exp   (time/instant->ns (t/>> now (t/new-duration 60 :minutes)))
              bctx {:time-now-ns (time/instant->ns now)}]
          (is (= (builtin-http-send {:args [req] :builtin-context bctx}) res))
          (is (= @counter 1))
          (is (= (builtin-http-send {:args [req] :builtin-context bctx}) res))
          (is (= @counter 1))
          (is (= (builtin-http-send {:args [req] :builtin-context {:time-now-ns exp}}) res)) ; fast-forward 1 hour
          (is (= @counter 2)))))))
teknql/wing
(ns wing.core.time-test
  (:require [wing.core.time :as sut]
            [clojure.test :refer [deftest testing is]]
            [tick.core :as t]))


(deftest divisible?-test
  (testing "returns true for durations that are evenly divisible"
    (is (sut/divisible? (t/new-duration 20 :minutes) (t/new-duration 1 :minutes)))
    (is (sut/divisible? (t/new-duration 20 :minutes) (t/new-duration 5 :minutes))))
  (testing "returns false for durations that are not evenly divisible"
    (is (not (sut/divisible? (t/new-duration 19 :minutes) (t/new-duration 5 :minutes))))))

(deftest round-to-test
  (testing "rounds down to a divisible value"
    (is (= (t/at (t/new-date 2018 1 1) (t/new-time 1 5))
           (sut/round-to (t/at (t/new-date 2018 1 1) (t/new-time 1 7))
                         (t/new-duration 5 :minutes))))))

(deftest ensure-chronological-test
  (let [times (take 3 (iterate #(t/>> % (t/new-duration 1 :minutes)) (t/now)))]
    (testing "filters non-chronological items"
      (is (= times
             (sut/ensure-chronological times)))
      (is (= (list (last times))
             (sut/ensure-chronological (reverse times)))))