A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2007-March/071799.html below:

[Python-Dev] datetime module enhancements

[Python-Dev] datetime module enhancementsRobert Brewer fumanchu at amor.org
Fri Mar 9 22:06:14 CET 2007
Brett Cannon wrote:
> On 3/9/07, Collin Winter <collinw at gmail.com> wrote:
> > On the subject of datetime enhancements, I came across an SF patch
> > (#1673403) the other day that proposed making it possible to compare
> > date and datetime objects...
> 
> I personally like the current solution.  The proposal to just assume
> midnight goes against EIBTI in my mind.

Yeah, but the current solution goes against, um, APBP*. Not in my mind,
but in my code. Repeatedly. I can't count how many times I've written
code like:

    if created > fdate:

when I "should" have written:

    if isinstance(created, datetime.date):
        date_version_of_created = created
    else:
        date_version_of_created = created.date()
    if date_version_of_created > fdate:

But it gets better, because:

    >>> isinstance(datetime.datetime(x, y, z), datetime.date)
    True

So the above won't work, you must remember to reverse the if/else:

    if isinstance(created, datetime.datetime):
        date_version_of_created = created.date()
    else:
        date_version_of_created = created
    if date_version_of_created > fdate:

That's at least one too many "must remembers" for dumb (and busy!) ol'
me. EIBTI until it's a PITA.

Is an implicit time of 0 really so surprising? It doesn't seem to be
surprising for the datetime constructor:

>>> datetime.datetime(2007, 3, 9)
datetime.datetime(2007, 3, 9, 0, 0)

Why should it be surprising for comparisons?


Robert Brewer
System Architect
Amor Ministries
fumanchu at amor.org

* APBP = "Although, practicality beats purity"
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4