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.

3 Answers3

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'
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

0

I found your question, and the following solution was already enough. Keep it short and simple.

TIMEZONE=$(date '+%Z')
if [ "$TIMEZONE" == "JST" ]
then
        echo +09
fi

Maybe it can help others finding this question,too.

Franz
  • 101