2

I use Emacs (Spacemacs) for email, and one of the most common tasks I have is converting an email containing a date and time to an item in my schedule. I noticed that calendar mode can convert certain expressions to timestamps, like "+7" for "seven days from now,"

But is there something that handles fuzzier text, like "Thursday, 4 February, at 6pm"?

If there isn't, does anyone know of something that can do this in any other language (that would be usable through Emacs)?

  • There is 'math-parse-date' from the calc package which is not too bad. It parses "Thursday, 4 February 6pm" but not "Thursday, 4 February, at 6pm". – Marco Wahl Feb 4 at 2:20
4

org-read-date can handle a certain amount of fuzziness, e.g.

'22 sept 0:34’  ⇒ 2006-09-22 0:34
‘w4’    ⇒ ISO week for of the current year 2006
‘2012 w4 fri’   ⇒ Friday of ISO week 4 in 2012
‘2012-w04-5’    ⇒ Same as above

See Org Mode date/time prompt for the gory details.

  • Good to know. Kinda too bad it's buried in Org. Doesn't sound like something that is (should be) specific to Org. – Drew Feb 5 at 14:58
  • 1
    Emacs ships with Org these days, so it's not too hard to use. – rpluim Feb 5 at 15:22
  • 1
    That's irrelevant. If it is not Org-specific but generally useful then it should probably be moved out of org. No reason for prefix org-, in particular, in that case. – Drew Feb 5 at 19:32
1
(setq cur   (current-time)) ; ==> (23636 51255 362090 0)
(setq strg  (format-time-string "%c" cur)) ; ==> "2/1/2019 2:29:11 PM"

See the Elisp manual, nodes Time of Day and Time Parsing. See also node Time Conversion.

See also standard library time-date.el. Some functions defined there convert between Emacs time representations and human-readable strings - e.g. date-to-time.

But no, I don't know of something that will interpret any old natural language way of writing a time+date. If you know the time then you can create a time object from its components using encode-time. If you have an Emacs time object then you can express it using a wide variety of standard string formats. But interpreting an arbitrary time-date-like string? Nope; not that I know of.

  • 1
    This seems like a way to go from a machine-readable time object to a human-readable time format. But I want to go from the human-readable time format ("next Tuesday," "the twelfth of March," "later this afternoon") and make a machine-readable time object from it, not the other way around. – Jonathan Feb 3 at 16:27
  • Please read what I wrote in the second paragraph. "I don't know of something that will interpret any old natural language way of writing a time+date." Maybe someone else does. There are an infinite number of reasonable natural-language ways of writing a time and date. Certainly someone could, and someone may have, written code that handles some of them, including, say, "third Monday following the 2nd full moon after Easter". (Incidentally, check out the Emacs code in holidays.el for the algorithm that determines the date of Easter.) – Drew Feb 3 at 22:01
  • So, your answer is that you don't know? – Jonathan Feb 5 at 15:29
  • My answer is what I wrote. It's what I was aware of; it's the standard Elisp documentation that covers such things, and I hoped it might help you. Will you be specifying just what you mean by "handles fuzzier text"? There are any number of kinds of date/time fuzzy expressions. What I posted can help with many string formats, including ISO dates & times. But no, it's not a general answer for whatever fuzziness you might have in mind. – Drew Feb 5 at 19:38
  • Maybe next time don't answer if you don't actually have an answer. Frankly, it's not very helpful to post irrelevant code, irrelevant manual pages, and lengthy explanations of why and how you don't have an actual answer. – Jonathan Feb 10 at 3:28

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.