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

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

Re: even elder races get tired of waiting


From: Jean Louis
Subject: Re: even elder races get tired of waiting
Date: Mon, 22 Mar 2021 10:54:21 +0300
User-agent: Mutt/2.0.6 (2021-03-06)

* Jude DaShiell <jdashiel@panix.com> [2021-03-21 22:24]:
> Use of cal with a month number and a year number to get a weekday of a
> particular date can make work a little easier.

How to do that?

> This is for really long time periods and only inside the gregorian calendar
> constraints since outside of those constraints things get really wild as a
> result of compound errors.
> With that weekday in mind subtracting a year when you won't land in a leap
> year or adding a year when you won't land in a leap year, subtract or add
> one weekday to get the correct weekday for that date in those years.  If you
> will land in a leap year, subtract or add two weekdays to get the correct
> weekday.  Modulus the weekday by 7 to keep it in whichever range you prefer
> to use..

I would like to use Emacs functions to calculate the new DATE after
SOME NUMBER OF DAYS from STARTING DATE.

For leap years it looks like PostgreSQL isdoing it right:

(defun days-from (from-date to-date)
  "Returns days passed from FROM-DATE to TO-DATE in format YYYY-MM-DD."
  (string-to-number
   (string-trim
    (shell-command-to-string
     (format "psql -Aqtc \"SELECT abs('%s'::date - '%s'::date)\"" to-date 
from-date)))))

(days-from "2020-02-28" "2020-03-01") => 2
(days-from "2021-02-28" "2021-03-01") => 1 



reply via email to

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