This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Use ISO timestamp in diff.py
Type: enhancement Stage: resolved
Components: Demos and Tools Versions: Python 3.2
process
Status: closed Resolution: fixed
Dependencies: 1647654 9527 Superseder:
Assigned To: belopolsky Nosy List: amaury.forgeotdarc, barry, belopolsky, djc, eric.araujo, python-dev, srumbalski, techtonik
Priority: normal Keywords: needs review, patch

Created on 2009-12-27 15:57 by techtonik, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
diff.py_iso_timestamps.diff techtonik, 2009-12-27 15:57 review
diff.py_iso_timestamps_true.diff techtonik, 2009-12-29 00:50 flawless review
diff.py_iso_timestamps_true_with_dst.diff techtonik, 2010-01-09 16:58 also detects dst review
diff.py_iso_timestamps_true_with_true_dst.diff techtonik, 2010-02-09 11:27 active dst review
Messages (29)
msg96912 - (view) Author: anatoly techtonik (techtonik) Date: 2009-12-27 15:57
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.
msg96922 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2009-12-27 20:45
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.
msg96929 - (view) Author: anatoly techtonik (techtonik) Date: 2009-12-27 22:12
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.
msg96962 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-12-28 17:59
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
msg96978 - (view) Author: anatoly techtonik (techtonik) Date: 2009-12-28 23:55
Thanks! Now the most elegant patch I could think out.
msg96979 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2009-12-29 00:30
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.
msg96981 - (view) Author: anatoly techtonik (techtonik) Date: 2009-12-29 00:50
Pepeighfied and regenerated. Should be flawless now.
msg97272 - (view) Author: Steven Rumbalski (srumbalski) Date: 2010-01-05 19:17
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
msg97460 - (view) Author: anatoly techtonik (techtonik) Date: 2010-01-09 16:58
New version detects DST using time.daylight flag.

utcoffset = -(time.altzone if time.daylight else time.timezone) // 60
msg97471 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-09 21:22
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.
msg97503 - (view) Author: anatoly techtonik (techtonik) Date: 2010-01-10 10:36
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
msg97539 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-10 18:46
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.
msg97540 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-10 18:57
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.
msg97546 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-01-10 20:10
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.
msg99092 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-09 08:05
So, is that right that even if time.daylight specifies the offset, this doesn't mean that this offset is active?

MS documentation you referenced is unclear: "The _get_daylight function retrieves the number of hours in daylight saving time as an integer. If daylight saving time is in effect, the default offset is one hour."

From this description it is easy to assume that if DST is not in effect then default offset would be 0.
msg99096 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-09 08:44
You are right.
----[pydst.py]------
import time

print time.asctime()
print time.localtime().tm_isdst
print time.daylight
--------------------

Tue Feb 09 10:31:47 2010
0
1

Sun May 09 10:33:20 2010
1
1


There is already an issue #7229 to correct the docs. I'll adjust my patch accordingly. Thanks for collaboration.
msg99108 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-09 11:27
Finally! (I really hope so)
msg99163 - (view) Author: Barry A. Warsaw (barry) * (Python committer) Date: 2010-02-10 14:08
This seems like a new feature to me so I'm removing 2.6 from the list.  My browser won't let me remove Python 3.1.
msg99166 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-10 15:38
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.
msg99171 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2010-02-10 15:57
> I'd like to propose to change default diff format to unicode as well
What kind of "unicode" format is it?
msg99200 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-11 05:49
I am sorry - too much windows to reply. This must be *unified*, of course.
msg99393 - (view) Author: anatoly techtonik (techtonik) Date: 2010-02-16 10:46
Ok. Let's commit it at least to 2.7 - I'll create a separate issue for discussion of unified diff format later.
msg104419 - (view) Author: anatoly techtonik (techtonik) Date: 2010-04-28 08:29
So, what about 2.7 ?
msg104430 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) Date: 2010-04-28 13:58
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.
msg104439 - (view) Author: anatoly techtonik (techtonik) Date: 2010-04-28 16:57
I still do not understand your policy - it is a tool, it is not a part of standard library.
msg107152 - (view) Author: anatoly techtonik (techtonik) Date: 2010-06-05 17:16
Adding Alexander as ISTM he may be interested to read the time discussion.
msg107154 - (view) Author: Alexander Belopolsky (belopolsky) * (Python committer) Date: 2010-06-05 17:28
The latest patch will produce wrong results if the file was last modified before timezone rules changed in your location.  See issue1647654.
msg163434 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-06-22 16:48
New changeset ec95b94ea831 by Alexander Belopolsky in branch 'default':
Issue #7582: Use ISO timestamp in diff.py
http://hg.python.org/cpython/rev/ec95b94ea831
msg163448 - (view) Author: anatoly techtonik (techtonik) Date: 2012-06-22 18:00
Thanks. I am glad OS TZ support finally issue took off. =)
History
Date User Action Args
2022-04-11 14:56:55adminsetgithub: 51831
2012-06-22 18:00:30techtoniksetmessages: + msg163448
2012-06-22 17:37:53belopolskysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2012-06-22 16:48:30python-devsetnosy: + python-dev
messages: + msg163434
2010-12-30 22:14:16georg.brandlunlinkissue7962 dependencies
2010-10-05 18:02:52belopolskysetdependencies: + Add aware local time support to datetime module
2010-07-05 21:19:08brian.curtinsetnosy: - brian.curtin
2010-07-04 16:58:32eric.araujolinkissue7962 dependencies
2010-07-04 16:33:30eric.araujosettitle: [patch] diff.py to use iso timestamp -> Use ISO timestamp in diff.py
2010-06-05 17:28:33belopolskysetassignee: belopolsky
dependencies: + No obvious and correct way to get the time zone offset
messages: + msg107154
2010-06-05 17:16:27techtoniksetnosy: + belopolsky
messages: + msg107152
2010-04-28 16:57:08techtoniksetmessages: + msg104439
2010-04-28 13:58:23brian.curtinsetmessages: + msg104430
versions: - Python 2.7
2010-04-28 08:29:37techtoniksetmessages: + msg104419
2010-02-16 12:33:56djcsetnosy: + djc
2010-02-16 10:46:55techtoniksetmessages: + msg99393
2010-02-16 04:53:21eric.araujosetnosy: + eric.araujo
2010-02-11 05:49:56techtoniksetmessages: + msg99200
2010-02-10 15:57:32amaury.forgeotdarcsetmessages: + msg99171
2010-02-10 15:38:29techtoniksetmessages: + msg99166
2010-02-10 15:00:48brian.curtinsetkeywords: + needs review
type: behavior -> enhancement
versions: - Python 3.1
2010-02-10 14:08:36barrysetnosy: + barry

messages: + msg99163
versions: - Python 2.6
2010-02-09 11:27:22techtoniksetfiles: + diff.py_iso_timestamps_true_with_true_dst.diff

messages: + msg99108
2010-02-09 08:44:29techtoniksetmessages: + msg99096
2010-02-09 08:05:30techtoniksetmessages: + msg99092
2010-01-10 20:10:53brian.curtinsetmessages: + msg97546
2010-01-10 18:57:54brian.curtinsetmessages: + msg97540
2010-01-10 18:46:22brian.curtinsetmessages: + msg97539
2010-01-10 10:36:46techtoniksetmessages: + msg97503
2010-01-09 21:22:36brian.curtinsetpriority: normal

messages: + msg97471
stage: patch review
2010-01-09 16:58:30techtoniksetfiles: + diff.py_iso_timestamps_true_with_dst.diff

messages: + msg97460
2010-01-05 19:17:25srumbalskisetnosy: + srumbalski
messages: + msg97272
2009-12-29 00:50:41techtoniksetfiles: - diff.py_iso_timestamps_true.diff
2009-12-29 00:50:33techtoniksetfiles: + diff.py_iso_timestamps_true.diff

messages: + msg96981
2009-12-29 00:30:09brian.curtinsetmessages: + msg96979
2009-12-28 23:55:39techtoniksetfiles: + diff.py_iso_timestamps_true.diff

messages: + msg96978
2009-12-28 17:59:44brian.curtinsetnosy: + brian.curtin
messages: + msg96962
2009-12-27 22:12:54techtoniksetmessages: + msg96929
2009-12-27 20:45:02amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg96922
2009-12-27 15:57:56techtonikcreate