[Python-Dev] datetime and timedelta enhancement

M.-A. Lemburg mal at egenix.com
Mon Nov 17 12:37:51 CET 2008

On 2008-11-16 02:14, Nick Coghlan wrote:
> M.-A. Lemburg wrote:
>> Guess I could add a .weeks attribute to mxDateTime, but no one ever
>> asked for that so far.
> Given that there are at least 3 different ways to define the number of
> "weeks" between two dates, it may be something best left to applications
> to worry about.

I'd just use the term "weeks" as meaning 7 full days and then
return a float value for fractions. That's the same convention used
for .days. Anything more complicated would need to use DateTime
values (see below).

> OOo implements 2 of them [1] for its WEEKS() function, and there's then
> a fairly obvious 3rd variant based on a Sunday to Saturday week.
> Cheers,
> Nick.
> [1]
> http://wiki.services.openoffice.org/wiki/Documentation/How_Tos/Calc:_WEEKS_function

If you need ISO week counting or any other date based counting
mechanism, you need to know the two DateTime values you're dealing
with and possibly the calendar you're using.

mxDateTime has an .iso_week attribute to help with this, e.g.

>>> Date(2008,11,17).iso_week
(2008, 47, 1)


Marc-Andre Lemburg

Professional Python Services directly from the Source  (#1, Nov 17 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
2008-11-12: Released mxODBC.Connect 0.9.3      http://python.egenix.com/

:::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,MacOSX for free ! ::::

   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611

More information about the Python-Dev mailing list