Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Updated tzdata to fix issues with 2024b
- Fix deprecation: Module.eval_quoted/4 is deprecated. Use Code.eval_quoted/3 instead
- Fix deprecation: "min..max inside match is deprecated"
- Fix deprecation: default arguments in protocol definitions are deprecated in Elixir 1.20 (`Timex.Comparable.compare/3`, `Timex.Comparable.diff/3`, `Timex.Protocol.to_datetime/2`)

---

Expand Down
4 changes: 2 additions & 2 deletions lib/comparable/comparable.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defprotocol Timex.Comparable do
0
"""
@spec compare(comparable, comparable, granularity) :: compare_result
def compare(a, b, granularity \\ :microsecond)
def compare(a, b, granularity)

@doc """
Get the difference between two date or datetime types.
Expand Down Expand Up @@ -136,5 +136,5 @@ defprotocol Timex.Comparable do
0
"""
@spec diff(comparable, comparable, granularity) :: diff_result
def diff(a, b, granularity \\ :microsecond)
def diff(a, b, granularity)
end
3 changes: 1 addition & 2 deletions lib/protocol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@ defprotocol Timex.Protocol do
Convert a date/time value to a DateTime.
An optional timezone can be provided, UTC will be assumed if one is not provided.
"""
@spec to_datetime(Types.valid_datetime()) :: DateTime.t() | {:error, term}
@spec to_datetime(Types.valid_datetime(), Types.valid_timezone()) ::
DateTime.t() | Timex.AmbiguousDateTime.t() | {:error, term}
def to_datetime(datetime, timezone \\ :utc)
def to_datetime(datetime, timezone)

@doc """
Convert a date/time value to a NaiveDateTime
Expand Down
4 changes: 2 additions & 2 deletions lib/timex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,7 @@ defmodule Timex do
compare(a, b, :microseconds)
end

defdelegate compare(a, b), to: Timex.Comparable
def compare(a, b), do: Timex.Comparable.compare(a, b, :microsecond)

@doc """
Compare two `Timex.Comparable` values, returning one of the following values:
Expand Down Expand Up @@ -1090,7 +1090,7 @@ defmodule Timex do
@spec diff(Time.t() | Comparable.comparable(), Time.t() | Comparable.comparable()) ::
Duration.t() | integer | {:error, term}
def diff(%Time{} = a, %Time{} = b), do: diff(a, b, :microseconds)
defdelegate diff(a, b), to: Timex.Comparable
def diff(a, b), do: Timex.Comparable.diff(a, b, :microsecond)

@doc """
Calculate time interval between two dates. The result will be a signed integer, negative
Expand Down