{"thread":{"id":"62920","subject":"Config timezone to prevent chaos when DST/changing timezone","startedAt":"2025-02-07T22:02:33Z","lastAt":"2025-02-08T21:54:29Z","messageCount":4,"participants":["Devste Devste","brian m. carlson","Andreas Schwab","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"512121","messageId":"CANM0SV3DXQeNinmy1Spj7n6G=5s3jMcFrAb0Ayun6ago7F3qWw@mail.gmail.com","threadId":"62920","inReplyTo":null,"subject":"Config timezone to prevent chaos when DST/changing timezone","fromName":"Devste Devste","fromEmail":"devstemail@gmail.com","sentAt":"2025-02-07T22:02:19Z","receivedAt":"2025-02-07T22:02:33Z","isPatch":false,"sender":{"key":"devstemail@gmail.com","avatar":null},"body":"Issue:\nWith DST or manual timezone changes (e.g. travelling) you can end up\nwith commits that are illogically sorted - newer commits have an\nauthor/committer date that is older than older commits.\n\nI found the discussion about user.hideTimezone\nhttps://public-inbox.org/git/CAEOYnAQYMrNAe9s1V-0DVLdL-B_KpHMDP5e=yRnbCkMWdrvFHQ@mail.gmail.com/T/#u\nand\nhttps://git.github.io/rev_news/2023/08/31/edition-102/\n\nWhile there are workarounds, these aren't possible in all cases (e.g.\n\"export TZ=UTC0\" won't work with many IDEs since they run git in a\nseparate shell and has side-effects on non-git commands. Using\npre/post-commit/rewrite/merge hooks won't guarantee it's correct e.g.\nif bypassing them if there checks in there that should be skipped)\n\nThere should be an easy way to force a specific timezone - or in\nabsence of that at least force UTC - to prevent this\n"},{"id":"512122","messageId":"Z6aNZ3qM1qsD5ZcG@tapette.crustytoothpaste.net","threadId":"62920","inReplyTo":"CANM0SV3DXQeNinmy1Spj7n6G=5s3jMcFrAb0Ayun6ago7F3qWw@mail.gmail.com","subject":"Re: Config timezone to prevent chaos when DST/changing timezone","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2025-02-07T22:47:03Z","receivedAt":"2025-02-07T22:47:12Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2025-02-07 at 22:02:19, Devste Devste wrote:\n> Issue:\n> With DST or manual timezone changes (e.g. travelling) you can end up\n> with commits that are illogically sorted - newer commits have an\n> author/committer date that is older than older commits.\n\nFirst of all, if the date and time displayed as local, it is very easy\nalready, without traveling, to end up with one time of a later commit\nbefore the other (ignoring the time zone) simply because different\npeople are in different time zones.  I'm sure I could give you a large\nnumber of examples in a variety of projects.\n\nSecond, Git doesn't guarantee a strict ordering of author or committer\ndate in timestamps.  It is very possible with a rebase to place commits\nwith newer author timestamps before ones with older timestamps because\nthey logically go in that order.  And we don't force users to contact an\nNTP server or other reliable time source, so some people just have bad\ntimestamps altogether.\n\n> I found the discussion about user.hideTimezone\n> https://public-inbox.org/git/CAEOYnAQYMrNAe9s1V-0DVLdL-B_KpHMDP5e=yRnbCkMWdrvFHQ@mail.gmail.com/T/#u\n> and\n> https://git.github.io/rev_news/2023/08/31/edition-102/\n> \n> While there are workarounds, these aren't possible in all cases (e.g.\n> \"export TZ=UTC0\" won't work with many IDEs since they run git in a\n> separate shell and has side-effects on non-git commands. Using\n> pre/post-commit/rewrite/merge hooks won't guarantee it's correct e.g.\n> if bypassing them if there checks in there that should be skipped)\n> \n> There should be an easy way to force a specific timezone - or in\n> absence of that at least force UTC - to prevent this\n\nThe standard way to set the timezone is setting `TZ`.  You can set it in\nyour `GIT_EDITOR` environment variable, which will be passed to the\nshell, like so:\n\n  export GIT_EDITOR=\"TZ=UTC vi\"\n\n(or the `core.editor` value, or any other approach).  This will invoke\nthe editor with the appropriate value so it works correctly.\n\nPart of the problem with setting it in Git is that Git doesn't actually\nhave a way to set the timezone other than the `TZ` environment variable\nbecause POSIX doesn't offer other approaches for doing so (or, for that\nmatter, enumerating valid values or verifying a value).  In addition,\nWindows uses a different, completely incompatible set of time zone names\nfrom everyone else on the planet, so such a setting would not work\ngracefully in a cross-platform way for arbitrary time zones.\n\nFor these reasons, reading an arbitrary time zone from the configuration\nwould require setting `TZ` internally and then calling `tzset`, but that\nfunction is not thread safe, which substantially restricts the places\nconfiguration parsing and handling can be done in our code.  It would\nalso create a bunch of headaches if we tried to load submodules\nrepository data in the same process (which is an eventual goal), leading\nto hard-to-reproduce problems.\n\nIn my case, I always set `TZ=UTC` in my `.zshenv` and I specifically\ninvoke my shell in `~/.Xsession` before starting the session manager.\nFor instance:\n\n  zsh -c 'mate-session'\n\nThis ensures that all programs are started with the `PATH`, `TZ`, and\nlocale values I want for them, including graphical programs.  If you\ndon't do that, then graphical programs you start outside of a terminal\nalso don't honor `PATH` or locale settings (for instance, I always force\n`LC_TIME=en_DK.UTF_8`, which I want for graphical programs as well).\n\nAs for hooks not working, if you have a policy requirement to use UTC,\nthen check for that in your server `pre-receive` hook or CI system,\nwhere those can be used as an effective control, as the Git FAQ\nmentions.\n-- \nbrian m. carlson (they/them or he/him)\nToronto, Ontario, CA\n"},{"id":"512130","messageId":"87seooss2u.fsf@linux-m68k.org","threadId":"62920","inReplyTo":"CANM0SV3DXQeNinmy1Spj7n6G=5s3jMcFrAb0Ayun6ago7F3qWw@mail.gmail.com","subject":"Re: Config timezone to prevent chaos when DST/changing timezone","fromName":"Andreas Schwab","fromEmail":"schwab@linux-m68k.org","sentAt":"2025-02-08T09:28:57Z","receivedAt":"2025-02-08T09:38:09Z","isPatch":false,"sender":{"key":"schwab@linux-m68k.org","avatar":"https://avatars.githubusercontent.com/u/2175493?v=4"},"body":"On Feb 07 2025, Devste Devste wrote:\n\n> With DST or manual timezone changes (e.g. travelling) you can end up\n> with commits that are illogically sorted - newer commits have an\n> author/committer date that is older than older commits.\n\nThe time stamps in commits are recorded in Universal Time, so neither\nDST nor timezone changes (both are essentially equivalent) have an\ninfluence on how the time stamp is interpreted as a point in time.\n\n> There should be an easy way to force a specific timezone - or in\n> absence of that at least force UTC - to prevent this\n\nYou can use --date=local to show all dates in your local time zone,\ninstead of the recorded time zone of the author/committer.\n\n-- \nAndreas Schwab, schwab@linux-m68k.org\nGPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1\n\"And now for something completely different.\"\n"},{"id":"512143","messageId":"xmqqfrkodrvx.fsf@gitster.g","threadId":"62920","inReplyTo":"87seooss2u.fsf@linux-m68k.org","subject":"Re: Config timezone to prevent chaos when DST/changing timezone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2025-02-08T21:54:26Z","receivedAt":"2025-02-08T21:54:29Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Andreas Schwab <schwab@linux-m68k.org> writes:\n\n> On Feb 07 2025, Devste Devste wrote:\n>\n>> With DST or manual timezone changes (e.g. travelling) you can end up\n>> with commits that are illogically sorted - newer commits have an\n>> author/committer date that is older than older commits.\n>\n> The time stamps in commits are recorded in Universal Time, so neither\n> DST nor timezone changes (both are essentially equivalent) have an\n> influence on how the time stamp is interpreted as a point in time.\n\nThe commits will be sorted correctly according to time, regardless\nof the recorded timezone.  Thanks for pointing it out.\n"}]}