-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
gh-137758: Clarify os.stat_result time fields (since Unix epoch) and add datetime conversion note #137761
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
Open
tangyuan0821
wants to merge
11
commits into
python:main
Choose a base branch
from
tangyuan0821:main2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+32
−10
Open
gh-137758: Clarify os.stat_result time fields (since Unix epoch) and add datetime conversion note #137761
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ead4f3f
gh-137758: Clarify os.stat_result time fields are seconds since the U…
tangyuan0821 a34b6df
Merge branch 'python:main' into main2
tangyuan0821 49caa9f
Correct the description of the time field in the document to clearly …
tangyuan0821 49a652a
Fix the indentation of the time field in the document.
tangyuan0821 a6b8620
Merge branch 'main' into main2
tangyuan0821 5cc8731
Fix the indentation of the time field in the document.
tangyuan0821 58d2f66
Merge branch 'main' into main2
tangyuan0821 2dc9164
docs(os): address review feedback on stat_result time field docs
tangyuan0821 7805c8f
Merge branch 'main' into main2
StanFromIreland 6fd16dc
gh-137758: Address review: clarify ns timestamp conversion and link n…
tangyuan0821 07457d2
Merge branch 'main' into main2
tangyuan0821 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -3263,15 +3263,18 @@ features: | |||||
|
|
||||||
| .. attribute:: st_atime | ||||||
|
|
||||||
| Time of most recent access expressed in seconds. | ||||||
| Time of most recent access expressed in | ||||||
| :ref:`seconds since the Unix epoch <stat-result-timestamps>`. | ||||||
|
|
||||||
| .. attribute:: st_mtime | ||||||
|
|
||||||
| Time of most recent content modification expressed in seconds. | ||||||
| Time of most recent content modification expressed in | ||||||
| :ref:`seconds since the Unix epoch <stat-result-timestamps>`. | ||||||
|
|
||||||
| .. attribute:: st_ctime | ||||||
|
|
||||||
| Time of most recent metadata change expressed in seconds. | ||||||
| Time of most recent metadata change expressed in | ||||||
| :ref:`seconds since the Unix epoch <stat-result-timestamps>`. | ||||||
|
|
||||||
| .. versionchanged:: 3.12 | ||||||
| ``st_ctime`` is deprecated on Windows. Use ``st_birthtime`` for | ||||||
|
|
@@ -3280,20 +3283,24 @@ features: | |||||
|
|
||||||
| .. attribute:: st_atime_ns | ||||||
|
|
||||||
| Time of most recent access expressed in nanoseconds as an integer. | ||||||
| Time of most recent access expressed in | ||||||
| :ref:`nanoseconds since the Unix epoch <stat-result-timestamps>` as an | ||||||
| integer. | ||||||
|
|
||||||
| .. versionadded:: 3.3 | ||||||
|
|
||||||
| .. attribute:: st_mtime_ns | ||||||
|
|
||||||
| Time of most recent content modification expressed in nanoseconds as an | ||||||
| Time of most recent content modification expressed in | ||||||
| :ref:`nanoseconds since the Unix epoch <stat-result-timestamps>` as an | ||||||
| integer. | ||||||
|
|
||||||
| .. versionadded:: 3.3 | ||||||
|
|
||||||
| .. attribute:: st_ctime_ns | ||||||
|
|
||||||
| Time of most recent metadata change expressed in nanoseconds as an | ||||||
| Time of most recent metadata change expressed in | ||||||
| :ref:`nanoseconds since the Unix epoch <stat-result-timestamps>` as an | ||||||
| integer. | ||||||
|
|
||||||
| .. versionadded:: 3.3 | ||||||
|
|
@@ -3305,16 +3312,19 @@ features: | |||||
|
|
||||||
| .. attribute:: st_birthtime | ||||||
|
|
||||||
| Time of file creation expressed in seconds. This attribute is not | ||||||
| always available, and may raise :exc:`AttributeError`. | ||||||
| Time of file creation expressed in | ||||||
| :ref:`seconds since the Unix epoch <stat-result-timestamps>`. | ||||||
| This attribute is not always available, | ||||||
| and may raise :exc:`AttributeError`. | ||||||
|
|
||||||
| .. versionchanged:: 3.12 | ||||||
| ``st_birthtime`` is now available on Windows. | ||||||
|
|
||||||
| .. attribute:: st_birthtime_ns | ||||||
|
|
||||||
| Time of file creation expressed in nanoseconds as an integer. | ||||||
| This attribute is not always available, and may raise | ||||||
| Time of file creation expressed in | ||||||
| :ref:`nanoseconds since the Unix epoch <stat-result-timestamps>` as an | ||||||
| integer. This attribute is not always available, and may raise | ||||||
| :exc:`AttributeError`. | ||||||
|
|
||||||
| .. versionadded:: 3.12 | ||||||
|
|
@@ -3338,6 +3348,18 @@ features: | |||||
| :attr:`st_atime_ns`, :attr:`st_mtime_ns`, :attr:`st_ctime_ns` and | ||||||
| :attr:`st_birthtime_ns`. | ||||||
|
|
||||||
| .. _stat-result-timestamps: | ||||||
|
|
||||||
| .. note:: | ||||||
|
|
||||||
| These timestamps are seconds (or nanoseconds for the ``*_ns`` variants) | ||||||
|
StanFromIreland marked this conversation as resolved.
|
||||||
| since the Unix epoch (00:00:00 UTC, January 1, 1970), and are compatible | ||||||
| with :func:`time.time`. To convert a timestamp ``ts`` (in seconds) to a | ||||||
| :class:`datetime.datetime`, use :func:`datetime.datetime.fromtimestamp` | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| for local time or | ||||||
| ``datetime.datetime.fromtimestamp(ts, tz=datetime.timezone.utc)`` for | ||||||
| UTC. For ``*_ns`` timestamps, divide by ``1_000_000_000`` first. | ||||||
|
|
||||||
| On some Unix systems (such as Linux), the following attributes may also be | ||||||
| available: | ||||||
|
|
||||||
|
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this makes more sense as one note?