Hacker News new | ask | show | jobs
by kseistrup 3401 days ago
It would be highly inconvenient to have to set this variable if you live in a country where you change the timezone twice a year due to summertime.
5 comments

If TZ is set properly then you don't need to change it twice a year.

(man tzset for more info and examples of different values TZ can be set to. Mine is set to "Europe/London" which handles the DST switches automatically.)

Hm…, now that I read TZSET(3): Wouldn't that be

    TZ=:Europe/London
It doesn't seem tzset() will accept the format

    TZ=Europe/London

?
Yes, but " If the colon is omitted each of the above TZ formats will be tried." , so it'll be figured out even if the colon is missing.
Ah yes, thanks for pointing that out!
Are you talking about DST? You don't change your timezone at DST switch, the timezone data knows how to calculate the correct time based on your location (roughly) and the time of year. Mountain standard time and mountain daylight time are both part of mountain time, for example.
What I meant was: Currently my timezone is CET. In a month's time it will be CEST. If I have to set TZ to explicitly mirror that it will be a burden.
TZ may be set like this:

   TZ=:Europe/Copenhagen
Replace Europe/Copenhagen with the appropriate entry from the list: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones

Usually, /etc/localtime is a symlink, as on my laptop:

  /etc/localtime -> /usr/share/zoneinfo/Europe/Copenhagen
so TZ=:/etc/localtime has the same result.

You can demonstrate that it takes account of changes to timezones:

Normal time for London:

  $ TZ=:Europe/London date -d '1995-12-30 12:00 UTC' -R
  Sat, 30 Dec 1995 12:00:00 +0000
British Summer Time:

  $ TZ=:Europe/London date -d '1995-06-30 12:00 UTC' -R
  Fri, 30 Jun 1995 13:00:00 +0100
'Double British Summer Time', used for a period during World War 2:

  $ TZ=:Europe/London date -d '1945-06-30 12:00 UTC' -R
  Sat, 30 Jun 1945 14:00:00 +0200
Before London's time was standardized to Greenwich:

  $ TZ=:Europe/London date -d '1845-06-30 12:00 UTC' -R
  Mon, 30 Jun 1845 11:58:45 -0001
wait, so when I did `echo $TZ`, to check, and got `Europe/Amsterdam` that means it's already properly and I did't need to set it to `:/etc/localtime`?

this is not a part of Linux I'm very familiar with

Thanks!
Do all your work in UTC. Seriously, you'll be glad later.

Convert to local time only on the edges, and only for end users.

All my VPSes run in UTC, no exception. What I'm talking about here is my desktop machine. I strongly prefer to run that in localtime.
If you set your machine to the DST timezone for your political unit, then the displayed time will automatically jump back and forth on the correct dates, as long as your time database is reasonably up-to-date; you don't need to manually change from non-DST to DST & back.

The non-DST timezones are for those who are lucky enough to live in political units which tell DST to get bent, and just stay on real time all year long.

DST delenda est.

Thanks, I didn't know that.

I believe I prefer the

    TZ=:Continent/City
notation in this case, though.
Starting or stopping Daylight Saving Time is not a timezone change. A timezone is — roughly — a set of timekeeping rules that some set of people use. DST is just part of those timekeeping rules. That is, your timezone is not the same thing as your UTC offset.

For example, the timezone America/New_York contains information not only about the UTC offset, but the offset during and not during DST, and when DST starts and ends. (And historical starts and ends to, so that UTC → local conversions (and vice versa) use the rules that were present at that time, not the rules that are present now, which may be different.)

E.g., my home desktop runs in the timezone America/Los_Angeles all year around. Most of my servers run in the timezone UTC all year. Both always have the appropriately correct time.

TZs should be defined in the form "Europe/London", "Asia/Beirut", "Pacific/Auckland", etc.

Although the hour offset can change at extremely short notice (e.g. discontinuing Daylight Savings during Ramadan [1]), the timezone declaration (e.g. "Africa/Casablanca"), shouldn't need to change, just the underlying timezone database.

[1] https://en.wikipedia.org/wiki/Daylight_saving_time_in_Morocc...

That's not how I read TZSET(3). According to TZSET(3) you can either use (example for Copenhagen shown)

    TZ=CET
or

    TZ=:Europe/Copenhagen
but not

    TZ=Europe/Copenhagen
Apologies, I didn't explain my response very well.

You're totally right to say that in the context of TZSET, to load the timezone specification from a TZ-formatted file it needs to be prefixed with ':'.

Rather than saying "Technically, you should set the value of TZ to 'Europe/London'", I was trying to say that my philosophical opinion of timezone recording - whether in a CMS, on an O/S level, in a compiled app, etc - is that it should start with the standard of geographical location.

There might be occasions to augment that with other data, maybe including the UTC offset for that TZ at a particular time, but the TZ specification can be subject to frequent change, whilst a description such as "Europe/London" changes infrequently and seems to have the least ambiguity.

Ok, we agree then.