This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document time.ctime format
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.8, Python 3.7, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Roger.Caldwell, belopolsky, cheryl.sabella, eric.smith, georg.brandl, harman786, miss-islington, p-ganssle, r.david.murray, vstinner, ztane
Priority: normal Keywords: patch

Created on 2012-02-02 20:49 by Roger.Caldwell, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ctime-doc.patch harman786, 2016-10-13 11:12 patch file review
Pull Requests
URL Status Linked Edit
PR 11303 merged harman786, 2018-12-24 09:07
PR 16022 merged miss-islington, 2019-09-12 10:24
Messages (16)
msg152475 - (view) Author: Roger Caldwell (Roger.Caldwell) Date: 2012-02-02 20:49
Hi.  I found this today and thought I would report.  I could not find anywhere that it was expected behavior.  When using time.ctime() to convert a date which only has 1 digit in the day position it returs a string with 2 spaces after the month vs one.

example
In [2]: import os,time

In [3]: time.ctime(os.path.getmtime('file.cfg'))
Out[3]: 'Tue Dec 13 18:52:58 2011'

In [4]: time.ctime(os.path.getmtime('14d-1.log'))
Out[4]: 'Tue Feb  1 19:53:11 2011'

Is this expected behavior?
msg152483 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2012-02-02 22:29
That's definitely the expected behavior. It's the same as the C library version of ctime().

But I couldn't find it documented in the Python docs, so I'm changing this to a documentation issue.

Thanks for the report.
msg152496 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2012-02-03 07:10
asctime() docs say it's a 24 char string.
msg153310 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2012-02-14 00:23
> asctime() docs say it's a 24 char string.

I'm not sure that all platform conform to this "specification"... which is not future proof!

$ ./python 
Python 3.3.0a0 (default:af1a9508f7fa, Feb 14 2012, 01:18:15) 
[GCC 4.6.2 20111027 (Red Hat 4.6.2-1)] on linux
>>> import time
>>> time.ctime(2**38)
'Wed Jul 14 08:09:04 10680'
>>> len(time.ctime(2**38))
25

I suppose that you can say that the month day is formatted as 2 characters (padded with a space if needed).
msg153311 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-02-14 00:25
Or you could give the strftime specification string that produces the equivalent output.
msg278557 - (view) Author: Harmandeep Singh (harman786) * Date: 2016-10-13 11:12
I was bored, I generated a patch for this.

Hope this helps :)
msg332336 - (view) Author: Antti Haapala (ztane) * Date: 2018-12-22 08:32
This should be added to `asctime` too.

The space-padded behaviour complies with the C standard which was the intent - after all, before it was using C `asctime` directly, and says that unlike C asctime, it doesn't have the newline character, meaning that as a rule, it should then behave similar to it, and only exception is marked.

Unfortunately MSVC asctime has been incorrectly using leading zeros (https://stackoverflow.com/q/53894148/918959).
msg332422 - (view) Author: Harmandeep Singh (harman786) * Date: 2018-12-24 09:07
I have created the PR as mentioned, I have added the example for time.ctime() and also added the note to time.asctime.
msg332584 - (view) Author: Harmandeep Singh (harman786) * Date: 2018-12-27 11:08
I have created a PR for the patch that I submitted, as this is my first contribution to the docs, I need to know that how do we decide if a change has to make an entry to `Misc/NEWS.d/next/` or needs `skip news` tag?
msg339973 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-11 13:18
I would like to help get this issue merged as it's already been approved by a core developer.

Does anyone object to the change?  Victor made a suggestion on the PR for alternative wording and I wanted to give others a chance to comment on that.

Also, looking at the man page for asctime, they use `Www Mmm dd hh:mm:ss yyyy` as the description of the output.  Maybe it would be helpful to add this since it shows the spacing and explicitly shows the day number taking up 2 characters?

Thanks!
msg339975 - (view) Author: Harmandeep Singh (harman786) * Date: 2019-04-11 13:48
This is not python compatible format, I want something like "%a %b %d %H:%M:%S %Y" to explain it.
msg339980 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-04-11 14:38
I guess what I'm thinking of `Www Mmm dd hh:mm:ss yyyy` as representing isn't so much a format, but rather a literal replacement of where each value has a placeholder in the string (that is, a pattern).  So, even if `Www` doesn't mean anything, to me it means that the first three characters in the string are a Weekday, then there's a space, then Mmm is the month, then a space, then dd is the day number (with zero sometimes suppressed), etc.  

If that is more confusing than not using it, then that's fine.  I just wanted to mention it.

Using %d to me is also confusing since the docs define %d as `Day of the month as a decimal number [01,31]`.  This clearly isn't using 01, but rather suppressing the 0.
msg340207 - (view) Author: Harmandeep Singh (harman786) * Date: 2019-04-14 13:54
I have updated the PR, this time I have kept it really simple, and have added examples showing both the cases.
msg352091 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-09-12 10:22
New changeset 2d32bf1ef23c9e468b2e8afab3c24e7a2047ac36 by Paul Ganssle (Harmandeep Singh) in branch 'master':
bpo-13927: time.ctime and time.asctime return string explantion (GH-11303)
https://github.com/python/cpython/commit/2d32bf1ef23c9e468b2e8afab3c24e7a2047ac36
msg352095 - (view) Author: miss-islington (miss-islington) Date: 2019-09-12 10:31
New changeset 1e17c4d414049ad2b5b6a0a53685efc7a550c5c5 by Miss Islington (bot) in branch '3.8':
bpo-13927: time.ctime and time.asctime return string explantion (GH-11303)
https://github.com/python/cpython/commit/1e17c4d414049ad2b5b6a0a53685efc7a550c5c5
msg352098 - (view) Author: Paul Ganssle (p-ganssle) * (Python committer) Date: 2019-09-12 10:35
We've merged the PR and I think it resolves this issue, so we can close this issue now. Please let me know if it's not fully resolved and we can re-open.

Thanks Roger for reporting this and Harmandeep for making the PR and requested changes.
History
Date User Action Args
2022-04-11 14:57:26adminsetgithub: 58135
2019-09-12 10:35:48p-gansslesetstatus: open -> closed
type: behavior -> enhancement
messages: + msg352098

resolution: fixed
stage: patch review -> resolved
2019-09-12 10:31:46miss-islingtonsetnosy: + miss-islington
messages: + msg352095
2019-09-12 10:24:53miss-islingtonsetpull_requests: + pull_request15645
2019-09-12 10:22:33p-gansslesetnosy: + p-ganssle
messages: + msg352091
2019-04-14 13:54:43harman786setmessages: + msg340207
2019-04-11 14:38:05cheryl.sabellasetmessages: + msg339980
2019-04-11 13:48:02harman786setmessages: + msg339975
2019-04-11 13:18:54cheryl.sabellasetnosy: + cheryl.sabella, belopolsky
messages: + msg339973
2019-01-04 23:19:25vstinnersettitle: Extra spaces in the output of time.ctime -> Document time.ctime format
versions: - Python 3.2, Python 3.3, Python 3.4, Python 3.5, Python 3.6
2018-12-27 11:08:41harman786setnosy: - docs@python
messages: + msg332584
2018-12-24 09:07:15harman786setversions: + Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8
stage: patch review
messages: + msg332422
pull_requests: + pull_request10527
2018-12-22 08:32:44ztanesetnosy: + ztane
messages: + msg332336
2018-09-12 03:47:50martin.panterlinkissue34642 superseder
2016-10-13 11:16:02harman786sethgrepos: - hgrepo360
2016-10-13 11:12:50harman786setfiles: + ctime-doc.patch

nosy: + harman786
messages: + msg278557

hgrepos: + hgrepo360
keywords: + patch
2012-02-14 00:25:56r.david.murraysetnosy: + r.david.murray
messages: + msg153311
2012-02-14 00:23:26vstinnersetnosy: + vstinner
messages: + msg153310
2012-02-03 07:10:51georg.brandlsetnosy: + georg.brandl
messages: + msg152496
2012-02-02 22:29:28eric.smithsetversions: + Python 3.2, Python 3.3
nosy: + docs@python, eric.smith

messages: + msg152483

assignee: docs@python
components: + Documentation, - None
2012-02-02 20:49:35Roger.Caldwellcreate