Public Vars

Back

day-of-week (clj)

(source)

function

(day-of-week) (day-of-week v)
extract day-of-week 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 day-of-week
  (let [days (fn [strings] (map t/day-of-week strings))]
    (is (every? #{cljc.java-time.day-of-week/sunday} (days ["sun" "sunday"])))
    (is (every? #{cljc.java-time.day-of-week/monday} (days ["mon" "monday"])))
    (is (every? #{cljc.java-time.day-of-week/tuesday} (days ["tue" "tues" "tuesday"])))
    (is (every? #{cljc.java-time.day-of-week/wednesday} (days ["wed" "weds" "wednesday"])))
    (is (every? #{cljc.java-time.day-of-week/thursday} (days ["thur" "thurs" "thursday"])))
    (is (every? #{cljc.java-time.day-of-week/friday} (days ["fri" "friday"])))
    (is (every? #{cljc.java-time.day-of-week/saturday} (days ["sat" "saturday"])))))

(deftest adjusters
  (is (= (t/date "2022-01-15")
         (t/day-of-week-in-month (t/date "2022-01-01") 3 t/SATURDAY)))
  (is (= (t/date "2022-01-01")
         (t/first-in-month (t/date "2022-01-01") t/SATURDAY)))
  (is (= (t/date "2022-01-29")
         (t/last-in-month (t/date "2022-01-01") t/SATURDAY)))
  (is (= (t/date "2022-01-08")
         (t/next (t/date "2022-01-01") t/SATURDAY)))
  (is (= (t/date "2022-01-01")
         (t/next-or-same (t/date "2022-01-01") t/SATURDAY)))
  (is (= (t/date "2021-12-25")
         (t/previous (t/date "2022-01-01") t/SATURDAY)))
  (is (= (t/date "2022-01-01")
         (t/previous-or-same (t/date "2022-01-01") t/SATURDAY))))


(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))))
lumberdev/tesserae
(ns tesserae.serialize
  (:require [tick.core :as t]
            [time-literals.read-write]
            [cognitect.transit :as transit]
            [hyperfiddle.electric :as e]
            #?(:cljs
               [java.time :refer [Period
                                  LocalDate
                                  LocalDateTime
                                  ZonedDateTime
                                  OffsetTime
                                  Instant
                                  OffsetDateTime
                                  ZoneId
                                  DayOfWeek
                                  LocalTime
                                  Month
                                  Duration
                                  Year
                                  YearMonth]]))
  #?(:clj (:import
            (java.time Period
                       LocalDate
                       LocalDateTime
                       ZonedDateTime
                       OffsetTime
                       Instant
                       OffsetDateTime
                       ZoneId
                       DayOfWeek
                       LocalTime
                       Month
                       Duration
                       Year
                       YearMonth))))


(def time-classes
  {'time/period          Period
   'time/date            LocalDate
   'time/date-time       LocalDateTime
   'time/zoned-date-time ZonedDateTime
   'time/instant         Instant
   ;;'offset-time OffsetTime
   ;;'offset-date-time OffsetDateTime
   'time/time            LocalTime
   'time/duration        Duration
   'time/year            Year
   'time/year-month      YearMonth
   'time/zone            ZoneId
   'time/day-of-week     DayOfWeek
   'time/month           Month})