all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* How to: 96 bit Date-time arithmetic?
@ 2002-08-31 15:39 Siegfried Heintze
  2002-08-31 18:21 ` Siegfried Heintze
  2002-09-04  7:57 ` Christian Lemburg
  0 siblings, 2 replies; 5+ messages in thread
From: Siegfried Heintze @ 2002-08-31 15:39 UTC (permalink / raw)


How do I add delta times and subtract absolute times stored in the 96 bit (3
integer) format? Apparently the functions encode and decode will help me
convert to and from the 96 bit time format.

I want to increment times by 1 day and have emacs properly figure out when
there is a Feb 28.

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

* Re: How to: 96 bit Date-time arithmetic?
  2002-08-31 15:39 How to: 96 bit Date-time arithmetic? Siegfried Heintze
@ 2002-08-31 18:21 ` Siegfried Heintze
  2002-08-31 20:49   ` lawrence mitchell
  2002-09-04  7:57 ` Christian Lemburg
  1 sibling, 1 reply; 5+ messages in thread
From: Siegfried Heintze @ 2002-08-31 18:21 UTC (permalink / raw)


While I am still curious about 96 bit arithmetic, here an alternative
attempt. Why does not it work?

(setq x (decode-time (current-time)))
(setq y (list (car x) (cadr x)  (caddr x) (1- (cadddr x))
       (nth 5 x) (nth 6 x) (nth 7 x)(nth 8 x) ))
(apply 'encode-time x) ; no error

(apply 'encode-time y) ; error -- why?

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

* Re: How to: 96 bit Date-time arithmetic?
  2002-08-31 18:21 ` Siegfried Heintze
@ 2002-08-31 20:49   ` lawrence mitchell
  0 siblings, 0 replies; 5+ messages in thread
From: lawrence mitchell @ 2002-08-31 20:49 UTC (permalink / raw)


Siegfried Heintze wrote:

> While I am still curious about 96 bit arithmetic, here an alternative
> attempt. Why does not it work?

> (setq x (decode-time (current-time)))
> (setq y (list (car x) (cadr x)  (caddr x) (1- (cadddr x))
>        (nth 5 x) (nth 6 x) (nth 7 x)(nth 8 x) ))
       ^ (nth 4 x)
> (apply 'encode-time x) ; no error

> (apply 'encode-time y) ; error -- why?

in `nth', N counts from zero.

Hence you want (nth 4 x) before (nth 5 x)
Notice that:

(length x)
    => 9
(length y)
    => 8

I'd probably do
(setcar (nthcdr 3 x) (1- (nth 3 x)))
instead, as it's somewhat easier to read.

On another note of style, you probably don't want to use setq
unless you've already bound x in a `let' form, or x is indeed a
global variable. e.g.
(let ((x (decode-time (current-time))))
  (setcar (nthcdr 3 x) (1- (nth 3 x)))
  x)
To return the modified value of x.
-- 
lawrence mitchell <wence@gmx.li>

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

* Re: How to: 96 bit Date-time arithmetic?
  2002-08-31 15:39 How to: 96 bit Date-time arithmetic? Siegfried Heintze
  2002-08-31 18:21 ` Siegfried Heintze
@ 2002-09-04  7:57 ` Christian Lemburg
  2002-09-04 13:58   ` Alan Shutko
  1 sibling, 1 reply; 5+ messages in thread
From: Christian Lemburg @ 2002-09-04  7:57 UTC (permalink / raw)


"Siegfried Heintze" <siegfried@heintze.com> writes:

> How do I add delta times and subtract absolute times stored in the 96 bit (3
> integer) format? Apparently the functions encode and decode will help me
> convert to and from the 96 bit time format.
> 
> I want to increment times by 1 day and have emacs properly figure out when
> there is a Feb 28.


(defun my-emacs-time->seconds (time)
  "Convert emacs time format to seconds as one 32 bit integer."
  (let ((high (lsh (car time) 16))
	(low (cadr time)))
    (logior high low)))

(defun my-seconds->emacs-time (time)
  "Convert one 32 bit integer to emacs time format."
  (list (lsh time -16) (logand time (1- (lsh 1 16))) 0))


-- 
Christian Lemburg, <lemburg@aixonix.de>, http://www.clemburg.com/
 Hand, n.:
 	A singular instrument worn at the end of a human arm and
 commonly thrust into somebody's pocket.
 		-- Ambrose Bierce, "The Devil's Dictionary"

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

* Re: How to: 96 bit Date-time arithmetic?
  2002-09-04  7:57 ` Christian Lemburg
@ 2002-09-04 13:58   ` Alan Shutko
  0 siblings, 0 replies; 5+ messages in thread
From: Alan Shutko @ 2002-09-04 13:58 UTC (permalink / raw)


Christian Lemburg <lemburg@aixonix.de> writes:

>   "Convert emacs time format to seconds as one 32 bit integer."

It should be noted that integers are only 32-bit on 64-bit
platforms.  On most platforms, integers are 28-bit.

It's probably better to use time-add from time-date.el (included in
Gnus and thus in Emacs).

-- 
Alan Shutko <ats@acm.org> - In a variety of flavors!
They can't get rid of Morn before he speaks!!!!

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

end of thread, other threads:[~2002-09-04 13:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-08-31 15:39 How to: 96 bit Date-time arithmetic? Siegfried Heintze
2002-08-31 18:21 ` Siegfried Heintze
2002-08-31 20:49   ` lawrence mitchell
2002-09-04  7:57 ` Christian Lemburg
2002-09-04 13:58   ` Alan Shutko

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.