Files
2026-03-09 23:09:46 -04:00

162 lines
3.4 KiB
Clojure

(ns Date
"Elixir Date module — calendar date operations.
In CljElixir: (Date/utc-today), (Date/new 2024 3 9), etc.")
(defn utc-today
"Returns today's date in UTC.
(Date/utc-today) ;=> ~D[2024-03-09]"
([])
([calendar]))
(defn new
"Creates a new date.
(Date/new 2024 3 9) ;=> {:ok ~D[2024-03-09]}"
([year month day])
([year month day calendar]))
(defn new!
"Creates a new date. Raises on error.
(Date/new! 2024 3 9) ;=> ~D[2024-03-09]"
([year month day])
([year month day calendar]))
(defn from-iso8601
"Parses ISO 8601 date. Returns {:ok date} or {:error reason}.
(Date/from-iso8601 \"2024-03-09\") ;=> {:ok ~D[2024-03-09]}"
([string])
([string calendar]))
(defn from-iso8601!
"Parses ISO 8601. Raises on error."
([string])
([string calendar]))
(defn to-iso8601
"Converts to ISO 8601 string.
(Date/to-iso8601 date) ;=> \"2024-03-09\""
([date])
([date format]))
(defn to-string
"Converts to string.
(Date/to-string date) ;=> \"2024-03-09\""
[date])
(defn add
"Adds days to a date.
(Date/add date 7) ;=> one week later
(Date/add date 1 :month)"
([date days])
([date amount unit]))
(defn diff
"Returns the difference in days between two dates.
(Date/diff date1 date2) ;=> 7"
[date1 date2])
(defn day-of-week
"Returns the day of the week (1=Monday, 7=Sunday).
(Date/day-of-week date) ;=> 6 (Saturday)"
([date])
([date starting-on]))
(defn day-of-year
"Returns the day of the year (1-366).
(Date/day-of-year date) ;=> 69"
[date])
(defn day-of-era
"Returns the day of the era and era number."
[date])
(defn days-in-month
"Returns the number of days in the month.
(Date/days-in-month date) ;=> 31"
[date])
(defn months-in-year
"Returns the number of months in the year."
[date])
(defn quarter-of-year
"Returns the quarter (1-4).
(Date/quarter-of-year date) ;=> 1"
[date])
(defn year-of-era
"Returns the year of the era."
[date])
(defn leap-year?
"Returns true if the date's year is a leap year.
(Date/leap-year? date) ;=> true"
[date])
(defn beginning-of-month
"Returns the first day of the month.
(Date/beginning-of-month date)"
[date])
(defn end-of-month
"Returns the last day of the month.
(Date/end-of-month date)"
[date])
(defn beginning-of-week
"Returns the first day of the week."
([date])
([date starting-on]))
(defn end-of-week
"Returns the last day of the week."
([date])
([date starting-on]))
(defn range
"Creates a date range.
(Date/range date1 date2) ;=> %Date.Range{}"
([first last])
([first last step]))
(defn compare
"Compares two dates. Returns :lt, :eq, or :gt."
[date1 date2])
(defn before?
"Returns true if `date1` is before `date2`."
[date1 date2])
(defn after?
"Returns true if `date1` is after `date2`."
[date1 date2])
(defn shift
"Shifts date by a duration.
(Date/shift date :month 1 :day -3)"
[date duration])
(defn convert
"Converts a date to a different calendar."
([date calendar]))
(defn convert!
"Converts to a different calendar. Raises on error."
([date calendar]))
(defn from-erl
"Converts Erlang date tuple to Date.
(Date/from-erl {2024 3 9}) ;=> {:ok ~D[2024-03-09]}"
([tuple])
([tuple calendar]))
(defn from-erl!
"Converts Erlang date tuple. Raises on error."
([tuple])
([tuple calendar]))
(defn to-erl
"Converts Date to Erlang date tuple.
(Date/to-erl date) ;=> {2024 3 9}"
[date])