Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:26:46+00:00 2026-06-10T20:26:46+00:00

From $PYTHONHOME/lib/python2.7/calendar.py, timegm is defined as EPOCH = 1970 _EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()

  • 0

From $PYTHONHOME/lib/python2.7/calendar.py, timegm is defined as

EPOCH = 1970
_EPOCH_ORD = datetime.date(EPOCH, 1, 1).toordinal()


def timegm(tuple):
    """Unrelated but handy function to calculate Unix timestamp from GMT."""
    year, month, day, hour, minute, second = tuple[:6]
    days = datetime.date(year, month, 1).toordinal() - _EPOCH_ORD + day - 1
    hours = days*24 + hour
    minutes = hours*60 + minute
    seconds = minutes*60 + second
    return seconds

Is there any reason why days is not calculated as :

days = datetime.date(year, month, day).toordinal() - _EPOCH_ORD

Can anyone think of cases where the previous expression would break?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:26:48+00:00Added an answer on June 10, 2026 at 8:26 pm
    datetime.date(year, month, day).toordinal()
    

    “range checks” that the day (combined with year and month) is part of a valid datetime.date.

    datetime.date(year, month, 1) does not — or rather, only requires that year and month are valid.

    Apparently some user was exploiting this “feature” (of not checking the day) and for the sake of backwards compatibility (with Python2.2!) the developers kept this behavior. See Raymond Hettinger’s comment in commit #27881.

    PS. You can find the commit that changed this line in calendar.py by running

    hg blame cpython/Lib/calendar.py 
    

    (provided you’ve hg cloned the CPython repository).

    10940: def timegm(tuple):
    11691:     """Unrelated but handy function to calculate Unix timestamp from GMT."""
    11691:     year, month, day, hour, minute, second = tuple[:6]
    27881:     days = datetime.date(year, month, 1).toordinal() - _EPOCH_ORD + day - 1
    

    Then, to find more about commit #27881, you can search http://hg.python.org/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from fabric.api import sudo, put, run def install(): run('source /home/user/.virtualenvs/demo/bin/activate') run('pip install requests') if
from fabric.api import env, sudo def get_hostname(): env.hosts = ['user@host_ip'] env.passwords = {'user@host_ip': 'password'}
From my website, I have a button which calls a method and then generates
From this context: import itertools lines = itertools.cycle(open('filename')) I'm wondering how I can implement
From the Scala API , I got the following example, which does not compile;
from Apple's Documentation : @property(readonly, nonatomic) CMMagneticField magneticField Returns the magnetic field measured by
From time to time, I find myself using the same group of statements and
From 2.13.2/3 The double quote and the question mark ? , can be represented
From time to time I run into the issue that Grails integration tests the
From my earlier post , I figured out why the command build /nmake USER_C_FLAGS=/DMyVersion=3

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.