mirror of
https://github.com/penpot/penpot.git
synced 2025-06-12 02:11:39 +02:00
✨ Add truncate function to time ns on backend.
This commit is contained in:
parent
0092806dda
commit
686cacd5ae
1 changed files with 22 additions and 5 deletions
|
@ -17,6 +17,8 @@
|
||||||
java.time.ZonedDateTime
|
java.time.ZonedDateTime
|
||||||
java.time.format.DateTimeFormatter
|
java.time.format.DateTimeFormatter
|
||||||
java.time.temporal.TemporalAmount
|
java.time.temporal.TemporalAmount
|
||||||
|
java.time.temporal.TemporalUnit
|
||||||
|
java.time.temporal.ChronoUnit
|
||||||
java.util.Date
|
java.util.Date
|
||||||
org.apache.logging.log4j.core.util.CronExpression))
|
org.apache.logging.log4j.core.util.CronExpression))
|
||||||
|
|
||||||
|
@ -54,15 +56,30 @@
|
||||||
:else
|
:else
|
||||||
(obj->duration ms-or-obj)))
|
(obj->duration ms-or-obj)))
|
||||||
|
|
||||||
(defn duration-between
|
|
||||||
{:deprecated true}
|
|
||||||
[t1 t2]
|
|
||||||
(Duration/between t1 t2))
|
|
||||||
|
|
||||||
(defn diff
|
(defn diff
|
||||||
[t1 t2]
|
[t1 t2]
|
||||||
(Duration/between t1 t2))
|
(Duration/between t1 t2))
|
||||||
|
|
||||||
|
(defn truncate
|
||||||
|
[o unit]
|
||||||
|
(let [unit (if (instance? TemporalUnit unit)
|
||||||
|
unit
|
||||||
|
(case unit
|
||||||
|
:nanos ChronoUnit/NANOS
|
||||||
|
:millis ChronoUnit/MILLIS
|
||||||
|
:micros ChronoUnit/MICROS
|
||||||
|
:seconds ChronoUnit/SECONDS
|
||||||
|
:minutes ChronoUnit/MINUTES))]
|
||||||
|
(cond
|
||||||
|
(instance? Instant o)
|
||||||
|
(.truncatedTo ^Instant o ^TemporalUnit unit)
|
||||||
|
|
||||||
|
(instance? Duration o)
|
||||||
|
(.truncatedTo ^Duration o ^TemporalUnit unit)
|
||||||
|
|
||||||
|
:else
|
||||||
|
(throw (IllegalArgumentException. "only instant and duration allowed")))))
|
||||||
|
|
||||||
(s/def ::duration
|
(s/def ::duration
|
||||||
(s/conformer
|
(s/conformer
|
||||||
(fn [v]
|
(fn [v]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue