1

I have a text file (Markdown, actually, but close enough) with dates in a slightly annoying US format %m/%d/%Y. I'd like it to be in ISO-8601 format everywhere throughout.

I could easily write a 5-10 line script to do this specific conversion, but it feels like the sort of thing someone has written a more complete version of already. I just don't know what this hypothetical tool is called.

My imagined tool would take arbitrary formats for input and output (but from the world of datetime formats), although maybe with shortcuts for common ones. Basically, a datetime-aware sed is what I would want. So I might run, e.g.:

$ datecvt -i US -o ISO8601 < myfile.txt > gooddates.txt
$ # ... or ...
$ datecvt -i '%m/%d/%Y' -o '%Y-%m-%d' --inplace myfile.txt

Perhaps slightly different usage syntax, but that sort of thing. Does it exist? (for OSX, but almost all Linux-oriented tools can be compiled, and have been with Homebrew).

  • if you know javascript then time.js or moment.js might work – onurcano Dec 31 '18 at 21:32
  • I know how to do the task in various programming languages. What I hoped for was a command-line utility to do it. I decided to try to write a "moderately good" version in Julia. Not because it's necessarily the best language to choose, but simply because I wanted to play with the language. I'm sure this early attempt is not idiomatic or optimal, but it does basically the goal: gist.github.com/DavidMertz/447661d67f7b3f5ffa3c23d56f3b7294 – David Mertz Jan 2 at 16:53
1

I know how to do the task in various programming languages. What I hoped for was a command-line utility to do it. I decided to try to write a "moderately good" version in Julia. Not because it's necessarily the best language to choose (startup time is terrible), but simply because I wanted to play with the language. I'm sure this early attempt is not idiomatic or optimal, but it does basically the goal:

gist.github.com/DavidMertz/447661d67f7b3f5ffa3c23d56f3b7294

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.