Some views on having your system timezone set to UTC
utcc.utoronto.ca
utcc.utoronto.ca
In my experience most people, including most developers but perhaps excluding many HN readers, don't understand what the timezone setting does. The time on all contemporary computers is always Unix Epoch Time, which is close to (but not exactly) UTC. Setting your timezone doesn't actually change anything about how time works on the computer. It just changes how time is printed. That's it.
So the second problem is that our text-based server world, for all its benefits, doesn't cope well with per-user parameters. I mean ... timezone support on Unix is basically buggy. It doesn't matter what TZ I set in my .profile, nevertheless the timezone of logs is in whatever TZ the server is running in. That's pretty stupid. And even simple calculations like "how many seconds elapsed between this log entry and this one" - which is really common - are very difficult, regardless of the TZ setting.
In my own personal perfect world, all logs would be printed in the first column of log files using the epoch time in seconds, and we'd have a command which would convert from the epoch time to the local timezone. So we could do something like:
tail -f /var/log/messages | grep 'panic' | timestamp
...in which case I would be able to choose the timezone and format of the timestamps to meet the needs of the job i was doing.So for me, this whole argument over UTC is dumb. It doesn't matter what timezone the system is set to; any zone can be "default". The real problem is that different users have different time formatting requirements, and to date we haven't had tools which deal with that properly.
(even logging all timestamps consistently in ISO format would be a big step up...)
[1] http://smarden.org/runit/svlogd.8.html
I think the insistence on UTC is a case of "a little knowledge". What happens is some developer somewhere has to learn the hard way about time zones. Now he could either learn about the problem in depth or he finds the shortcut solution: just use UTC. He's now unlikely to ever get bitten again, but he never really learnt what the problem was. He now tells other developers to use UTC and many will blindly follow.
In that way it's a bit like the whole insistence on spaces over tabs. Another instance of "a little knowledge" and losing the power of the tab character as a result.
Now, as Europe got some sanity and will abandon time shifts the next year, local time as long as as it comes with time zone will be OK. But out of habit I guess I will continue to configure servers to use UTC.
Unfortunately it is Unix time that has a real discontinuity. This happens around leap seconds when Unix time will jump backwards or forwards by a whole number of seconds. This is actually the fault of UTC, though. Leap seconds are an abomination. Unix had the right idea all along which is to just count a number of seconds since an epoch and not worry about the movements of the solar system.
For a small number of input formats `ts` from Joey Hess' moreutils¹ can do this. Its `-r` option pulls dates out of its input and reformats them, either as a relative timestamp by default(33m57s ago) or a user-specified format if given.
Your example becomes `tail | grep | ts -r %FT%T` or something like that.
It supports syslog format, a subset of ISO-8601, and a few others. It doesn't support epoch in seconds though, but Joey is nice to interact with if you were to offer a patch.
---
This, among other reasons, is why I like all my logging going through systemd's journal nowadays. With journalctl you have a good choice of output options for date formatting or dumping as JSON if you want more.
I think Windows computers set the hardware clock to local time by default, actually.
Windows, Linux, macOS, all set the timezone value to 0x07FF which is defined as EFI_UNSPECIFIED_TIMEZONE which is to be treated as local time (but without a timezone).
In effect, it's the same mess as BIOS. It shows how specs can just be thwarted.
It's gotten so bad that I've made binary [1] and text [2] formats that handle all cases and have sane defaults (yes, even ISO8601 gets it wrong).
A time value without accompanying time zone data is just a bug waiting to happen. Once you add unambiguous timezone information to the time structure, getting correct time information every time is just a matter of making conversion libraries for language X. No more guesswork, no more bugs.
[1] https://github.com/kstenerud/compact-time/blob/master/compac...
[2] https://github.com/kstenerud/concise-encoding/blob/master/ct...
Another problem with ISO8601 is that omitting the time zone info implies floating time rather than UTC time, and this causes no end of bugs in all implementations.
When I finally gave up on it, I came up with the following alternative:
Time zone data omitted (implies UTC):
2019-01-23/14:08:51.941245 = January 23, 2019, at 14:08:51 and 941245 microseconds, UTC
Area/location based timezone:
1985-10-26/01:20:01.105/America/Los_Angeles = October 26, 1985, at 1:20:01 and 105 milliseconds, Los Angeles time
Latitude/longitude based timezone:
5192-11-01/03:00:00/48.86/2.36 = November 1st, 5192, at 3:00:00, at whatever is in the place of Paris at that time
What the GP is suggesting is exactly doing the same thing for time. If the internal format is always UTC, that doesn't mean timezones are going away for the user, just that they shouldn't show up in the data layer.
https://infiniteundo.com/post/25326999628/falsehoods-program...
Sure, but the only thing users normally see is that printed representation. What's the actual problem you see here?
> I mean ... timezone support on Unix is basically buggy. It doesn't matter what TZ I set in my .profile, nevertheless the timezone of logs is in whatever TZ the server is running in.
I don't see what's buggy there. If you set a TZ in your .profile, logs produced by processes within the context of that .profile will be in your desired timezone. Processes outside that context look at the system timezone, configured using /etc/localtime.
The UTC system time crowd basically just wants all logs (that don't explicitly specify further) to be in a standard timezone that does not move, so that it can be reasoned about without a lot of context. Your perfect world with an epoch time in the first column does exactly that, with the downside of not meaning anything to a human without the timestamp-conversion command.
I agree we need better tools to deal with timestamps after the fact.
So my ideal would be to be able to set TZ and see logs in TZ time.
My ideal, to use epoch time instead of local time in logs, is because in a large number of cases I'm more interested in the relative time of log entries than the absolute time. Computing relative time (seconds intervals) between log entries is error prone.
I suppose in a sense I'm in both the UTC and non-UTC camp. On reflection, I agree that server logs should be in UTC. I just don't think I should have to read them in UTC or personally operate in UTC.
The ts tool mentioned above sounds perfect, and I'm gonna start playing with it...
This applies to e.g. Linux.
But the RTC in your computer might store localtime. I do recommend using UTC there no matter what. If dual-booting windows, this needs a little extra work[0].
[0]: https://wiki.archlinux.org/index.php/System_time#UTC_in_Wind...
It usually starts like this " but we're all in <tz> so we should just use that so no one needs to do any maths."
Then later when operations spread to elsewhere it becomes "but most stuff is still done in <original tz> so we will still use that and everyone in other places will just need to deal with it and use our 'real' tz."
Then when you are operating in 3 or 4 or 5 or more locations it is too late to change anything and you are screwed because now you are in some provincial timezone for 50% of your systems - complete with clock changes - and the rest are a mess of either in UTC or some other TZ local to that server with their own different clock changes to the original TZ. Chaos.
And you can guarantee that none of the log files have TZ in their timestamps because of that original "we're only in one TZ" mindset so why bother saying what TZ it is... From then on every time you look at a log or a database or a web UI or whatever you need to double guess the timezone.
For those that come after you, please please please if you can't use UTC then at the very least always show the timezone in your log files/UIs/etc even of it seems redundant at the time - in the future someone handling an incident or trying to fix a P1 bug on a Friday afternoon will thank you.
Whether being able to figure this out afterwards is important depends on your use case, of course.
> The extra second is displayed on UTC clocks as 23:59:60.
Note how it's not 23:59:59 repeated, and thus fully unambiguous
It is for example better to use the UTC timezone when you complain to your cloud provider with a support in another timezone.
It can also help to find poorly developed software that ignores timezones before it's too late.
If only, but unfortunately that's not how UNIX time works. Instead its more like number of days since epoch * 86400 + seconds since midnight. Which is 27 seconds different than simple seconds since epoch count. This is why I would advise against using UNIX timestamps for anything critical because they are fundamentally ambiguous
Yeah, the people who decided to do that were Wrong.
Fortunately it only really matters during leap seconds, and nothing stops you from doing it the right way and having your timestamps in actual seconds since epoch and then converting to "Unix time" or anything else you need. See e.g. libtai:
> For timestamp with time zone, the internally stored value is always in UTC (Universal Coordinated Time, traditionally known as Greenwich Mean Time, GMT). An input value that has an explicit time zone specified is converted to UTC using the appropriate offset for that time zone.
[0] https://www.postgresql.org/docs/current/datatype-datetime.ht...
Which also requires you to store the TZ location (ie city) and not just the name or offset of the timezone itself.
For planned events, it becomes really hard to determine what to do when changing locale.
Edit: The other thing about examining logs is that I don't care what local time it occurred. Once an incident is identified all I care about is the time of the incident which can all be in UTC, my mind is at those hours while reading logs from every source.
You could convert to UTC for display purposes, when possible. It's not always possible for times in the future, but that's a concept people are already used to: you can't reliably convert a future time stamp between local time zones, either.
pretty useful when you need to track DST on a system which is otherwise all UTC.
Whatever you do pick, you definitely want to avoid Daylight Savings Time because it’s not just twice a year - it’s a different twice a year depending on which years (laws enacted it, and have moved it multiple times).
It just happens to be +00:00 to UTC all year right now.
Iceland had DST in the 1960s.
The UK had "Double Summer Time" during WW2, and I believe again in the 1970s. Granted that was before computers but still.
If you are lucky it shows your wall clock time.
If you are not lucky you need to do take into account the shift, which is part of the string.
Then there are their research partners, which again may be scattered around the world, etc.
So, no not customers in the traditional sense, but they depend on University services, and many of them are paying for the privilege.
I gave up after missing meetings a couple times this way.
I don't understand this at all. I have run all servers in UTC for as long as I can remember. I've run a few teams with very large server fleets.
Understanding that the time reported by a user needs to be converted is just part of the job. It becomes second nature quickly.
Even if all your users are in your local timezone, you will inevitably need to interact with vendors and systems in other places.
I don't get what calamity the author thinks they are avoiding.
Since I’m on the west coast, 7.5 months of the year we’re in the same time zone and for the other 4.5 it’s not hard to subtract 1. Crons don’t really need adjustment with the time change in pacific because off peak is still off peak.