Skip to content

Commit

Permalink
Merge pull request #582 from Kraigie/jb3/fix-statem-datetime-error
Browse files Browse the repository at this point in the history
Fix the error caused by trying to cast a datetime to datetime
  • Loading branch information
jb3 authored May 4, 2024
2 parents 2799a51 + 8fcbd35 commit dfe11f1
Showing 1 changed file with 8 additions and 2 deletions.
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

0 comments on commit dfe11f1

Please sign in to comment.