git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone
@ 2007-01-26  8:58 Andy Parkins
  2007-01-26  9:43 ` Andy Parkins
  2007-01-26 17:49 ` Simon 'corecode' Schubert
  0 siblings, 2 replies; 3+ messages in thread
From: Andy Parkins @ 2007-01-26  8:58 UTC (permalink / raw)
  To: git

I got bitten because in the UK (where one would expect 1970-01-01 00:00
to be UTC 0) some politicians decided to mess around with daylight
savings time from 1968 to 1971; it was permanently BST (+0100).  That
means that on my computer the following is true:

$ date --date="1970-01-01 00:00" +"%F %T %z (%Z)"
1970-01-01 00:00:00 +0100 (BST)

This of course means that the --date argument to date is specified in
local time, not UTC.  So when the hooks--update script does this:

date=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds")

It's actually saying (in my timezone) "1970-01-01 01:00:00 UTC" + $ts.
Clearly this is wrong.  The UNIX epoch started at midnight UTC not 1am
UTC.

This leads to the tagged time in hooks--update being shown as one hour
earlier than the true tagged time (in my timezone).  The problem would
be worse for other timezones.  For a +1300 timezone on 1970-01-01, the
tagged time would be 13 hours earlier.  Oops.

The solution is to force the reference time to UTC, which is what this
patch does.  In my timezone:

$ date --date="1970-01-01 00:00 +0000" +"%F %T %z (%Z)"
1970-01-01 01:00:00 +0100 (BST)

Much better.

Signed-off-by: Andy Parkins <andyparkins@gmail.com>
---
 templates/hooks--update |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/templates/hooks--update b/templates/hooks--update
index 9863a80..81f706f 100644
--- a/templates/hooks--update
+++ b/templates/hooks--update
@@ -46,7 +46,7 @@ then
 		if [ "$ref_type" = tag ]; then
 			eval $(git cat-file tag $3 | \
 				sed -n '4s/tagger \([^>]*>\)[^0-9]*\([0-9]*\).*/tagger="\1" ts="\2"/p')
-			date=$(date --date="1970-01-01 00:00:00 $ts seconds" +"$date_format")
+			date=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds" +"$date_format")
 			echo "Tag '$tag' created by $tagger at $date"
 			git cat-file tag $3 | sed -n '5,$p'
 			echo
-- 
1.5.0.rc2.g017f3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone
  2007-01-26  8:58 [PATCH 1/2] UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone Andy Parkins
@ 2007-01-26  9:43 ` Andy Parkins
  2007-01-26 17:49 ` Simon 'corecode' Schubert
  1 sibling, 0 replies; 3+ messages in thread
From: Andy Parkins @ 2007-01-26  9:43 UTC (permalink / raw)
  To: git

On Friday 2007 January 26 08:58, Andy Parkins wrote:

> This of course means that the --date argument to date is specified in
> local time, not UTC.  So when the hooks--update script does this:
>
> date=$(date --date="1970-01-01 00:00:00 +0000 $ts seconds")

Bugger.  This description is wrong.  I've shown the fixed version not the 
original.  This line should have read

 date=$(date --date="1970-01-01 00:00:00 $ts seconds")

Sorry - patch was fine, message needs that change to make sense though.


Andy
-- 
Dr Andy Parkins, M Eng (hons), MIEE
andyparkins@gmail.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone
  2007-01-26  8:58 [PATCH 1/2] UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone Andy Parkins
  2007-01-26  9:43 ` Andy Parkins
@ 2007-01-26 17:49 ` Simon 'corecode' Schubert
  1 sibling, 0 replies; 3+ messages in thread
From: Simon 'corecode' Schubert @ 2007-01-26 17:49 UTC (permalink / raw)
  To: Andy Parkins; +Cc: git

[-- Attachment #1: Type: text/plain, Size: 632 bytes --]

Andy Parkins wrote:
> $ date --date="1970-01-01 00:00" +"%F %T %z (%Z)"
> 1970-01-01 00:00:00 +0100 (BST)

nice observation.  yet, my system doesn't even have date --date=.  regarding the idea to provide a generic nice hook, it should be considered to convert this usage to a standards-conforming way.

cheers
  simon

-- 
Serve - BSD     +++  RENT this banner advert  +++    ASCII Ribbon   /"\
Work - Mac      +++  space for low €€€ NOW!1  +++      Campaign     \ /
Party Enjoy Relax   |   http://dragonflybsd.org      Against  HTML   \
Dude 2c 2 the max   !   http://golden-apple.biz       Mail + News   / \


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 252 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-01-26 17:49 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-26  8:58 [PATCH 1/2] UNIX reference time of 1970-01-01 00:00 is UTC timezone, not local time zone Andy Parkins
2007-01-26  9:43 ` Andy Parkins
2007-01-26 17:49 ` Simon 'corecode' Schubert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).