Proposal to enhance date / time features

6 views
Skip to first unread message

ghtdak

unread,
Feb 11, 2009, 4:23:09 PM2/11/09
to sage-devel
Python pretty much punted on date and time. It has some support, but
its not very good.

The Python Quick Reference: http://rgruet.free.fr/PQR25/PQR2.5.html

suggests mxDateTime: http://www.egenix.com/products/python/mxBase/mxDateTime/

and, having worked with it, I recommend it over what comes native with
Python. My guess is this is why Python hasn't bothered.

A quick glance through the license doesn't show anything obviously
problematic. Seems to be the Python license but I don't know if that
makes sense...

My proposal is to add something for date and time handling. Looks
like mx might be the right approach.

Questions? Comments? Jokes?

-glenn

mabshoff

unread,
Feb 11, 2009, 4:51:57 PM2/11/09
to sage-devel


On Feb 11, 1:23 pm, ghtdak <gl...@tarbox.org> wrote:

Hi Glenn,

> Python pretty much punted on date and time.  It has some support, but
> its not very good.
>
> The Python Quick Reference:http://rgruet.free.fr/PQR25/PQR2.5.html
>
> suggests mxDateTime:http://www.egenix.com/products/python/mxBase/mxDateTime/

Could you go into details what is better about this code?

> and, having worked with it, I recommend it over what comes native with
> Python.  My guess is this is why Python hasn't bothered.
>
> A quick glance through the license doesn't show anything obviously
> problematic.  Seems to be the Python license but I don't know if that
> makes sense...

It isn't the Python license, but basically "you can do anything with
this code provided you keep the license intact", i.e. it is somewhat
BSD-ish, but without an advertising clause. It is OSI approved, but
since we aren't linking to anything covered by the GPL or another
"restrictive" licenses it doesn't matter too much. It is just not nice
to have another license and license proliferation generally sucks

The code seems to be well tested, runs on OSX, Windows, Linux, ....
and has some C backend, so from that end things are looking good.

But the interesting question is whether there is an alternative with a
clean license?

> My proposal is to add something for date and time handling.  Looks
> like mx might be the right approach.
>
> Questions?  Comments?  Jokes?

A perl, a python and a ruby programmer go into a bar. One of them
looks at the other and says: ... - oh never mind :)

> -glenn

Cheers,

Michael

William Stein

unread,
Feb 11, 2009, 6:03:03 PM2/11/09
to sage-...@googlegroups.com, Phaedon Sinis, sage-f...@googlegroups.com

I know that Phaedon Sinis's new package for quantitative finance in
Sage, which he intends to submit within about 2 weeks, has lots of
more sophisticated date/time handling than what is builtin to Python,
at least stuff motivated by finance. I'm guessing you're also
interested in datetime functionality motivated by finance. So
Phaedon, care to make any remarks?

William

Phaedon Sinis

unread,
Feb 11, 2009, 6:40:48 PM2/11/09
to William Stein, sage-...@googlegroups.com, sage-f...@googlegroups.com
Hi Glenn,

thanks for looking into this.
At first glance, it looks like it basically allows date arithmetic.
I was planning to incorporate Gustavo Niemeyer's relativedelta.py for this purpose.
My date library adds business-day / holiday calculations.

Does anyone have a strong preference between relativedelta.py and mxDateTime?

mabshoff

unread,
Feb 11, 2009, 6:47:39 PM2/11/09
to sage-devel


On Feb 11, 3:40 pm, Phaedon Sinis <phaedonsi...@gmail.com> wrote:
> Hi Glenn,
>
> thanks for looking into this.
> At first glance, it looks like it basically allows date arithmetic.
> I was planning to incorporate Gustavo Niemeyer's relativedelta.py for this
> purpose.
> My date library adds business-day / holiday calculations.
>
> Does anyone have a strong preference between relativedelta.py and
> mxDateTime?

Well, I knew matplotlib had some date/time stuff since I had seen it
whiz by when unpacking the tarball, so I 20 seconds of grepping
revealed:

mabshoff@sage:/scratch/mabshoff/sage-3.3.rc1/spkg/standard/
matplotlib-0.98.3.p5/src$ grep -r "Gustavo Niemeyer" *
lib/dateutil/rrule.py:Copyright (c) 2003-2005 Gustavo Niemeyer
<gus...@niemeyer.net>
lib/dateutil/rrule.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/tzwin.py:__author__ = "Jeffrey Harris & Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/tz.py:Copyright (c) 2003-2005 Gustavo Niemeyer
<gus...@niemeyer.net>
lib/dateutil/tz.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/relativedelta.py:Copyright (c) 2003-2005 Gustavo
Niemeyer <gus...@niemeyer.net>
lib/dateutil/relativedelta.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/parser.py:Copyright (c) 2003-2005 Gustavo Niemeyer
<gus...@niemeyer.net>
lib/dateutil/parser.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/zoneinfo/__init__.py:Copyright (c) 2003-2005 Gustavo
Niemeyer <gus...@niemeyer.net>
lib/dateutil/zoneinfo/__init__.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/easter.py:Copyright (c) 2003-2005 Gustavo Niemeyer
<gus...@niemeyer.net>
lib/dateutil/easter.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"
lib/dateutil/__init__.py:Copyright (c) 2003-2005 Gustavo Niemeyer
<gus...@niemeyer.net>
lib/dateutil/__init__.py:__author__ = "Gustavo Niemeyer
<gus...@niemeyer.net>"

So relativedelta.py is already in Sage, no need to add it :)

Cheers,

Michael

boo...@u.washington.edu

unread,
Feb 11, 2009, 9:18:57 PM2/11/09
to sage-devel
> Questions? Comments? Jokes?

sage: current_time()
Time to buy a watch!

ghtdak

unread,
Feb 12, 2009, 3:50:39 AM2/12/09
to sage-devel


On Feb 11, 3:47 pm, mabshoff <mabsh...@googlemail.com> wrote:
> On Feb 11, 3:40 pm, Phaedon Sinis <phaedonsi...@gmail.com> wrote:
>
> > Hi Glenn,
>
> > thanks for looking into this.
> > At first glance, it looks like it basically allows date arithmetic.
> > I was planning to incorporate Gustavo Niemeyer's relativedelta.py for this
> > purpose.
> > My date library adds business-day / holiday calculations.
>
> > Does anyone have a strong preference between relativedelta.py and
> > mxDateTime?

The matplotlib.dates module "appears" to be Gustavo's complete
dateutil library

http://labix.org/python-dateutil

My guess it does everything the typical user (e.g. myself) would
need. Being part of Matplotlib is obviously a bonus and you've
clearly found it useful.

Pretty much puts this one to bed.

> So relativedelta.py is already in Sage, no need to add it :)

So, do I get credit for the enhancement? :-)

-glenn

>
> Cheers,
>
> Michael

mabshoff

unread,
Feb 12, 2009, 4:09:54 AM2/12/09
to sage-devel


On Feb 12, 12:50 am, ghtdak <gl...@tarbox.org> wrote:
> On Feb 11, 3:47 pm, mabshoff <mabsh...@googlemail.com> wrote:

Hi Glenn,

> The matplotlib.dates module "appears" to be Gustavo's complete
> dateutil library
>
> http://labix.org/python-dateutil
>
> My guess it does everything the typical user (e.g. myself) would
> need.  Being part of Matplotlib is obviously a bonus and you've
> clearly found it useful.
>
> Pretty much puts this one to bed.

Cool. This outcome was exactly what I had hoped for when I encouraged
you to post to sage-devel before doing anything.

> > So relativedelta.py is already in Sage, no need to add it :)
>
> So, do I get credit for the enhancement?  :-)

Sure, just let me know where to send the gold star ;)

> -glenn

Cheers,

Michael

John Cremona

unread,
Feb 19, 2009, 12:10:41 PM2/19/09
to sage-devel
I hope we will fully support this kind of thing:

%cal 9 1752
September 1752
Su Mo Tu We Th Fr Sa
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Well, someone asked for jokes!

John

On 12 Feb, 08:50, ghtdak <gl...@tarbox.org> wrote:
> On Feb 11, 3:47 pm, mabshoff <mabsh...@googlemail.com> wrote:
>
> > On Feb 11, 3:40 pm, Phaedon Sinis <phaedonsi...@gmail.com> wrote:
>
> > > Hi Glenn,
>
> > > thanks for looking into this.
> > > At first glance, it looks like it basically allowsdatearithmetic.
> > > I was planning to incorporate Gustavo Niemeyer's relativedelta.py for this
> > > purpose.
> > > Mydatelibrary adds business-day / holiday calculations.

Jason Grout

unread,
Feb 19, 2009, 1:48:20 PM2/19/09
to sage-...@googlegroups.com
John Cremona wrote:
> I hope we will fully support this kind of thing:
>
> %cal 9 1752
> September 1752
> Su Mo Tu We Th Fr Sa
> 1 2 14 15 16
> 17 18 19 20 21 22 23
> 24 25 26 27 28 29 30
>
> Well, someone asked for jokes!

Already done :)

sage: !cal 9r 1752r


September 1752
Su Mo Tu We Th Fr Sa
1 2 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30

Jason

kcrisman

unread,
Feb 19, 2009, 1:59:32 PM2/19/09
to sage-devel

>
> sage: !cal 9r 1752r
>     September 1752
> Su Mo Tu We Th Fr Sa
>         1  2 14 15 16
> 17 18 19 20 21 22 23
> 24 25 26 27 28 29 30

Wow, that's amazing. What about in Russia or Italy, though?

As a non-joke, this isn't ?-able, though. How would someone find this
by looking under ca[tab]? (You can't, and !ca[tab] does the same
thing).

Also, does this have a non-English version available within Sage?
E.g.

> So Mo Di Mi Do Fr Sa

- kcrisman

Timothy Clemans

unread,
Feb 19, 2009, 2:04:02 PM2/19/09
to sage-...@googlegroups.com
On Thu, Feb 19, 2009 at 1:59 PM, kcrisman <kcri...@gmail.com> wrote:
>
>
>>
>> sage: !cal 9r 1752r
>> September 1752
>> Su Mo Tu We Th Fr Sa
>> 1 2 14 15 16
>> 17 18 19 20 21 22 23
>> 24 25 26 27 28 29 30
>
> Wow, that's amazing. What about in Russia or Italy, though?
>
> As a non-joke, this isn't ?-able, though. How would someone find this
> by looking under ca[tab]? (You can't, and !ca[tab] does the same
> thing).

It's calling the system's calendar program. Anytime you put ! in front
of an identifier you are running the command through the shell and not
Sage.

Phaedon Sinis

unread,
Mar 1, 2009, 6:32:25 PM3/1/09
to sage-devel
After this, I'll stop prefacing all my questions with apologies for
being a beginner.

import matplotlib.dateutil works fine within sage
but dateutil seems to be empty. dir(dateutil) doesn't contain
anything -- and I am looking specificalliy for relativedelta. What am
I doing wrong?


On Feb 11, 3:47 pm, mabshoff <mabsh...@googlemail.com> wrote:
> On Feb 11, 3:40 pm, Phaedon Sinis <phaedonsi...@gmail.com> wrote:
>
> > Hi Glenn,
>
> > thanks for looking into this.
> > At first glance, it looks like it basically allows date arithmetic.
> > I was planning to incorporate Gustavo Niemeyer's relativedelta.py for this
> > purpose.
> > My date library adds business-day / holiday calculations.
>
> > Does anyone have a strong preference between relativedelta.py and
> > mxDateTime?
>
> Well, I knew matplotlib had some date/time stuff since I had seen it
> whiz by when unpacking the tarball, so I 20 seconds of grepping
> revealed:
>
> mabshoff@sage:/scratch/mabshoff/sage-3.3.rc1/spkg/standard/
> matplotlib-0.98.3.p5/src$ grep -r "Gustavo Niemeyer" *
> lib/dateutil/rrule.py:Copyright (c) 2003-2005  Gustavo Niemeyer
> <gust...@niemeyer.net>
> lib/dateutil/rrule.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/tzwin.py:__author__ = "Jeffrey Harris & Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/tz.py:Copyright (c) 2003-2005  Gustavo Niemeyer
> <gust...@niemeyer.net>
> lib/dateutil/tz.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/relativedelta.py:Copyright (c) 2003-2005  Gustavo
> Niemeyer <gust...@niemeyer.net>
> lib/dateutil/relativedelta.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/parser.py:Copyright (c) 2003-2005  Gustavo Niemeyer
> <gust...@niemeyer.net>
> lib/dateutil/parser.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/zoneinfo/__init__.py:Copyright (c) 2003-2005  Gustavo
> Niemeyer <gust...@niemeyer.net>
> lib/dateutil/zoneinfo/__init__.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/easter.py:Copyright (c) 2003-2005  Gustavo Niemeyer
> <gust...@niemeyer.net>
> lib/dateutil/easter.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"
> lib/dateutil/__init__.py:Copyright (c) 2003-2005  Gustavo Niemeyer
> <gust...@niemeyer.net>
> lib/dateutil/__init__.py:__author__ = "Gustavo Niemeyer
> <gust...@niemeyer.net>"

Jason Grout

unread,
Mar 2, 2009, 12:23:12 PM3/2/09
to sage-...@googlegroups.com
Phaedon Sinis wrote:
> After this, I'll stop prefacing all my questions with apologies for
> being a beginner.
>
> import matplotlib.dateutil works fine within sage
> but dateutil seems to be empty. dir(dateutil) doesn't contain
> anything -- and I am looking specificalliy for relativedelta. What am
> I doing wrong?


This works:


----------------------------------------------------------------------
| Sage Version 3.3, Release Date: 2009-02-21 |
| Type notebook() for the GUI, and license() for information. |
----------------------------------------------------------------------
sage: from matplotlib.dates import relativedelta as rd
sage: rd
<class dateutil.relativedelta.relativedelta at 0xc01ef2c>


Also, this works:

sage: from dateutil import relativedelta as rd
sage: rd.<TAB>
rd.FR rd.TH rd.datetime rd.x
rd.MO rd.TU rd.relativedelta
rd.SA rd.WE rd.weekday
rd.SU rd.calendar rd.weekdays
sage: rd.relativedelta
<class dateutil.relativedelta.relativedelta at 0xa2598cc>


So it looks like you want the module matplotlib.dates or the module
dateutil.relativedelta

Jason

Reply all
Reply to author
Forward
0 new messages