Skip to content

bpo-43869: Time Epoch is the same on all platforms #30664

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

Merged
merged 2 commits into from
Jan 19, 2022
Merged

bpo-43869: Time Epoch is the same on all platforms #30664

merged 2 commits into from
Jan 19, 2022

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 18, 2022

Add an explicit test_epoch() test in test_time.

https://bugs.python.org/issue43869

@vstinner
Copy link
Member Author

The Python test suite checks that the Epoch is 1970-01-01 at 00:00 since 2008! It's tested indirectly by test_structseq since this change:

commit 9c2019632b9e775dcc8ae259b5028f9824265c6a
Author: Christian Heimes <[email protected]>
Date:   Mon Jan 14 03:33:52 2008 +0000

    Added new an better structseq representation. E.g. repr(time.gmtime(0)) now returns 'time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)' instead of '(1970, 1, 1, 0, 0, 0, 3, 1, 0)'. The feature is part of #1816: sys.flags

Test:

    def test_repr(self):
        (...)
        t = time.gmtime(0)
        self.assertEqual(repr(t),
            "time.struct_time(tm_year=1970, tm_mon=1, tm_mday=1, tm_hour=0, "
            "tm_min=0, tm_sec=0, tm_wday=3, tm_yday=1, tm_isdst=0)")

Add an explicit test_epoch() test in test_time.
# bpo-43869: Make sure that Python use the same Epoch on all platforms:
# January 1, 1970, 00:00:00 (UTC).
epoch = time.gmtime(0)
# Only test the date and time, ignore other gmtime() members
Copy link
Member Author

@vstinner vstinner Jan 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could test more members, but I don't think that it is worth it. It can make the test more fragile if the exact value changes depending on the platform.

``time.gmtime(0)``.
* The :dfn:`epoch` is the point where the time starts.
It is January 1, 1970, 00:00:00 (UTC) on all platforms.
To find out what the epoch is, look at ``time.gmtime(0)``.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This reads a bit strange now - you tell us exactly what the epoch is, and then tell us how to find out what it is. How about changing the above 3 lines to something like:

  • The :dfn:epoch is the point where the time starts, the
    return value of time.gmtime(0).
    It is January 1, 1970, 00:00:00 (UTC) on all platforms.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that the doc sounds strange. But I wanted to keep "gmtime(0)", it sounds important to me. I like your wording, I copied it in my PR ;-) Would you mind to review it again?

@vstinner vstinner merged commit a847785 into python:main Jan 19, 2022
@vstinner vstinner deleted the epoch branch January 19, 2022 10:27
@vstinner
Copy link
Member Author

Thanks for the suggestion Irit, and thanks for the review Irit and Paul ;-)

@bedevere-bot
Copy link

bedevere-bot commented Jan 19, 2022

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 FreeBSD Shared 3.x has failed when building commit a847785.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/all/#builders/483/builds/1513) and take a look at the build logs.
  4. Check if the failure is related to this commit (a847785) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/all/#builders/483/builds/1513

Summary of the results of the build (if available):

Click to see traceback logs
remote: Enumerating objects: 13, done.        
remote: Counting objects:   8% (1/12)        
remote: Counting objects:  16% (2/12)        
remote: Counting objects:  25% (3/12)        
remote: Counting objects:  33% (4/12)        
remote: Counting objects:  41% (5/12)        
remote: Counting objects:  50% (6/12)        
remote: Counting objects:  58% (7/12)        
remote: Counting objects:  66% (8/12)        
remote: Counting objects:  75% (9/12)        
remote: Counting objects:  83% (10/12)        
remote: Counting objects:  91% (11/12)        
remote: Counting objects: 100% (12/12)        
remote: Counting objects: 100% (12/12), done.        
remote: Compressing objects:  25% (1/4)        
remote: Compressing objects:  50% (2/4)        
remote: Compressing objects:  75% (3/4)        
remote: Compressing objects: 100% (4/4)        
remote: Compressing objects: 100% (4/4), done.        
remote: Total 13 (delta 8), reused 8 (delta 8), pack-reused 1        
From https://github.com/python/cpython
 * branch                  main       -> FETCH_HEAD
Auto packing the repository in background for optimum performance.
See "git help gc" for manual housekeeping.
rror: cannot lock ref 'refs/remotes/origin/HEAD': Unable to create '/usr/home/buildbot/python/3.x.koobs-freebsd-564d/build/.git/refs/remotes/origin/HEAD.lock': File exists.

Another git process seems to be running in this repository, e.g.
an editor opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.
fatal: failed to run reflog
rror: task 'gc' failed
Note: switching to 'a847785b40ed8819bde2dac5849dc31d15e99a74'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at a847785b40   [bpo-43869](https://bugs.python.org/issue43869): Time Epoch is the same on all platforms (GH-30664)
Switched to and reset branch 'main'

4 errors

find: build: No such file or directory
find: build: No such file or directory
find: build: No such file or directory
find: build: No such file or directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants