help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The wild and weird world of Emacs Lisp date/time arithmetic


From: Skip Montanaro
Subject: Re: The wild and weird world of Emacs Lisp date/time arithmetic
Date: Thu, 17 Dec 2020 14:04:54 -0600

> You can do it with a function like this:
>
>     (defun my-add-one-day (date-string)
>       (let ((decoded (decoded-time-add (parse-time-string date-string)
>                                        (make-decoded-time :day 1))))
>         (format "%04d-%02d-%02d"
>                 (nth 5 decoded)
>                 (nth 4 decoded)
>                 (nth 3 decoded))))
>
> (my-add-one-day "2020-12-31") ;=> "2021-01-01"
>

Thanks. That isn't a problem in my case as my output format is dead simple.
Still, it seems there should be an inverse to parse-time-string which
consumes a format string and one of those n-element lists. I'm thinking in
terms of C stdio functions strptime and strftime, or the methods of the
same name for Python's datetime objects. That's what fooled me about the
format-time-string function. Its name implies that it would consume the
output of parse-time-string but it doesn't.

Skip


reply via email to

[Prev in Thread] Current Thread [Next in Thread]