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. 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

sergio
In Ruby, I can go: User.find_by(email: "foobar@email.com").update(email: "hello@email.com") How can I do something similar in Elixir? ...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
Fl4m3Ph03n1x
Background Let’s assume I have a typical GenServer that receives messages as requests, does some operation in a DB and returns responses....
New
mathew4509
I have a list say x = ["23gh", "56kh", "97mh"] I would like to pass each element to Val in each iteration. Say, in iteration 1 -------...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
New

Other popular topics Top

chrismccord
Phoenix 1.4.0 released Phoenix 1.4 is out! This release ships with exciting new features, most notably with HTTP2 support, improved deve...
688 30048 115
New
AstonJ
You’re a programmer, so you don’t need spoon feeding with the conventional drivel about “this is an integer.” No. You need to know what’s...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 49522 488
New
fireproofsocks
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New

We're in Beta

About us Mission Statement