Extend Date/Time sigils to allow `now` with a truncation modifier

62 views
Skip to first unread message

Aleksei Matiushkin

unread,
Mar 30, 2021, 2:54:30 AM3/30/21
to elixir-lang-core
Hello,

I often find myself writing `DateTime.truncate(DateTime.utc_now(), :second)` or similar stuff to get to the ‘instance’ of now.

What if we have sigils `~U`, `~D`, and `~T` extended to:

~U[now] → DateTime.utc_now()
~T[now] → Time.utc_now()
~D[today] → Date.utc_today() 

with possible modifiers `s` and `m` to truncate times to seconds and milliseconds respectively?

~U[now]s → DateTime.truncate(DateTime.utc_now(), :second)

Here is the PR with the code for the reference https://github.com/elixir-lang/elixir/pull/10840 (it uses empty sigils instead of ~U[now])

esurk....@gmail.com

unread,
Mar 30, 2021, 4:31:46 AM3/30/21
to elixir-lang-core
For me, it breaks the semantic of a sigil. I think of a sigil as a text representation of data, and your proposal is a text representation of a function call. In the end, every sigil triggers a function. But I think this should be a pure function.

Aleksei Matiushkin

unread,
Mar 30, 2021, 9:51:25 AM3/30/21
to elixir-l...@googlegroups.com
Technically, lowercased sigils are not pure as well.

--
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/42a4b61b-4bae-475f-885b-974881ea0ebbn%40googlegroups.com.


--

Aleksei MatiushkinSoftware Engineer - R&D
 
Office    (+34) 935 679 834 - Ext. 
 

8 Devonshire Square, London, EC2M 4PL, United Kingdom
Torre Mapfre, Planta 22, Marina, 16-18, 08005 Barcelona, Spain

 

LinkedIn    Twitter    YouTube
 
Kantox Limited is a UK private company with registered company number 07657495 and registered address at 8 Devonshire Square, London EC2M 4PL, United Kingdom. We are authorised with the UK Financial Conduct Authority (FCA) under the Payment Service Website 2017 as a Payments Institution (FRN 580343) for the provision of payment services and with HMRC as a Money Service Business Registration No.12641987.
Kantox European Union, S.L.  is a Spanish private company with tax ID number B673693371 and registered address at Torre Mapfre, Planta 22, Marina, 16-18, 08005 Barcelona, Spain. Kantox is authorized by the Bank of Spain, with registration number 6890, which is the supervisor of the Spanish banking system along with the European Central Bank. Additionally, we are supervised by SEPBLAC, the Supervisory Authority for the prevention of money laundering and terrorist financing in Spain.
KANTOX is the Controller for the processing of data in accordance with the GDPR and LOPDGDD for the purpose of maintaining a commercial relationship. You may exercise your rights of access and rectification, portability, restriction and opposition by writing to KANTOX to the email: gd...@kantox.com. You have your right to make a complaint at www.aepd.es.  
Reply all
Reply to author
Forward
0 new messages