We don't drop the offset information in the suggested implementation. And
pattern matching on {datetime, offset} instead of {:ok, datetime, offset}
still has the benefit that it *has* to match otherwise a *nice* error is
returned (which doesn't happen if you match on {:ok, datetime, offset} and
get a MatchError).

Andrea Leopardi
an.leopa...@gmail.com


On Wed, Jun 19, 2019 at 10:40 AM Fernando Tapia Rico <fertap...@gmail.com>
wrote:

> This has been suggested in the past. For example
> https://github.com/elixir-lang/elixir/pull/6514
>
> The main reason why there is not a bang variant is because the `offset`
> information would be dropped.
>
> On Wednesday, June 19, 2019 at 10:13:39 AM UTC+2, Andrea Leopardi wrote:
> > I can't see a reason why not to add this. I think a PR would be welcome!
> >
> >
> >
> >
> >
> > Andrea Leopardi
> > an.le...@gmail.com
> >
> >
> >
> > On Mon, Jun 17, 2019 at 4:31 PM Mário Guimarães <mario.lui...@gmail.com>
> wrote:
> >
> > The proposed function could be implemented like this
> >
> >
> >
> >
> >   def from_iso8601!(string, calendar \\ Calendar.ISO) do
> >     case DateTime.from_iso8601(string, calendar) do
> >       {:ok, datetime, offset} ->
> >         {datetime, offset}
> >
> >       {:error, reason} ->
> >         raise ArgumentError,
> >               "cannot convert #{string} to datetime, reason:
> #{inspect(reason)}"
> >     end
> >   end
> >
> >
> >
> >
> > segunda-feira, 17 de Junho de 2019 às 15:18:29 UTC+1, Mário Guimarães
> escreveu:
> > Hello,
> >
> >
> > all "from_x" functions in DateTime support their throw exception
> version, but the function "from_iso8601/2" which returns an error tuple.
> >
> >
> > Doesn't it make sense, because of convenience and completeness, to
> provide a bang version of this function?
> >
> >
> > See https://hexdocs.pm/elixir/DateTime.html#from_iso8601/2
> >
> >
> > Thanks
> > Mário
> >
> >
> >
> >
> > --
> >
> > You received this message because you are subscribed to the Google
> Groups "elixir-lang-core" group.
> >
> > To unsubscribe from this group and stop receiving emails from it, send
> an email to elixir-l...@googlegroups.com.
> >
> > To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/1b2ea98e-24b0-4829-8943-82ca3add955c%40googlegroups.com
> .
> >
> > For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups
> "elixir-lang-core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to elixir-lang-core+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elixir-lang-core/f8d56771-d618-4ece-be85-4f4f740fe928%40googlegroups.com
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to elixir-lang-core+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/CAM9Rf%2BJn2ky5kgaExDz0kwgpv3ez0qZTMNpPqqkv_CHXN_Q9SQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to