5

In Chile the case is very particular as the days of daylight saving changes are different a year from another...

Is there a function to get for given day at given UTC time the UTC offset?

I saw on a Suse documentation that something like zdump -v /usr/share/zoneinfo/Chile/Continental makes me enable to get all changings through years, but the job has to be done still... any command to do that?

Or/and is there a function with a given date and time from given timezone to UTC? And its reverse?

How does linux handle these changes? didn't find more documentation than Suse one.

Philippe Gachoud
  • 1,517
  • 15
  • 20

2 Answers2

5

You can use the date command. You set the timezone and then specify the date and time. The command will return that time with the -03 or -04, so you will know if DST was in effect.

For example, for Chile/Continental:

Before DST change this year:

$ TZ=Chile/Continental date --date='2020-04-03 11:00 +00'
Fri Apr  3 11:00:00 -03 2020

After DST change this year:

$ TZ=Chile/Continental date --date='2020-04-06 11:00 +00'
Mon Apr  6 11:00:00 -04 2020

To undo that, just set TZ to UTC and change the offset:

$ TZ=UTC date --date='2020-04-03 11:00 -04'
Eduardo Trápani
  • 1,140
  • 6
  • 10
  • Many thx, to be precise, up to you if you want to edit your answer, to get the offset I had to add `+%z` to get `-0300` or `-0400` so the complete command would be `TZ=Chile/Continental date --date='2020-04-03 11:00 +00' +%z` – Philippe Gachoud Jun 09 '20 at 09:33
  • Strange... Just to confirm ¿you don't see the `-04` after the hour and right before the `2020` in the output? This is the actual result in my system: `Mon Apr 6 11:00:00 -04 2020`. – Eduardo Trápani Jun 09 '20 at 13:49
  • 1
    Yes, I see it thx, but I have to parse it then... as my question was about getting only the UTC offset. You showed me the way than for anybody looking for the offset without parsing it with awk etc... but got the same result as you. – Philippe Gachoud Jun 09 '20 at 14:30
0

Based on Eduardo Trápani's answer, the final answer for me was

  • TZ=Chile/Continental date --date='TZ=Chile/Continental date --date='2020-04-05 02:00:15 +00' +%z which gives -0300
  • TZ=Chile/Continental date --date='2020-04-05 04:00:15 +00' +%z which gives -0400

List zones

ls -l /usr/share/zoneinfo/

See details of a particular zone

zdump -v /usr/share/zoneinfo/Chile/Continental

Philippe Gachoud
  • 1,517
  • 15
  • 20