unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* The wild and weird world of Emacs Lisp date/time arithmetic
@ 2020-12-17 15:57 Skip Montanaro
  2020-12-17 19:23 ` Christopher Dimech
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Skip Montanaro @ 2020-12-17 15:57 UTC (permalink / raw)
  To: Help GNU Emacs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2020-12-18 15:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-12-17 15:57 The wild and weird world of Emacs Lisp date/time arithmetic Skip Montanaro
2020-12-17 19:23 ` Christopher Dimech
2020-12-17 19:47 ` Teemu Likonen
2020-12-17 19:59   ` Teemu Likonen
2020-12-17 20:04   ` Skip Montanaro
2020-12-17 20:35     ` Stefan Möding
2020-12-17 20:51       ` Skip Montanaro
2020-12-18 15:37 ` Emanuel Berg via Users list for the GNU Emacs text editor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).