Using the Zic Timezone Compiler on Linux

Having trouble setting your correct time zone? Is your watch setting the wrong time? In Linux, the time depends on the time zone you set and if the time zone is not correct, then you will constantly have problems with your time.

The good news is that there is a way to fix this using the zic timezone compiler. If you’re wondering what zic is, it’s a Linux program that reads the time zone text from a file and creates the correct time conversion based on the given command and time zone. This guide covers using zic to set your time zone and the zic options available.

How to check your time zone

Before using zic, you should know your time zone. Luckily, you can easily check this from the command line with the following date command:

$ Date +” %Z %z”

Here we indicate alphabetic time zone with %Z and numeric time zone with %z.

In our example we see that the time zone EAT is around +0300.

Alternatively, you can run the following command:

$cat /etc/timezone

Your time zone is still displayed.

How to use the Zic time zone compiler

zic’s main job is to read a file’s inputs and use them to compress your timezone and give correct time conversion.

The basic syntax is:

$zic [option] [filename]

The file that zic reads is the time zone database (tzdate). The tzdate contains the data and code with the history of local time for most time zones around the world. Also, the data is updated regularly, and you just need to download it and compile it with zic.

click here to download the tzdata.tar.gz. Once downloaded, extract the archive files to a folder of your choice. In our case we will extract it by Downloads/Timezone.

Open the extracted folder. It should contain different files as in the following image:

You will find that there are files with different time zones. Because of this, you need to know your time zone to continue to the next step.

You now need to compile a file based on your time zone. For example, if your time zone is EAT, your file is called Africa. So to compile it, append its name to zic as shown in the following command:

$zic Africa

You need root to run the command. After compression, you must copy the file to the zoneinfo/ directory.

Again, the path to the zone info depends on your location. If you open /usr/share/zoneinfo/ you will see the list of available zones.

The different locations are listed above. Navigate to the directory in your time zone. You will see the different areas under the time zone.

Still in the directory where you Zic compiled your file, copy the file to the path with your timezone. For example, to copy the file for the Africa time zone, the command is:

$ cp africa usr/share/zoneinfo/Africa/

You may need to reboot your system and after the reboot check the time zone with “+z” as before. It should now show the exact time.

The time zone database contains files for the different locations. Each of these files contains ruled lines with a specific format. The format of a rule line is:

Rule ENTER NAME FROM TO SAVE LETTERS/S

The different fields in the rule line represent different things.

NAME: Represents the name that contains the rules, and in most cases it is the name of the time zone.

FROM: The first year that the specified rule applies.

TO: The last year the rule applies.

TYPE: By default it’s set to – but if it’s something else the zic will run the type of year set.

IN: The month in which the rule applies.

A: The day of the month. Here you can have different formats. For example, 4 represents the 4th of the month. A format like Mon>=7 represents the first Monday or any day after the 7th of the month.

AT: It represents the exact time of day.

SAVE: When the rule is applied. This option specifies the time that is to be added to the currently set local time.

LETTER/S: It can be the abbreviation for the time zone.

When defining a zone, the format is as follows:

Zone NAME UTCOFF RULES/SAVE FORMAT [UNTIL]

In the previous figure, STDOFF represents the time to be added to the local standard time. RULES is the name of the rule to apply. FORMAT is the format for the abbreviation of the time zone. Also, UNTIL indicates when the location rule changes.

Conclusion

If you’re using the Zic timezone compiler, your best resource is the man page. There are countless options that you can use to optimize the time conversion. In this guide, we’ve covered how to compile the time from a time zone database file. We also saw how a rule is defined. With the details discussed, you can combine the available options and tweak the time conversion according to your needs.

Related Posts