trisolaran

trisolaran

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

Showing Posts 1 to 7

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 OP

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!

LostKobrakai

LostKobrakai

Totally agree. Though even then there’s the question if it works only for english input (e.g. month names) or if the language can be configured, should it attempt to guess the language out of multiple configured ones, …

Marcus

Marcus

A DateTimeParser without a predefined format is also available, see DateTimeParser - Parse DateTime, NaiveDateTime, Time, or Date from strings

trisolaran

trisolaran OP

well we could say: if it’s not supported when formatting, then it’s not going to be supported when parsing either.

LostKobrakai

LostKobrakai

Localization is supported for formatting via the options passed in.

trisolaran

trisolaran OP

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.

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews