Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module level now() and today() functions to datetime module #53149

Closed
techtonik mannequin opened this issue Jun 5, 2010 · 7 comments
Closed

Add module level now() and today() functions to datetime module #53149

techtonik mannequin opened this issue Jun 5, 2010 · 7 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@techtonik
Copy link
Mannequin

techtonik mannequin commented Jun 5, 2010

BPO 8903
Nosy @rhettinger, @abalkin, @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/abalkin'
closed_at = <Date 2010-06-11.06:44:45.293>
created_at = <Date 2010-06-05.06:48:26.003>
labels = ['type-feature', 'library']
title = 'Add module level now() and today() functions to datetime module'
updated_at = <Date 2010-06-15.08:34:46.678>
user = 'https://bugs.python.org/techtonik'

bugs.python.org fields:

activity = <Date 2010-06-15.08:34:46.678>
actor = 'techtonik'
assignee = 'belopolsky'
closed = True
closed_date = <Date 2010-06-11.06:44:45.293>
closer = 'rhettinger'
components = ['Library (Lib)']
creation = <Date 2010-06-05.06:48:26.003>
creator = 'techtonik'
dependencies = []
files = []
hgrepos = []
issue_num = 8903
keywords = []
message_count = 7.0
messages = ['107123', '107165', '107332', '107520', '107525', '107530', '107852']
nosy_count = 4.0
nosy_names = ['rhettinger', 'belopolsky', 'techtonik', 'r.david.murray']
pr_nums = []
priority = 'low'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue8903'
versions = ['Python 3.1', 'Python 3.2', 'Python 3.3']

@techtonik
Copy link
Mannequin Author

techtonik mannequin commented Jun 5, 2010

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)

@techtonik techtonik mannequin added the stdlib Python modules in the Lib dir label Jun 5, 2010
@abalkin
Copy link
Member

abalkin commented Jun 6, 2010

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

@abalkin abalkin self-assigned this Jun 6, 2010
@abalkin
Copy link
Member

abalkin commented Jun 8, 2010

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.

@abalkin abalkin changed the title datetime functions Add module level now() and today() functions to datetime module Jun 8, 2010
@abalkin abalkin added the type-feature A feature request or enhancement label Jun 8, 2010
@bitdancer
Copy link
Member

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.)

@abalkin
Copy link
Member

abalkin commented Jun 11, 2010

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.

@rhettinger
Copy link
Contributor

FWIW, I concur with the rejection.

@techtonik
Copy link
Mannequin Author

techtonik mannequin commented Jun 15, 2010

Raymond mention your reasons please. I may need them one day for describing development process.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants