classification
Title: add datetime.time.now() for consistency
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.3
process
Status: open Resolution: postponed
Dependencies: Superseder:
Assigned To: belopolsky Nosy List: belopolsky, techtonik
Priority: low Keywords:

Created on 2010-06-05 06:36 by techtonik, last changed 2010-12-01 18:46 by belopolsky.

Messages (6)
msg107122 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-05 06:36
There is:
datetime.date.today()
datetime.datetime.today()
datetime.datetime.now([tz])

But no:
datetime.time.now([tz])
msg107166 - (view) Author: Alexander Belopolsky (belopolsky) (Python committer) Date: 2010-06-06 00:11
Anatoly,

Didn't you just recently complain about the large number of functions in datetime module? (issue7584)

datetime.datetime.now().time() seems adequate to me.

What is your use case?
msg107191 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-06 08:19
> What is your use case?

>>> from datetime import now, today
>>> now()
datetime.time ...
>>> today()
datetime.date ...
msg107192 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-06 08:21
> Didn't you just recently complain about the large number of functions in datetime module?

About verbosity of datetime API to be exact, so it is a ratio of (API functions + required docs)/user code that makes required stuff done.
msg107331 - (view) Author: Alexander Belopolsky (belopolsky) (Python committer) Date: 2010-06-08 17:59
Anatoly,

msg107191 belongs to issue8903, not here and it is not a use case, but rather a demonstration of how the proposed feature would work.

My question is why would an application need current time without current date?  I feel providing time.now() may lead so people to call date.today() and time.now() separately instead of datetime.now() leading to interesting bugs.

One think I would consider an improvement over the current situation, would be to rename date.today() to date.now().  There are too many ways to spell the same thing:

date.today()
datetime.today()
datetime.now().date()

and no easy way to write a "how long ago" function that would work for both date and datetime:

def ago(t):
    t.now() - t
msg118216 - (view) Author: Alexander Belopolsky (belopolsky) (Python committer) Date: 2010-10-08 18:58
I need to correct myself: datetime.today() is not an alternative spelling of date.today(), but rather a function returning current datetime which subtly different from datetime.now().
History
Date User Action Args
2010-12-01 18:46:55belopolskysetresolution: postponed
versions: + Python 3.3, - Python 3.2
2010-10-08 18:58:42belopolskysetstage: needs patch
type: enhancement
versions: - Python 3.1, Python 2.7, Python 3.3
2010-10-08 18:58:12belopolskysetmessages: + msg118216
2010-06-08 17:59:02belopolskysetmessages: + msg107331
2010-06-06 08:21:37techtoniksetmessages: + msg107192
2010-06-06 08:19:03techtoniksetmessages: + msg107191
2010-06-06 00:11:38belopolskysetpriority: normal -> low

nosy: + belopolsky
messages: + msg107166

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