From: budden
Subject: Date and time again
Date: 
Message-ID: <943f55af-59a8-461d-8afc-a3757de8a573@i6g2000yqj.googlegroups.com>
Dear lisper(s)!
  What date/time library do you use? Are you satisfied?

From: budden
Subject: Re: Date and time again
Date: 
Message-ID: <b94642e0-6b1a-4990-bd75-41ca8f062134@c36g2000yqn.googlegroups.com>
I see. Noone uses date/time :) Thanks for your replies. I will
intensify my move to Python.

E.g. consider the task of calculating date which is weak ahead of
today.
In Python it is:
>>> import datetime as dt # local package aliases are unavailable in CL still
>>> dt.date.today()+dt.timedelta(7)
datetime.date(2009, 6, 30)

Note there is a reasonable default date representation. No such
one in CL.

Also, it required some experiments to learn that undocumented
function local-time:timestamp+ could do the same job in CL:

> (local-time:timestamp+ (local-time:now) 7 :day)
09-06-30T13:50:49.00
From: TomSW
Subject: Re: Date and time again
Date: 
Message-ID: <ca9e0974-7857-453f-a561-a214c329be9f@m19g2000yqk.googlegroups.com>
On Jun 23, 11:53 am, budden <···········@mail.ru> wrote:
> I see. Noone uses date/time :) Thanks for your replies. I will
> intensify my move to Python.

Is that a threat? - as a favourite cll poster would say :)

> Also, it required some experiments to learn that undocumented
> function local-time:timestamp+ could do the same job in CL:

It is documented - http://common-lisp.net/project/local-time/manual.html/time.
There's also the date-calc package, which is documented here:
http://common-lisp.net/project/cl-date-calc/

Coincidentally or not, the local-time package was inspired by Eric
Naggum.

cheers,
Tom SW
From: budden
Subject: Re: Date and time again
Date: 
Message-ID: <cd318037-cbc9-4a89-92be-bc613f57b7bd@k8g2000yqn.googlegroups.com>
> > Also, it required some experiments to learn that undocumented
> > function local-time:timestamp+ could do the same job in CL:
> It is documented -http://common-lisp.net/project/local-time/manual.html/time.
Thanks. My fault. I mean it has no docstring.

> There's also the date-calc package, which is documented here:http://common-lisp.net/project/cl-date-calc/
Yes, I found it too. What I expected to read was lispers opinions of
their experience using either or both
of them and which is better in their opinion.

> Does something like this can do what you want?
> (defun +day (day)
>   (encode-universal-time 0 0 0 day 1 1900 0))
> ...
> Can't you build what you want from *-time functions?
I asked to add 7 days just for the example. Date/time management is
far from being trivial and significant
effort is required to build everything I need from the scratch. Local-
time itself has a source size of
70 Kbytes. So this is not an option :)
From: Philippe Brochard
Subject: Re: Date and time again
Date: 
Message-ID: <87prcvdy92.fsf@grigri.elcforest>
budden writes:

> I see. Noone uses date/time :) Thanks for your replies. I will
> intensify my move to Python.
>
> E.g. consider the task of calculating date which is weak ahead of
> today.
> In Python it is:
>>>> import datetime as dt # local package aliases are unavailable in CL still
>>>> dt.date.today()+dt.timedelta(7)
> datetime.date(2009, 6, 30)
>
> Note there is a reasonable default date representation. No such
> one in CL.
>
> Also, it required some experiments to learn that undocumented
> function local-time:timestamp+ could do the same job in CL:
>
>> (local-time:timestamp+ (local-time:now) 7 :day)
> 09-06-30T13:50:49.00
>
Does something like this can do what you want?

(defun +day (day)
  (encode-universal-time 0 0 0 day 1 1900 0))

(decode-universal-time (+ (get-universal-time) (+day 7)))

or

(defparameter day (+day 2))

(defun now ()
  (get-universal-time))

(defun date (date)
  (multiple-value-bind (s m h d mo y)
      (decode-universal-time date)
    (declare (ignore s m h))
    (values y mo d)))

(date (+ (now) (* 9 day)))


Can't you build what you want from *-time functions?
  http://www.lispworks.com/documentation/HyperSpec/Body/25_ad.htm
From: Madhu
Subject: Re: Date and time again
Date: 
Message-ID: <m3bpofcgyj.fsf@moon.robolove.meer.net>
* budden <····································@c36g2000yqn.googlegroups.com> :
Wrote on Tue, 23 Jun 2009 02:53:29 -0700 (PDT):

| E.g. consider the task of calculating date which is weak ahead of
| today.

Here's how I do this with my own date-time.lisp library (I've sent you
the link to the code by private mail)

| In Python it is:
|>>> import datetime as dt # local package aliases are unavailable in CL still

* (package-add-nicknames "DATE-TIME" "DT") ; wrapper around rename-package

#<The DATE-TIME package, 122/192 internal, 11/12 external>

* (in-package "DT")

#<The DATE-TIME package, 122/192 internal, 11/12 external>

|>>> dt.date.today()+dt.timedelta(7)

* (setq $a (make-instance 'date-time))
Warning:  Declaring $A special.

#<DATE-TIME "Tue Jun 23 17:03:37 IST 2009" {589195CD}>

* (date-time+ $a (make-instance 'duration :days 7))

#<DATE-TIME "Tue Jun 30 11:33:37 GMT 2009" {5899103D}>

You can add two date-time objects.  There are subtle issues involved
whether you count days first or whether you count years first.

| datetime.date(2009, 6, 30)
|
| Note there is a reasonable default date representation. No such
| one in CL.

There is, it is a bignum, which is the only "Reasonable" representation,
which you can destructure and use as you like.  I've shown you what
level of abstraction I'm comfortable with.

Allegro has a datetime library but I preferred a different API.  I'm
sure you will prefer a different API to access a datetime to mine.

--
Madhu
From: Robert Uhl
Subject: Re: Date and time again
Date: 
Message-ID: <m3my7zhuf1.fsf@latakia.octopodial-chrome.com>
budden <···········@mail.ru> writes:
>
>   What date/time library do you use? Are you satisfied?

I haven't really had need to do a lot of date/time calculations, so I
just stick with what's in the standard so far.  It was good enough to
enable me to build a basic little calendar kinda like in Python's
calendar module.  It was basically a Lisp port of a Blosxom plug-in in
Perl, so it's not very Lispy but it gets the job done.

Erik Naggum's proposed LOCAL-TIME library sounded very interesting; I
understand that Daniel Lowe is busily implementing it at
<http://www.cliki.net/local-time>.

-- 
Robert Uhl <http://public.xdi.org/=ruhl>
And if made to pass a high-enough instantaneous current, most
diodes will become Noise-emitting devices too.       --Tanuki
From: Scott Burson
Subject: Re: Date and time again
Date: 
Message-ID: <9ace0d7e-a710-4e1c-947b-420dc281cf89@k17g2000prn.googlegroups.com>
On Jun 22, 8:55 am, budden <···········@mail.ru> wrote:
> Dear lisper(s)!
>   What date/time library do you use? Are you satisfied?

I have not had to add much to the CL builtins.  CL universal time
works very well, once you get used to thinking in those terms.  Here
are some snippets of code I have found useful:

#+Allegro
(defun Local-Timezone ()
  excl::*time-zone*)

#+SCL     ; Scieneer; may work in CMUCL too
(defun Local-Timezone ()
  (tzset)
  (let ((tz rem (truncate unix::unix-timezone 3600)))
    (assert (= rem 0))
    tz))
;;; Other implementations of Local-Timezone left as an exercise
;;; for the reader

;;; `encode-universal-time' and `decode-universal-time' don't work the
right
;;; way for some uses: if an explicit timezone is supplied, they don't
adjust
;;; for daylight saving time.  These routines do.
(defun Encode-Time (sec min hr day mon yr tz)
  (- (encode-universal-time sec min hr day mon yr)
     (* 3600 (- (Local-Timezone) tz))))

(defun Decode-Time (utime tz)
  (let ((sec min hr day mon yr dow dst? tz2
	     (decode-universal-time (+ utime
				       (* 3600 (- (Local-Timezone) tz))))))
    (values sec min hr day mon yr dow dst? (- tz (- (Local-Timezone)
tz2)))))


-- Scott
From: Scott Burson
Subject: Re: Date and time again
Date: 
Message-ID: <3e758002-7df9-48d7-bea6-39057672423b@q3g2000pra.googlegroups.com>
On Jun 23, 10:28 am, Scott Burson <········@gmail.com> wrote:
> [some code]

Oops, heh, that code uses my extended LET macro:

http://common-lisp.net/project/misc-extensions/

Translate into MULTIPLE-VALUE-BIND in the obvious way if you don't
want to use my macro.

-- Scott
From: budden
Subject: Re: Date and time again
Date: 
Message-ID: <be16092d-c34b-45fc-8891-a6b8665a6176@j9g2000vbp.googlegroups.com>
Well, thank everyone for the useful comments.