Skip to content

Use ISO timestamp in diff.py #51831

Closed
Closed

Description

@techtonik
mannequin
BPO 7582
Nosy @warsaw, @amauryfa, @abalkin, @djc, @merwok
Dependencies
  • bpo-9527: Add aware local time support to datetime module
  • bpo-1647654: No obvious and correct way to get the time zone offset
  • Files
  • diff.py_iso_timestamps.diff
  • diff.py_iso_timestamps_true.diff: flawless
  • diff.py_iso_timestamps_true_with_dst.diff: also detects dst
  • diff.py_iso_timestamps_true_with_true_dst.diff: active dst
  • 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 = 'https://github.com/abalkin'
    closed_at = <Date 2012-06-22.17:37:53.631>
    created_at = <Date 2009-12-27.15:57:56.577>
    labels = ['type-feature']
    title = 'Use ISO timestamp in diff.py'
    updated_at = <Date 2012-06-22.18:00:30.271>
    user = 'https://bugs.python.org/techtonik'

    bugs.python.org fields:

    activity = <Date 2012-06-22.18:00:30.271>
    actor = 'techtonik'
    assignee = 'belopolsky'
    closed = True
    closed_date = <Date 2012-06-22.17:37:53.631>
    closer = 'belopolsky'
    components = ['Demos and Tools']
    creation = <Date 2009-12-27.15:57:56.577>
    creator = 'techtonik'
    dependencies = ['9527', '1647654']
    files = ['15678', '15689', '15798', '16184']
    hgrepos = []
    issue_num = 7582
    keywords = ['patch', 'needs review']
    message_count = 29.0
    messages = ['96912', '96922', '96929', '96962', '96978', '96979', '96981', '97272', '97460', '97471', '97503', '97539', '97540', '97546', '99092', '99096', '99108', '99163', '99166', '99171', '99200', '99393', '104419', '104430', '104439', '107152', '107154', '163434', '163448']
    nosy_count = 8.0
    nosy_names = ['barry', 'amaury.forgeotdarc', 'belopolsky', 'techtonik', 'djc', 'eric.araujo', 'srumbalski', 'python-dev']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue7582'
    versions = ['Python 3.2']

    Activity

    1. techtonik commented on Dec 27, 2009

      techtonikmannequin
      MannequinAuthor

      make diff.py produce unified diffs with ISO 8601 timestamps

      Currently generated timestamps are difficult to separate from filename
      when parsing if you don't know that the diff was generated by diff.by
      This patch make diff.py output more standard compliant by including ISO
      8601 timestamps that also conform to RFC 3339 profile for timestamp format
      on the internet.

    2. amauryfa commented on Dec 27, 2009

      @amauryfa
      Contributor

      Using ISO format certainly makes sense, but it seems to me that after
      dt=datetime.fromtimestamp(mtime), dt.tzinfo is always None, so the test is
      not necessary.

    3. techtonik commented on Dec 27, 2009

      techtonikmannequin
      MannequinAuthor

      That's true. Is there any way to get current TZ offset in Python? I can't
      find anything better than datetime.datetime.now() -
      datetime.datetime.utcnow() and then rounding to a nearest minute.

    4. briancurtin commented on Dec 28, 2009

      @briancurtin
      Member

      Look at time.timezone -
      http://docs.python.org/library/time.html#time.timezone

      # I'm in US Central time, so it's -6 from UTC
      >>> import time
      >>> tz = time.timezone
      >>> tz
      21600
      >>> tz / 60 / 60
      6
    5. techtonik commented on Dec 28, 2009

      techtonikmannequin
      MannequinAuthor

      Thanks! Now the most elegant patch I could think out.

    6. briancurtin commented on Dec 29, 2009

      @briancurtin
      Member

      Looks cleaner and works for me.

      One very minor comment: the spaces inside the parenthesis on the
      time.localtime call are inconsistent and don't comply with PEP-8.

    7. techtonik commented on Dec 29, 2009

      techtonikmannequin
      MannequinAuthor

      Pepeighfied and regenerated. Should be flawless now.

    8. srumbalski commented on Jan 5, 2010

      srumbalskimannequin
      Mannequin

      I think this is incorrect during daylight savings time:
      tzoffset = -time.timezone // 60

      This should do it:
      isdst = time.localtime().tm_isdst
      tzoffset = -(time.altzone if isdst else time.timezone)//60

    9. techtonik commented on Jan 9, 2010

      techtonikmannequin
      MannequinAuthor

      New version detects DST using time.daylight flag.

      utcoffset = -(time.altzone if time.daylight else time.timezone) // 60

    10. briancurtin commented on Jan 9, 2010

      @briancurtin
      Member

      Using time.daylight is incorrect. time.daylight specifies the number of hours that the daylight offset is, not a flag to specify whether or not daylight savings time is in effect.

      Steven's suggestion of using time.localtime().tm_isdst seems to be the better route.

    11. techtonik commented on Jan 10, 2010

      techtonikmannequin
      MannequinAuthor

      Brian, documentation says quite the opposite.

      time.daylight
      Nonzero if a DST timezone is defined.
      http://docs.python.org/library/time.html?highlight=daylight#time.daylight

    12. briancurtin commented on Jan 10, 2010

      @briancurtin
      Member

      The documentation could use some work. It means that if the timezone does use a daylight savings time period, time.daylight specifies the amount of the offset. In my timezone this value is 1. However, time.localtime().is_dst is currently 0, because we are not on savings time.

      For that reason, using time.daylight in your patch gives an incorrect result for me.

    13. briancurtin commented on Jan 10, 2010

      @briancurtin
      Member

      http://msdn.microsoft.com/en-us/library/2t504ch6%28VS.80%29.aspx has some info for how this is implemented on Windows, and I get the same results on my Mac.

      On Linux an AttributeError is raised time.struct_time not having an attribute is_dst, and time.daylight matches the other two platforms.

    14. briancurtin commented on Jan 10, 2010

      @briancurtin
      Member

      Whoops, nevermind the Linux comment on that last one. My typo there caused the exception. The result there is the same as the other platforms.

    15. 6 remaining items

    16. techtonik commented on Feb 10, 2010

      techtonikmannequin
      MannequinAuthor

      I use this tool in instructions how to generate patches on windows, so I am interested to see this fix in the version, that users will likely to use for next couple of years, but I'd be happy to see this committed in any branch.

      If it is going to be committed in alpha only them I'd like to propose to change default diff format to unicode as well.

      Please, also review http://bugs.python.org/issue7585 that contains more important API change that also prevents diff.py from generating correct patches.

    17. amauryfa commented on Feb 10, 2010

      @amauryfa
      Contributor

      I'd like to propose to change default diff format to unicode as well
      What kind of "unicode" format is it?

    18. techtonik commented on Feb 11, 2010

      techtonikmannequin
      MannequinAuthor

      I am sorry - too much windows to reply. This must be *unified*, of course.

    19. techtonik commented on Feb 16, 2010

      techtonikmannequin
      MannequinAuthor

      Ok. Let's commit it at least to 2.7 - I'll create a separate issue for discussion of unified diff format later.

    20. techtonik commented on Apr 28, 2010

      techtonikmannequin
      MannequinAuthor

      So, what about 2.7 ?

    21. briancurtin commented on Apr 28, 2010

      @briancurtin
      Member

      2.7 is now frozen as far as new features go. It's still good for 3.2.

      I think this is ready to go, so I'll probably commit it later in the day.

    22. techtonik commented on Apr 28, 2010

      techtonikmannequin
      MannequinAuthor

      I still do not understand your policy - it is a tool, it is not a part of standard library.

    23. techtonik commented on Jun 5, 2010

      techtonikmannequin
      MannequinAuthor

      Adding Alexander as ISTM he may be interested to read the time discussion.

    24. abalkin commented on Jun 5, 2010

      @abalkin
      Member

      The latest patch will produce wrong results if the file was last modified before timezone rules changed in your location. See bpo-1647654.

    25. self-assigned this
      on Jun 5, 2010
    26. changed the title [-][patch] diff.py to use iso timestamp[/-] [+]Use ISO timestamp in diff.py[/+] on Jul 4, 2010
    27. python-dev commented on Jun 22, 2012

      python-devmannequin
      Mannequin

      New changeset ec95b94ea831 by Alexander Belopolsky in branch 'default':
      Issue bpo-7582: Use ISO timestamp in diff.py
      http://hg.python.org/cpython/rev/ec95b94ea831

    28. techtonik commented on Jun 22, 2012

      techtonikmannequin
      MannequinAuthor

      Thanks. I am glad OS TZ support finally issue took off. =)

    29. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions