0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-13 10:38:13 -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
(:require [clojure.set :as set]
[beicon.core :as rx]
[uxbox.util.datetime :as dt]
[uxbox.util.time :as dt]
[uxbox.util.uuid :as uuid]
[potok.core :as ptk]
[uxbox.util.router :as r]

View file

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

View file

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

View file

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

View file

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

View file

@ -18,7 +18,7 @@
[uxbox.main.ui.lightbox :as lbx]
[uxbox.main.ui.keyboard :as kbd]
[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.dom :as dom]))

View file

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

View file

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

View file

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

View file

@ -20,7 +20,7 @@
[uxbox.main.ui.workspace.base :as wb]
[uxbox.main.ui.icons :as i]
[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.dom :as dom]))

View file

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

View file

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