You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Timex.Types.calendar_types() and Timex.Types.valid_datetime() include Time.t() since 2a912f3.
However no support for Time.t() was ever added to align with the updated typespec changes. The docs in e.g. Timex.Format.DateTime.Formatter correctly state that the datetime formatter only supports DateTime.t(), Date.t() and NaiveDateTime.t(). This means that typespecs of the following functions don't correspond to what they actually support:
The errors seen above in Steps to reproduce are caused by a call to Timex.Protocol.to_naive_datetime/1 (which is referenced by both Timex.Format.DateTime.Formatters.Relative.lformat/3 and Timex.Format.DateTime.Formatters.Relative.relative_to/4) because the protocol is not implemented for Time.
Ways to solve
Option 1:
Remove Time.t() from the typespecs
Remove Time from the guard in Timex.Format.DateTime.Formatter.lformat/3 such that the function call instead returns {:error, :invalid_date} when a Time-struct is passed
Option 2:
Add support for Time.t()
I would expect such support to act like the behaviour of a passed 'today'-value of type DateTime or NaiveDateTime, i.e. returning values such as {:ok, "8 hours ago"} or {:ok, "in 1 hour"}.
I'm not sure if it makes sense to implement Timex.Protocol for Time since a lot of the functions are date-related, so maybe it makes sense to instead make a separate clause of Timex.Format.DateTime.Formatters.Relative.lformat/3 which handles Time just slightly differently to how Date, DateTime and NaiveDateTime are handled.
(Very similar function clause, but call do_format/5 with the passed Time-struct and Time.utc_now() instead of Timex.Protocol.to_naive_datetime(date) and Timex.Protocol.now()?)
The text was updated successfully, but these errors were encountered:
Steps to reproduce
Description of issue
Timex.Types.calendar_types()
andTimex.Types.valid_datetime()
includeTime.t()
since 2a912f3.However no support for
Time.t()
was ever added to align with the updated typespec changes. The docs in e.g.Timex.Format.DateTime.Formatter
correctly state that the datetime formatter only supportsDateTime.t()
,Date.t()
andNaiveDateTime.t()
. This means that typespecs of the following functions don't correspond to what they actually support:Timex.Format.DateTime.Formatters.Relative.format/2
Timex.Format.DateTime.Formatters.Relative.format!/2
Timex.Format.DateTime.Formatters.Relative.lformat/3
Timex.Format.DateTime.Formatters.Relative.lformat!/3
The errors seen above in
Steps to reproduce
are caused by a call toTimex.Protocol.to_naive_datetime/1
(which is referenced by bothTimex.Format.DateTime.Formatters.Relative.lformat/3
andTimex.Format.DateTime.Formatters.Relative.relative_to/4
) because the protocol is not implemented forTime
.Ways to solve
Option 1:
Time.t()
from the typespecsTime
from the guard inTimex.Format.DateTime.Formatter.lformat/3
such that the function call instead returns{:error, :invalid_date}
when aTime
-struct is passedOption 2:
Time.t()
I would expect such support to act like the behaviour of a passed 'today'-value of type
DateTime
orNaiveDateTime
, i.e. returning values such as{:ok, "8 hours ago"}
or{:ok, "in 1 hour"}
.I'm not sure if it makes sense to implement
Timex.Protocol
forTime
since a lot of the functions are date-related, so maybe it makes sense to instead make a separate clause ofTimex.Format.DateTime.Formatters.Relative.lformat/3
which handlesTime
just slightly differently to howDate
,DateTime
andNaiveDateTime
are handled.(Very similar function clause, but call
do_format/5
with the passedTime
-struct andTime.utc_now()
instead ofTimex.Protocol.to_naive_datetime(date)
andTimex.Protocol.now()
?)The text was updated successfully, but these errors were encountered: