unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Christopher Dimech <dimech@gmx.com>
To: Skip Montanaro <skip.montanaro@gmail.com>
Cc: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: Re: The wild and weird world of Emacs Lisp date/time arithmetic
Date: Thu, 17 Dec 2020 20:23:53 +0100	[thread overview]
Message-ID: <trinity-11248b69-183e-45ba-a9ae-c167b5d33e96-1608233033000@3c-app-mailcom-bs11> (raw)
In-Reply-To: <CANc-5Uwbq-bs2xjBw4wvNDNZm0xo0BR0mkMramWqfYVm3GcPyQ@mail.gmail.com>

> 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	other threads:[~2020-12-17 19:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=trinity-11248b69-183e-45ba-a9ae-c167b5d33e96-1608233033000@3c-app-mailcom-bs11 \
    --to=dimech@gmx.com \
    --cc=help-gnu-emacs@gnu.org \
    --cc=skip.montanaro@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).