[Proposal] DateTime.to_utc/1

43 views
Skip to first unread message

thojan...@gmail.com

unread,
Jan 14, 2021, 8:37:30 AM1/14/21
to elixir-lang-core
What do you think of adding a convenience function:
`DateTime.to_utc(dt)`

Which would be a shortcut for:
`DateTime.shift_zone!(dt, "Etc/UTC")`

As converting back to UTC might be a common need for some applications, and writing systematically "Etc/UTC" is a bit ugly.

Zubair

unread,
Jan 14, 2021, 2:03:13 PM1/14/21
to elixir-lang-core
If the same thing is achievable which is a single line of code, I don't think it would be appropriate. It can be easily achieved by  `DateTime.shift_zone!(dt, "Etc/UTC")` 

thojan...@gmail.com

unread,
Jan 15, 2021, 7:03:13 AM1/15/21
to elixir-lang-core
We already have `DateTime.utc_now()` as a shortcut for `DateTime.now("Etc/UTC")`. So it would make sense to add `to_utc/1` as a convenience function as well here.
Reply all
Reply to author
Forward
0 new messages