Script to normalize date-time strings from the clipboard
I wanted to copy some metadata of a Tweet the other day to cite a person in a Zettel. My computer language is set to English, so I get am/pm times. Of course all I care about are ISO-formatted date and time strings!
So I wondered how bad it'd be to use a natural language parser for the dates in a script. The popular "chronic" Ruby gem didn't recognize the format. With the "timeliness" Ruby gem, I was able to specify the format, but where's the fun in that?
require "timeliness" Timeliness.parse("1:51 PM - 12 Apr 2019", format: "h:nn_ampm - dd mmm yyyy") # => 2019-04-12 13:51:00 +0200
Turns out nickel is very good at parsing U.S. Twitter dates:
require "nickel" Nickel.parse("1:51 PM - 12 Apr 2019").occurrences.start_time.to_time # => 2019-06-21 13:51:00 +0200
It's a bit clunky to use as a oneliner, but wrapped in a Keyboard Maestro or Alfred action or Quicksilver action or Automator workflow, I think this is pretty useful. You should be able to change the output format, but I like the default.
How do you automate stuff like that?
Author at Zettelkasten.de • http://christiantietze.de/
It looks like you're new here. If you want to get involved, click one of these buttons!