trisolaran

trisolaran

Why does the Calendar module have a strftime function but no strptime function?

Hi!

The calendar module has had the time formatting function strftime/3 for a while now, which is very useful. However, if a want to parse a time string according to a given format, I still have to resort to external libraries and for example use Timex.parse/2 and friends.

Why doesn’t the module have a strptime function (strptime(3) - Linux manual page) ? Is this still work in progress or not planned for some reason?

Thanks

Most Liked

LostKobrakai

LostKobrakai

Calendar functionalty has been added piece by piece to elixir core. Parsing is the last larger piece still missing, but also I feel like the one most tricky to get right. Andrea Leopardi recently did a few PRs to GitHub - hrzndhrn/datix: A date-time parser using `Calendar.strftime` format strings. · GitHub and I’ve heard Jose talk about it (iirc in one of the podcasts with thinking elixir), so it’s certainly on their mind.

Until then I’d just pull in datix for parsing tasks. There’s now a handful of smaller libraries, which just do a subset of datetime handling, so there’s no need to pull in the large timex library.

trisolaran

trisolaran

Thanks @LostKobrakai

It’s not immediately clear to me while parsing would be considerably more difficult than formatting, but I’m sure the devil is, as usual, in the details :slight_smile:

Thanks for pointing me to Datix and the other libraries. Currently I’m using Timex only for parsing so this sounds like a good way to replace it with a more lightweight library :+1:

I think I know which podcast episode you’re referring to. IIRC they were talking about a parsing functionality similar to some “magic” function in Rails (I believe it was this one) which tries to make sense of any time string without a predefined format. They were saying that this isn’t generally a good idea (I agree) and that something similar will likely not make it into Elixir. However, parsing from a specified format is a completely different story and something I think should make it into the core library at some point, so that’s why I asked the question.

Good to know this is in the making!

trisolaran

trisolaran

yeah my point was only that if I had to write the strptime function I would design it as the exact counterpart of strftime. So if strftime accepts localization options like :month_names and Co, strptime should do the same but not attempt to do anything more sophisticated.

Where Next?

Popular in Questions Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New

Other popular topics Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 54921 245
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
axelson
This post is a wiki (feel free to hit the edit button near the bottom right of this post to add your own changes!) This post collects co...
239 49084 226
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

We're in Beta

About us Mission Statement