0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-15 11:38:24 -05:00

Rename datetime ns to time.

And rename DateTime type to Instant.
This commit is contained in:
Andrey Antukh 2017-01-06 16:31:57 +01:00
parent d3e81dc810
commit fd7b0b1958
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
12 changed files with 34 additions and 38 deletions

View file

@ -7,7 +7,7 @@
(ns uxbox.main.data.colors (ns uxbox.main.data.colors
(:require [clojure.set :as set] (:require [clojure.set :as set]
[beicon.core :as rx] [beicon.core :as rx]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.uuid :as uuid] [uxbox.util.uuid :as uuid]
[potok.core :as ptk] [potok.core :as ptk]
[uxbox.util.router :as r] [uxbox.util.router :as r]

View file

@ -15,7 +15,7 @@
[uxbox.util.forms :as sc] [uxbox.util.forms :as sc]
[uxbox.main.data.pages :as udp] [uxbox.main.data.pages :as udp]
[uxbox.store :as st] [uxbox.store :as st]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.data :refer (without-keys [uxbox.util.data :refer (without-keys
replace-by-id replace-by-id
index-by)])) index-by)]))

View file

@ -18,7 +18,7 @@
[uxbox.util.router :as r] [uxbox.util.router :as r]
[uxbox.util.i18n :refer (tr)] [uxbox.util.i18n :refer (tr)]
[uxbox.util.forms :as sc] [uxbox.util.forms :as sc]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.data :refer (without-keys replace-by-id)])) [uxbox.util.data :refer (without-keys replace-by-id)]))
;; --- Specs ;; --- Specs

View file

@ -22,7 +22,7 @@
[uxbox.main.data.shapes-impl :as shimpl] [uxbox.main.data.shapes-impl :as shimpl]
[uxbox.main.data.lightbox :as udl] [uxbox.main.data.lightbox :as udl]
[uxbox.main.data.history :as udh] [uxbox.main.data.history :as udh]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.math :as mth] [uxbox.util.math :as mth]
[uxbox.util.data :refer (index-of)])) [uxbox.util.data :refer (index-of)]))

View file

@ -19,7 +19,7 @@
[uxbox.util.i18n :as t :refer (tr)] [uxbox.util.i18n :as t :refer (tr)]
[uxbox.util.data :refer (read-string)] [uxbox.util.data :refer (read-string)]
[uxbox.util.mixins :as mx :include-macros true] [uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[potok.core :as ptk] [potok.core :as ptk]
[uxbox.util.forms :as sc] [uxbox.util.forms :as sc]
[uxbox.util.lens :as ul] [uxbox.util.lens :as ul]

View file

@ -18,7 +18,7 @@
[uxbox.main.ui.lightbox :as lbx] [uxbox.main.ui.lightbox :as lbx]
[uxbox.main.ui.keyboard :as kbd] [uxbox.main.ui.keyboard :as kbd]
[uxbox.main.ui.dashboard.header :refer (header)] [uxbox.main.ui.dashboard.header :refer (header)]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.data :as data :refer (read-string)] [uxbox.util.data :as data :refer (read-string)]
[uxbox.util.dom :as dom])) [uxbox.util.dom :as dom]))

View file

@ -24,7 +24,7 @@
[uxbox.util.dom :as dom] [uxbox.util.dom :as dom]
[uxbox.util.blob :as blob] [uxbox.util.blob :as blob]
[uxbox.util.mixins :as mx :include-macros true] [uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.datetime :as dt])) [uxbox.util.time :as dt]))
;; --- Helpers & Constants ;; --- Helpers & Constants

View file

@ -15,7 +15,7 @@
[potok.core :as ptk] [potok.core :as ptk]
[uxbox.util.mixins :as mx :include-macros true] [uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.dom :as dom] [uxbox.util.dom :as dom]
[uxbox.util.datetime :as dt])) [uxbox.util.time :as dt]))
(def ^:private clipboard-ref (def ^:private clipboard-ref
(-> (l/key :clipboard) (-> (l/key :clipboard)

View file

@ -16,7 +16,7 @@
[uxbox.main.ui.workspace.base :as wb] [uxbox.main.ui.workspace.base :as wb]
[uxbox.util.blob :as blob] [uxbox.util.blob :as blob]
[uxbox.util.data :refer (read-string)] [uxbox.util.data :refer (read-string)]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.dom :as dom] [uxbox.util.dom :as dom]
[uxbox.util.mixins :as mx :include-macros true] [uxbox.util.mixins :as mx :include-macros true]
[potok.core :as ptk] [potok.core :as ptk]

View file

@ -20,7 +20,7 @@
[uxbox.main.ui.workspace.base :as wb] [uxbox.main.ui.workspace.base :as wb]
[uxbox.main.ui.icons :as i] [uxbox.main.ui.icons :as i]
[uxbox.util.mixins :as mx :include-macros true] [uxbox.util.mixins :as mx :include-macros true]
[uxbox.util.datetime :as dt] [uxbox.util.time :as dt]
[uxbox.util.data :refer (read-string)] [uxbox.util.data :refer (read-string)]
[uxbox.util.dom :as dom])) [uxbox.util.dom :as dom]))

View file

@ -4,15 +4,15 @@
;; ;;
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz> ;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
(ns uxbox.util.datetime (ns uxbox.util.time
(:require [cljsjs.moment])) (:require [cljsjs.moment]))
;; A simplified immutable date time representation type. ;; A simplified immutable date time representation type.
(deftype DateTime [^number v] (deftype Instant [^number v]
IComparable IComparable
(-compare [this other] (-compare [this other]
(if (instance? DateTime other) (if (instance? Instant other)
(compare v (.-v other)) (compare v (.-v other))
(throw (js/Error. (str "Cannot compare " this " to " other))))) (throw (js/Error. (str "Cannot compare " this " to " other)))))
@ -20,7 +20,7 @@
(-pr-writer [_ writer _] (-pr-writer [_ writer _]
(let [m (js/moment v) (let [m (js/moment v)
ms (.toISOString m)] ms (.toISOString m)]
(-write writer (str "#datetime \"" ms "\"")))) (-write writer (str "#instant \"" ms "\""))))
Object Object
(toString [this] (toString [this]
@ -33,39 +33,35 @@
IHash IHash
(-hash [_] v)) (-hash [_] v))
(alter-meta! #'->DateTime assoc :private true) (alter-meta! #'->Instant assoc :private true)
(defn datetime (defn instant
"Create a new DateTime instance from "Create a new Instant instance from
unix offset." unix offset."
[v] [v]
{:pre [(number? v)]} {:pre [(number? v)]}
(DateTime. v)) (Instant. v))
(defn datetime?
"Return true if `v` is an instance of DateTime."
[v]
(instance? DateTime v))
(defn instant? (defn instant?
"Return true if `v` is an instance of Instant."
[v] [v]
(instance? DateTime v)) (instance? Instant v))
(defn parse (defn parse
"Parse a string representation of datetime "Parse a string representation of instant
with an optional `format` parameter." with an optional `format` parameter."
([v] (parse v :offset)) ([v] (parse v :offset))
([v fmt] ([v fmt]
(cond (cond
(datetime? v) v (instant? v) v
(= fmt :offset) (DateTime. v) (= fmt :offset) (Instant. v)
:else (let [m (if (= fmt :unix) :else (let [m (if (= fmt :unix)
(js/moment.unix v) (js/moment.unix v)
(js/moment v fmt))] (js/moment v fmt))]
(DateTime. (.valueOf m)))))) (Instant. (.valueOf m))))))
(defn format (defn format
"Returns a string representation of the DateTime "Returns a string representation of the Instant
instance with optional `fmt` format parameter. instance with optional `fmt` format parameter.
You can use `:iso` and `:unix` shortcuts as You can use `:iso` and `:unix` shortcuts as
@ -76,7 +72,7 @@
" "
([v] (format v :iso)) ([v] (format v :iso))
([v fmt] ([v fmt]
{:pre [(datetime? v)]} {:pre [(instant? v)]}
(let [vm (js/moment (.-v v))] (let [vm (js/moment (.-v v))]
(case fmt (case fmt
:unix (.unix vm) :unix (.unix vm)
@ -85,10 +81,10 @@
(.format vm fmt))))) (.format vm fmt)))))
(defn now (defn now
"Return the current DateTime." "Return the current Instant."
[] []
(let [vm (js/moment)] (let [vm (js/moment)]
(DateTime. (.valueOf vm)))) (Instant. (.valueOf vm))))
(defn timeago (defn timeago
[v] [v]

View file

@ -11,17 +11,17 @@
[uxbox.util.data :refer (parse-int)] [uxbox.util.data :refer (parse-int)]
[uxbox.util.geom.point :as gpt] [uxbox.util.geom.point :as gpt]
[uxbox.util.geom.matrix :as gmt] [uxbox.util.geom.matrix :as gmt]
[uxbox.util.datetime :as dt])) [uxbox.util.time :as dt]))
;; --- Transit Handlers ;; --- Transit Handlers
(def datetime-write-handler (def instant-write-handler
(t/write-handler (constantly "m") (t/write-handler (constantly "m")
#(str (dt/format % :offset)))) #(str (dt/format % :offset))))
(def datetime-read-handler (def instant-read-handler
(t/read-handler (t/read-handler
#(dt/datetime (parse-int %)))) #(dt/instant (parse-int %))))
(def point-write-handler (def point-write-handler
(t/write-handler (t/write-handler
@ -47,12 +47,12 @@
(def ^:privare +read-handlers+ (def ^:privare +read-handlers+
{"u" uuid {"u" uuid
"m" datetime-read-handler "m" instant-read-handler
"matrix" matrix-read-handler "matrix" matrix-read-handler
"point" point-read-handler}) "point" point-read-handler})
(def ^:privare +write-handlers+ (def ^:privare +write-handlers+
{dt/DateTime datetime-write-handler {dt/Instant instant-write-handler
gmt/Matrix matrix-write-handler gmt/Matrix matrix-write-handler
gpt/Point point-write-handler}) gpt/Point point-write-handler})