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: Christopher Dimech
Subject: Re: The wild and weird world of Emacs Lisp date/time arithmetic
Date: Thu, 17 Dec 2020 20:23:53 +0100

> Sent: Thursday, December 17, 2020 at 4:57 PM
> From: "Skip Montanaro" <skip.montanaro@gmail.com>
> To: "Help GNU Emacs" <help-gnu-emacs@gnu.org>
> Subject: The wild and weird world of Emacs Lisp date/time arithmetic
>
> I have a very simple date calculation. I have a CSV file whose first field
> is an ISO-8601 date, for example:
>
> 2020-12-03,738050,2262878,0.33
>
> I want to write a function to add a day and append a new (empty) record.
> The end result should look like this:
>
> 2020-12-03,738050,2262878,0.33
> 2020-12-04
>
> Easy peasy, right? I have no problem plucking the time out of the buffer or
> decoding the string. I'm having trouble converting back to string form
> after parsing and doing the arithmetic. It seems to me that there are a
> myriad number of datetime representations. I would have thought (based on
> their names) that parse-time-string and format-time-string were
> complementary functions, but they are not. This raises an exception:
>
> (format-time-string "%Y-%m-%d" (parse-time-string "2020-05-17"))
>
> So, given a timestamp as returned from (parse-time-string), how does one
> format it for display? More concretely, I would like the return value from
> this function:
>
> (defun dt-convert ()
>   (setq this-date (parse-time-string "2020-05-17"))
>   (setq one-day (make-decoded-time :day 1))
>   (setq next-date (decoded-time-add this-date one-day))
>   (format-time-string "%Y-%m-%d" next-date)
>   )
>
> to be "2020-05-18".
>
> Completely perplexed...
>
> Skip Montanaro


I have had a similar experience working with dates.  It is problematic.




reply via email to

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