I'm not 100% convinced about the sigil since it would only work with UTC.
What I would love to see, however, is an Inspect implementation for DateTime. 
The structs are extremely hard to read and see what's happening. Even having a 
simple inspect implementation should make it much easier.

Michał.

On 27 Jun 2017, 16:29 +0200, Wojtek Mach <[email protected]>, wrote:
> I think that'd be a nice addition. Even if it does not eventually land in 
> Elixir, anyone can define the `~Z` (or whatever) sigil just for tests as 
> shown at the end of the post.
>
> I usually deal with just `NaiveDateTime`s but on the rare occasion that I 
> used `DateTime` not having the sigil wasn't as bad as the incredibly verbose 
> inspect output of DateTime's (the whole struct). Thus, if there was an 
> unambiguous text representation (that contains timezone) which could be used 
> in both the sigil and inspect, I think that would be a great addition to the 
> language. While inspect could handle any struct (assuming it was correctly 
> constructed, leaving this to the developer), sigil probably would only work 
> for Etc/UTC, until Elixir ships with tzdata.
>
> defmodule FooCase do
>   use ExUnit.CaseTemplate
>
>   using do
>     quote do
>       def sigil_Z(binary, _opts) do
>         {:ok, datetime, 0} = DateTime.from_iso8601(binary)
>         datetime
>       end
>     end
>   end
> end
>
>
> defmodule FooTest do
>   use FooCase
>
>
>   test "the truth" do
>     assert ~Z[2015-01-23T23:50:07Z] == 
> DateTime.from_naive!(~N[2015-01-23T23:50:07], "Etc/UTC")
>   end
> end
>
> W dniu wtorek, 27 czerwca 2017 04:05:49 UTC+2 użytkownik Gregory McIntyre 
> napisał:
> > Love Elixir! So good!
> >
> > Recently we found ourselves writing a lot of DateTime literals to feed into 
> > our unit tests like this:
> >
> > DateTime.from_naive!(~N[2016-05-05 01:01:42], "Etc/UTC")
> >
> > Is there a simpler way to specify human readable timestamp literals in 
> > code? Could there be? I'm not sure what the best sigil would be, but 
> > something like this?
> >
> > ~Z[2016-05-05T01:01:42Z]
> >
> > (That is ISO 8601 format.)
> >
> > Love and peace and many thanks,
> > Greg
> >
> --
> 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 [email protected].
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/elixir-lang-core/d59e56aa-dde9-426b-9303-a62f2576e396%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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elixir-lang-core/dab16d14-f52c-487e-a0bb-2e924a0e40cb%40Spark.
For more options, visit https://groups.google.com/d/optout.

Reply via email to