Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix the error caused by trying to cast a datetime to datetime #582

Merged
merged 1 commit into from
May 4, 2024
Merged
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
10 changes: 8 additions & 2 deletions lib/nostrum/util.ex
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,19 @@ defmodule Nostrum.Util do
end

@doc """
Converts possibly nil ISO8601 timestamp to a `DateTime`
Converts possibly nil ISO8601 timestamp to a `DateTime`.

If a `DateTime` is provided, return it as-is.
"""
@spec maybe_to_datetime(String.t() | nil) :: DateTime.t() | nil
@spec maybe_to_datetime(String.t() | nil | DateTime.t()) :: DateTime.t() | nil
def maybe_to_datetime(nil) do
nil
end

def maybe_to_datetime(%DateTime{} = dt) do
dt
end

def maybe_to_datetime(stamp) do
{:ok, casted, 0} = DateTime.from_iso8601(stamp)
casted
Expand Down