Skip to content
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

timestamp() method for datetime objects #43077

Closed
catlee mannequin opened this issue Mar 23, 2006 · 5 comments
Closed

timestamp() method for datetime objects #43077

catlee mannequin opened this issue Mar 23, 2006 · 5 comments
Labels
extension-modules C modules in the Modules dir

Comments

@catlee
Copy link
Mannequin

catlee mannequin commented Mar 23, 2006

BPO 1457227
Nosy @gvanrossum, @catlee
Files
  • datetime.patch: datetime.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2006-09-16.19:43:28.000>
    created_at = <Date 2006-03-23.20:06:07.000>
    labels = ['extension-modules']
    title = 'timestamp() method for datetime objects'
    updated_at = <Date 2006-09-16.19:43:28.000>
    user = 'https://github.com/catlee'

    bugs.python.org fields:

    activity = <Date 2006-09-16.19:43:28.000>
    actor = 'davidfraser'
    assignee = 'none'
    closed = True
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2006-03-23.20:06:07.000>
    creator = 'catlee'
    dependencies = []
    files = ['7097']
    hgrepos = []
    issue_num = 1457227
    keywords = ['patch']
    message_count = 5.0
    messages = ['49841', '49842', '49843', '49844', '49845']
    nosy_count = 3.0
    nosy_names = ['gvanrossum', 'davidfraser', 'catlee']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1457227'
    versions = []

    @catlee
    Copy link
    Mannequin Author

    catlee mannequin commented Mar 23, 2006

    This patch adds a timestamp() method to datetime
    objects. It is equivalent to:
    time.mktime(self.timetuple())

    I pulled out the dstflag calculation code from
    datetime_timetuple into a new function, get_dstflag, so
    that datetime_timestamp can make use of the same code.

    The patch also includes updates to the datetime
    documentation, and a simple unit test.

    @catlee catlee mannequin closed this as completed Mar 23, 2006
    @catlee catlee mannequin added the extension-modules C modules in the Modules dir label Mar 23, 2006
    @catlee catlee mannequin closed this as completed Mar 23, 2006
    @catlee catlee mannequin added the extension-modules C modules in the Modules dir label Mar 23, 2006
    @gvanrossum
    Copy link
    Member

    Logged In: YES
    user_id=6380

    I'm against this functionality.

    It suggests an linkage between the "naive"
    (timezone-unaware) time carried in the datetime object, and
    the UTC space that posix timestamps represent. The entire
    point of the datetime type (unless an explicit tzinfo is
    passed) is that it doesn't know which timezone it represents.

    When you call time.mktime(self.timetuple()), you as the
    application make the determination that the timetuple (which
    is still tz-unaware!) represents your current local time.
    That's a fine decision for the app to make. But I don't
    think users should be lured into believing there's an
    equivalency inherent in the datetime type -- there isn't.

    @catlee
    Copy link
    Mannequin Author

    catlee mannequin commented Mar 23, 2006

    Logged In: YES
    user_id=186532

    The .fromtimestamp and .utcfromtimestamp class methods
    already imply this linkage, don't they?

    What if timestamp() only works if the datetime object isn't
    "naive"?

    @gvanrossum
    Copy link
    Member

    Logged In: YES
    user_id=6380

    Well, that they both exist implies that the linkage is
    ambiguous...

    I think it's just not worth the new API given that it's (as
    you admit) just a shorthand for two other calls.

    There's also the problem that the range for timestamps is
    much smaller than the range of datetime -- this isn't a
    problem for .[utc]fromtimestamp() but is a problem for the
    reverse API.

    @davidfraser
    Copy link
    Mannequin

    davidfraser mannequin commented Sep 16, 2006

    Logged In: YES
    user_id=221678

    I know this is closed...
    I think it would be helpful to either

    1. add a description to the documentation of how to convert
      back, explaining the timezone story
    2. add a timestamp() function that takes a timezone parameter

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant