This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add module level now() and today() functions to datetime module
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 3.3
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, r.david.murray, rhettinger, techtonik
Priority: low Keywords:

Created on 2010-06-05 06:48 by techtonik, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg107123 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-05 06:48
Current OOP API of datetime is ugly:

from datetime import datetime
print datetime.today().isoformat()

The proposal is to add today() and now() as module functions:

from datetime import today, now
print today()
# datetime.date(2010, 6, 5)
print now()
# datetime.datetime(2010, 6, 5, 9, 48, 4, 868000)
msg107165 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-06 00:04
How hard is it to add

now = datetime.now
todate = date.today

at the top of your module is you really like shorter names?

-1
msg107332 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-08 18:07
Note that it is important to keep class methods because in some cases it is convenient to obtain now/today from datetime/date instances instead of importing them from the module.  So deprecating class methods is not an option and adding module level functions that are equivalent to existing class methods is not TOOWTDI.
msg107520 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-06-11 02:37
I actually agree with Anatoly here.  I find it much more intuitive to do

  import datetime

   timestamp = datetime.now()

than to do 

   timestamp = datetime.datetime.now()

I always have to remember that 'now' is a class method, often after getting a "datetime module has no attribute 'now'" message.  In most standard library modules a function like that would be, well, a function.  I can't imagine code where I'd find it more convenient to get 'now' from the class, and if I saw code like

    timestamp = othertimestamp.now()

I'd run screaming.

Personally I think the class methods would be better off deprecated in favor of module level functions.

However, all that said, the datetime API is what it is, and I'm not sure it is worth going through a deprecation cycle for this.  (Though othertimestamp.now() really does give me the heebie jeebies.)
msg107525 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-11 04:02
On Thu, Jun 10, 2010 at 10:37 PM, R. David Murray
<report@bugs.python.org> wrote:
>
> R. David Murray <rdmurray@bitdance.com> added the comment:
>
> I actually agree with Anatoly here.  I find it much more intuitive to do
>
>  import datetime
>
>   timestamp = datetime.now()
>
> than to do
>
>   timestamp = datetime.datetime.now()
>

Given the unfortunate name clash between the class and the module, I
never do "import datetime" and instead doe "from datetime import
datetime, date".  I find it very convenient  that importing datetime
class brings in all related functions and I don't need to import
factory functions separately.

Also, ISTM that the datetime module was designed to allow easy
extension by subclassing.  The factory methods are written so that
they work for subclasses:

...   pass
>>> Date.today()
Date(2010, 6, 10)

Writing a separate module level today() for the subclass would be quite awkward.
msg107530 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2010-06-11 06:35
FWIW, I concur with the rejection.
msg107852 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-15 08:34
Raymond mention your reasons please. I may need them one day for describing development process.
History
Date User Action Args
2022-04-11 14:57:01adminsetgithub: 53149
2010-06-15 08:34:46techtoniksetmessages: + msg107852
2010-06-11 06:44:45rhettingersetstatus: open -> closed
2010-06-11 06:35:23rhettingersetnosy: + rhettinger
messages: + msg107530
2010-06-11 04:02:55belopolskysetmessages: + msg107525
2010-06-11 02:37:53r.david.murraysetstatus: pending -> open
nosy: + r.david.murray
messages: + msg107520

2010-06-08 18:07:56belopolskysetstatus: open -> pending
title: datetime functions -> Add module level now() and today() functions to datetime module
type: enhancement
messages: + msg107332

resolution: rejected
2010-06-06 00:04:30belopolskysetpriority: normal -> low

nosy: + belopolsky
messages: + msg107165

assignee: belopolsky
2010-06-05 06:48:26techtonikcreate