GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — datetime.utcnow() should return a timezone aware datetime · Issue #90477 · python/cpython

datetime.utcnow() should return a timezone aware datetime #90477

New issue
Copy link
New issue
Copy link
Closed
Closed
datetime.utcnow() should return a timezone aware datetime#90477
Copy link
Labels
3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

rtphokie
mannequin
opened on Jan 9, 2022
Issue body actions
BPO 46319
Nosy @abalkin, @vadmium, @pganssle, @rtphokie
Superseder
  • bpo-12756: datetime.datetime.utcnow should return a UTC timestamp
  • 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 = None
    closed_at = <Date 2022-01-10.03:21:41.082>
    created_at = <Date 2022-01-09.18:37:40.462>
    labels = ['type-bug', 'library', '3.9', '3.10', '3.11']
    title = 'datetime.utcnow() should return a timezone aware datetime'
    updated_at = <Date 2022-01-10.03:21:41.081>
    user = 'https://github.com/rtphokie'

    bugs.python.org fields:

    activity = <Date 2022-01-10.03:21:41.081>
    actor = 'p-ganssle'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-01-10.03:21:41.082>
    closer = 'p-ganssle'
    components = ['Library (Lib)']
    creation = <Date 2022-01-09.18:37:40.462>
    creator = 'rtphokie'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 46319
    keywords = []
    message_count = 3.0
    messages = ['410160', '410179', '410183']
    nosy_count = 4.0
    nosy_names = ['belopolsky', 'martin.panter', 'p-ganssle', 'rtphokie']
    pr_nums = []
    priority = 'normal'
    resolution = 'duplicate'
    stage = 'resolved'
    status = 'closed'
    superseder = '12756'
    type = 'behavior'
    url = 'https://bugs.python.org/issue46319'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    Activity

    1. rtphokie commented on Jan 9, 2022

      @rtphokie
      rtphokiemannequin
      on Jan 9, 2022
      MannequinAuthor
      More actions
      datetime.datetime.utcnow()

      returns a timezone naive datetime, this is counter-intuitive since you are logically dealing with a known timezone. I suspect this was implemented this way for fidelity with the rest of datetime.datetime (which returns timezone naive datetime objects).

      The workaround (see below) is to replace the missing tzinfo.

      Recommendation:
      By default datetime.datetime.utcnow() should return a timezone aware datetime (with tzinfo of UTC of course) or at least offer this behavoir as an option,

      e.g.:

      datetime.datetime.utcnow(timezone-aware=True)

      Workaround:
      dt = datetime.utcnow().replace(tzinfo=timezone.utc)

    2. rtphokie
      added
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      3.10 (EOL)end of lifeend of life
      3.11only security fixesonly security fixes
      3.9 (EOL)end of lifeend of life
      stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
      on Jan 9, 2022
    3. AlexWaygood
      removed
      3.7 (EOL)end of lifeend of life
      3.8 (EOL)end of lifeend of life
      on Jan 9, 2022
    4. vadmium commented on Jan 10, 2022

      @vadmium
      vadmium
      on Jan 10, 2022
      Member
      More actions

      Perhaps this is a duplicate of bpo-12756?

    5. pganssle commented on Jan 10, 2022

      @pganssle
      pganssle
      on Jan 10, 2022
      Member
      More actions

      Yes, this is the documented behavior, including a warning against using UTC now in the documentation!

      There is some possibility of removing utcnow entirely as an "attractive nuisance", but I suspect that this will lead to much consternation and hand-wringing, and there are some legitimate uses for utcnow, so I haven't made it a high priority to have that particular fight...

    6. pganssle
      closed this as completedon Jan 10, 2022
    7. pganssle
      closed this as completedon Jan 10, 2022
    8. ezio-melotti
      transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.10 (EOL)end of lifeend of life3.11only security fixesonly security fixes3.9 (EOL)end of lifeend of lifestdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions

        You are visitor 01402520 — GeezerVison does not store the pages you look up.
        Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.