Normalization and helper predicates for date formatting options maps. | (ns metabase.util.formatting.internal.date-options (:require [metabase.util :as u] [metabase.util.formatting.constants :as constants])) |
(def ^:private default-options {:date-enabled true :date-style constants/default-date-style :time-style constants/default-time-style :output-density "default" :unit :default}) | |
(def ^:private units-with-hour #{:default :minute :hour :hour-of-day}) | |
(def ^:private units-with-day #{nil :default :minute :hour :day :week}) | |
(def ^:private time-only? #{:hour-of-day}) | |
Normalizes the options map. This returns a Clojure map with Mixes in the [[default-options]], plus:
- defaulting | (defn prepare-options [options] (let [options (-> (u/normalize-map options) (update :unit keyword)) {:keys [compact date-abbreviate type unit] :as options} (merge default-options (when (units-with-hour (:unit options)) {:time-enabled "minutes"}) options)] (cond-> options true (dissoc :compact :date-abbreviate) (time-only? unit) (assoc :date-enabled false) (= type "tooltip") (assoc :output-density "condensed") (or compact date-abbreviate) (assoc :output-density "compact") (not (units-with-day unit)) (dissoc :weekday-enabled)))) |