Back

divide-by (clj)

(source)

function

(divide-by divisor t)

Examples

tick
(ns tick.alpha.interval-test
  (:require
   [clojure.spec.alpha :as s]
   [tick.core :as t]
   [tick.protocols :as p]
   [clojure.test
    :refer [deftest is testing run-tests]
    :refer-macros [deftest is testing run-tests]]
   [tick.alpha.interval :as ti]
   #?@(:cljs [[java.time :refer [Instant LocalDateTime LocalTime]]]))
  #?(:clj
     (:import [java.time LocalDateTime Instant LocalTime])))

(deftest division-test2
  (is (= 365 (count (ti/divide-by t/date (t/year 2017)))))
  (is (= 12 (count (ti/divide-by t/year-month (t/year 2017)))))
  (is (= 30 (count (ti/divide-by t/date (t/year-month "2017-09")))))
  (is (= (t/date "2017-09-01") (first (ti/divide-by t/date (t/year-month "2017-09")))))
  (is (= (t/date "2017-09-30") (last (ti/divide-by t/date (t/year-month "2017-09")))))
  (is (= 31 (count (ti/divide-by t/date (t/year-month "2017-10")))))
  (is (= 8 (count (ti/divide-by t/date (ti/bounds (t/date "2017-10-03") (t/date "2017-10-10"))))))
  (is (= [(t/date "2017-09-10")] (ti/divide-by t/date (ti/bounds (t/date-time "2017-09-10T12:00")
                                                        (t/date-time "2017-09-10T14:00")))))
  (is (= [(t/date "2017-09-10") (t/date "2017-09-11")] (ti/divide-by t/date (ti/bounds (t/date-time "2017-09-10T12:00") (t/date-time "2017-09-11T14:00")))))
  (is (= 2 (count (ti/divide-by t/year-month (ti/bounds (t/date "2017-09-10") (t/date "2017-10-10"))))))
  (is (= 3 (count (ti/divide-by t/year (ti/bounds (t/date-time "2017-09-10T12:00") (t/year "2019"))))))
  (is (= 3 (count (ti/divide-by t/year (ti/bounds (t/date-time "2017-09-10T12:00") (t/year-month "2019-02"))))))
  (is (= 24 (count (ti/divide-by (t/new-duration 1 :hours) (t/date "2017-09-10"))))))