Files
CljElixir/stubs/NaiveDateTime.clj
2026-03-09 23:09:46 -04:00

127 lines
3.0 KiB
Clojure

(ns NaiveDateTime
"Elixir NaiveDateTime module — datetime without timezone.
In CljElixir: (NaiveDateTime/utc-now), (NaiveDateTime/new 2024 3 9 12 0 0), etc.
'Naive' because it has no timezone information.")
(defn utc-now
"Returns the current UTC naive datetime.
(NaiveDateTime/utc-now) ;=> ~N[2024-03-09 12:00:00]"
([])
([calendar]))
(defn local-now
"Returns the current local naive datetime."
([])
([calendar]))
(defn new
"Creates a new NaiveDateTime.
(NaiveDateTime/new 2024 3 9 12 0 0) ;=> {:ok ~N[2024-03-09 12:00:00]}"
([year month day hour minute second])
([year month day hour minute second microsecond])
([date time]))
(defn new!
"Creates a new NaiveDateTime. Raises on error."
([year month day hour minute second])
([year month day hour minute second microsecond])
([date time]))
(defn from-iso8601
"Parses ISO 8601 string.
(NaiveDateTime/from-iso8601 \"2024-03-09T12:00:00\") ;=> {:ok naive}"
([string])
([string calendar]))
(defn from-iso8601!
"Parses ISO 8601. Raises on error."
([string])
([string calendar]))
(defn to-iso8601
"Converts to ISO 8601 string.
(NaiveDateTime/to-iso8601 ndt) ;=> \"2024-03-09T12:00:00\""
([naive-datetime])
([naive-datetime format]))
(defn to-string
"Converts to string."
[naive-datetime])
(defn to-date
"Extracts the Date part."
[naive-datetime])
(defn to-time
"Extracts the Time part."
[naive-datetime])
(defn add
"Adds time.
(NaiveDateTime/add ndt 3600) ;=> +1 hour"
([naive-datetime amount])
([naive-datetime amount unit]))
(defn diff
"Returns difference.
(NaiveDateTime/diff ndt1 ndt2) ;=> seconds"
([naive-datetime1 naive-datetime2])
([naive-datetime1 naive-datetime2 unit]))
(defn truncate
"Truncates to precision."
[naive-datetime precision])
(defn compare
"Compares two NaiveDateTimes. Returns :lt, :eq, or :gt."
[naive-datetime1 naive-datetime2])
(defn before?
"Returns true if first is before second."
[naive-datetime1 naive-datetime2])
(defn after?
"Returns true if first is after second."
[naive-datetime1 naive-datetime2])
(defn shift
"Shifts by a duration."
[naive-datetime duration])
(defn beginning-of-day
"Returns midnight of the same day."
[naive-datetime])
(defn end-of-day
"Returns 23:59:59.999999 of the same day."
[naive-datetime])
(defn from-erl
"Converts from Erlang datetime tuple.
(NaiveDateTime/from-erl {{2024 3 9} {12 0 0}}) ;=> {:ok naive}"
([tuple])
([tuple microsecond])
([tuple microsecond calendar]))
(defn from-erl!
"Converts from Erlang tuple. Raises on error."
([tuple])
([tuple microsecond])
([tuple microsecond calendar]))
(defn to-erl
"Converts to Erlang datetime tuple.
(NaiveDateTime/to-erl ndt) ;=> {{2024 3 9} {12 0 0}}"
[naive-datetime])
(defn from-gregorian-seconds
"Creates from seconds since year 0."
([seconds])
([seconds microsecond])
([seconds microsecond calendar]))
(defn to-gregorian-seconds
"Returns seconds since year 0."
[naive-datetime])