Subject: Re: Lisp Date arithmetic library From: Erik Naggum <firstname.lastname@example.org> Date: Tue, 25 Jun 2002 21:23:50 GMT Newsgroups: comp.lang.lisp Message-ID: <email@example.com> * Bruce Lester | I am looking for Lisp code to calculate and format date values in a variety | of formats. Does anyone have suggestions on where I might look for this? It is actually too simple. First you have to forget tiemzones, because they do not generally work, not even your local one, since Common Lisp does not interface to your operating system's timezone database in any standard way and many implementations are severely confused outside the state where its authors live. That makes the whole problem a lot simpler than it really is, so you are relieved of lots of minor problems. Then you just use decoded-universal-time and bind the values like this: (multiple-value-bind (ss mm hh d m y dow dst zone) (decode-universal-time X) ...) Now, the _only_ correct way to print a date is this: (format <stream> "~4,'0D-~2,'0D-~2,'0D" y m d) and the _only_ correct way to print a time is this: (format <stream "~2,'0D:~2,'0D:~2,'0D" hh mm ss) and if you have to write both in a row, use a space or a T between them. Drop the "culturally correct" ways to write dates and times and just get with the program. Just like floating point numbers are _not_ written with a stupid decimal comma, and times of day are _not_ written in some ancient 12-hours system, nor with hour, minute, second in any other order, you write year, month, and day of month in that order. No variation, no need to do it abstractly, just do it right. http://www.naggum.no/lugm-time.html (or .ps) might still be worth a read. If you need to compute with days, remember that (floor <universal-time> 86400) always decomposes into a day since 1900-01-01 and the seconds the start of the current day. There are exactly 86400 seconds in a day, all year round. -- Guide to non-spammers: If you want to send me a business proposal, please be specific and do not put "business proposal" in the Subject header. If it is urgent, do not use the word "urgent". If you need an immediate answer, give me a reason, do not shout "for your immediate attention". Thank you.