For anyone interested, I've implemented the ~Z sigil to experiment with in 
a personal 
project: https://gist.github.com/wojtekmach/b66d1bd1eadf17cc57f7ae64f0f6d4b1
This allows me to do:

$ iex -S mix
iex(1)> DateTime.utc_now
~Z[2017-09-08 21:04:17.404239]
iex(2)> Calendar.DateTime.shift_zone!(~Z[2017-09-08 21:04:17.404239], 
"America/New_York")
#DateTime<2017-09-08 17:04:17.404239-04:00 EDT America/New_York>


The Code.compiler_options.ignore_module_conflict is obviously a hack, so 
looking forward to hearing if it's a big no-no :)


W dniu wtorek, 27 czerwca 2017 16:49:41 UTC+2 użytkownik Wojtek Mach 
napisał:
>
> There's DateTime.to_string/1 which seems perfect to use, I'm looking into 
> it:
>
> iex(1)> DateTime.utc_now
> #DateTime<2017-06-27 14:46:54.331343Z>
>
> iex(3)> %DateTime{year: 2000, month: 2, day: 29, zone_abbr: "CET", hour: 
> 23, minute: 0, second: 7, microsecond: {0, 0}, utc_offset: 3600, 
> std_offset: 0, time_zone: "Europe/Warsaw"}
> #DateTime<2000-02-29 23:00:07+01:00 CET Europe/Warsaw>
>
>
> W dniu wtorek, 27 czerwca 2017 16:40:12 UTC+2 użytkownik Michał Muskała 
> napisał:
>>
>> 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 <woj...@wojtekmach.pl>, 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 elixir-lang-co...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/elixir-lang-core/d59e56aa-dde9-426b-9303-a62f2576e396%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/elixir-lang-core/d59e56aa-dde9-426b-9303-a62f2576e396%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> 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/a530322b-a0a4-4696-b697-f485b5d7682f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to