Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add tz argument to date.today() #94257

Closed as not planned
Closed as not planned
Labels
extension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-featureA feature request or enhancement
@lucaswiman

Description

@lucaswiman

Feature or enhancement

Add atz argument todate.today, mirroring the interface ofdatetime.now.

Pitch

"Today" depends on the time zone, but there are many situations where you may be interested in the current date in other time zones. The most common is probably a server that runs in UTC time, but is used by people around the world.

Example use cases:

  • A calendar application where you want to show today's appointments to the end user, in the end-user's time zone.
  • Prioritizing records by due date, with records due today prioritized over records that are late.
  • Business rules involving when a record is "stale" that depends on a number of days ago relative to adate. This can easily lead to off-by-one errors if you don't specify the time zone.

Currently, these can be implemented withdatetime.now(tz=...).date(). While this is not a huge inconvenience, it seems like "today" and "now" both depend on the timezone, so they should both take the same inputs.

Previous discussion

This was discussed inthis thread on python-ideas. No one voiced any opposition, and Steven D'Aprano suggested I create an issue here.

Implementation

The python code indatetime.py looks fairly easy to change. Basically add something like:

iftzisnotNone:returndatetime.now(tz=tz).date()

That may not be the most performant implementation, though it's guaranteed to pick up any bugfixes to.now(...), which is desirable.

I'm less familiar with the C code. The relevant piece seems to behere, which may be able to work in the same way (calling the.now() code). If anyone has implementation pointers, I'd appreciate it.

The most difficult part seems to be adding a test case that will reliably pass whatever the local time the test is running under is.

Off the top of my head, my only idea is to pick time zones on either side of the international date line and assert that "today" in each of them differs by 1. I'm open to other suggestions for test cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirstdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp