[Django] #32366: Update usage of now() &co

39 views
Skip to first unread message

Django

unread,
Jan 19, 2021, 9:28:08 AM1/19/21
to django-...@googlegroups.com
#32366: Update usage of now() &co
------------------------------------------------+--------------------------
Reporter: Carlton Gibson | Owner: nobody
Type: Cleanup/optimization | Status: assigned
Component: Utilities | Version: 4.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+--------------------------
Using datetime.now(), rather than utcnow() is the modern recommended
approach.

Warning in docs:
> ... the recommended way to create an object representing the current
time in UTC is by calling datetime.now(timezone.utc).

https://docs.python.org/3.9/library/datetime.html#datetime.datetime.now
https://docs.python.org/3/library/datetime.html#datetime.datetime.utcnow

More depth here:
https://blog.ganssle.io/articles/2019/11/utcnow.html

`datetime.utcfromtimestamp()` and `datetime.utctimetuple()` carry similar
warnings.

* Update the code to modern usage.
* Update docs examples (for backport to stable docs).

--
Ticket URL: <https://code.djangoproject.com/ticket/32366>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jan 19, 2021, 9:28:31 AM1/19/21
to django-...@googlegroups.com
#32366: Update usage of now() &co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
Type: | Gibson

Cleanup/optimization | Status: assigned
Component: Utilities | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* owner: nobody => Carlton Gibson


Comment:

[https://github.com/django/django/pull/13916 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:1>

Django

unread,
Jan 19, 2021, 11:30:59 AM1/19/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: assigned
Component: Utilities | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:2>

Django

unread,
Mar 2, 2021, 10:48:35 AM3/2/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: assigned
Component: Utilities | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Jacob Walls):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:3>

Django

unread,
Mar 2, 2021, 12:51:02 PM3/2/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Carlton
Type: | Gibson
Cleanup/optimization | Status: assigned
Component: Utilities | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:4>

Django

unread,
May 10, 2021, 3:53:19 PM5/10/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 4.0

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Nick Pope):

* owner: Carlton Gibson => Nick Pope
* needs_better_patch: 1 => 0


Comment:

I've created a new [https://github.com/django/django/pull/14374 PR] to try
and get this completed.

--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:5>

Django

unread,
May 11, 2021, 6:12:29 AM5/11/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 4.0
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:6>

Django

unread,
May 12, 2021, 6:08:48 AM5/12/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |
Component: Utilities | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Carlton Gibson <carlton.gibson@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"d06c5b358149c02a62da8a5469264d05f29ac659" d06c5b3]:
{{{
#!CommitTicketReference repository=""
revision="d06c5b358149c02a62da8a5469264d05f29ac659"
Fixed #32366 -- Updated datetime module usage to recommended approach.

- Replaced datetime.utcnow() with datetime.now().
- Replaced datetime.utcfromtimestamp() with datetime.fromtimestamp().
- Replaced datetime.utctimetuple() with datetime.timetuple().
- Replaced calendar.timegm() and datetime.utctimetuple() with
datetime.timestamp().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:8>

Django

unread,
May 12, 2021, 6:08:48 AM5/12/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Nick Pope
Type: | Status: assigned
Cleanup/optimization |
Component: Utilities | Version: 4.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"69ffb1acf38bd34f76707468bb592eb4b164e2da" 69ffb1ac]:
{{{
#!CommitTicketReference repository=""
revision="69ffb1acf38bd34f76707468bb592eb4b164e2da"
Refs #32366 -- Avoided use of datetime.utcnow() in the documentation.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:7>

Django

unread,
May 12, 2021, 6:12:59 AM5/12/21
to django-...@googlegroups.com
#32366: Update usage of now() & co
-------------------------------------+-------------------------------------
Reporter: Carlton Gibson | Owner: Nick Pope
Type: | Status: closed
Cleanup/optimization |
Component: Utilities | Version: 4.0
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Carlton Gibson <carlton.gibson@…>):

In [changeset:"cd84f7acfa65775837952bf4d1b654966be3c2cf" cd84f7ac]:
{{{
#!CommitTicketReference repository=""
revision="cd84f7acfa65775837952bf4d1b654966be3c2cf"
[3.2.x] Refs #32366 -- Avoided use of datetime.utcnow() in the
documentation.

Backport of 69ffb1acf38bd34f76707468bb592eb4b164e2da from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32366#comment:9>

Reply all
Reply to author
Forward
0 new messages