The good news is that there is a way to fix this using the zic timezone compiler. If you wonder what zic is, it is a Linux program that reads the text containing the time zone from a file and creates the correct time conversion based on the specified command and timezone. This guide will cover the use of zic to set your timezone and the available zic options.
How to Check Your Timezone
Before using zic, you should know your timezone. Luckily, you can easily check that from the command line using the following date command:
Here, we display the alphabetic timezone using the %Z and the numeric timezone using the %z.
In our example, we see that the timezone is EAT at +0300.
Alternatively, you can run the following command:
It will still display your timezone.
How to Use the Zic Timezone Compiler
The main work of zic is to read the inputs of a file and use it to compress your timezone and give a correct time conversion.
The basic syntax is:
The file that zic reads is the time zone database (tzdate). The tzdate contains the data and code with the history of the local time for most timezone globally. Besides, the data gets periodically updated, and you only need to download it and compile it using 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 to Downloads/timezone.
Open the extracted folder. It should contain different files like in the following image:
You will notice that there are files with different time zones. That’s why you need to know your time zone to proceed to the next step.
You now need to compile a file based on your timezone. For instance, if your timezone is EAT, your file is named Africa. So, to compile it, append its name to zic, as shown in the following command:
You need the root to run the command. Once compressed, you need to copy the file to the zoneinfo/ directory.
The path to the zoneinfo depends again on your location. When you open the /usr/share/zoneinfo/, you will see the list of the available zones.
The different locations are listed above. Navigate into the directory in your timezone. You will see the various areas under the timezone.
Still on the directory where you compiled your file using zic, copy the file into the path with your time zone. For instance, to copy the file for the time zone Africa, the command will be:
You may need to reboot your system, and once restarted, check the time zone as we did earlier using the “+z”. It should now display the exact time.
The time zone database has files for the different locations. Each of these files contains rule lines with a specific format. The format of a rule line is:
Rule NAME FROM TO TYPE IN ON AT SAVE LETTER/S
The different fields in the rule line represent the different things.
NAME: It represents the name in which the rules are a part of, and in most cases, it is the time zone’s name.
FROM: The first year in which the set rule applies.
TO: The final year in which the rule applies.
TYPE: By default, it is set to – but if it is something else, the zic will execute the type of year set.
IN: The month when the rule takes applies.
ON: The day of the month. Here, you can have different formats. For instance, 4 represents the 4th of the month. A format like Mon>=7 represents the first Monday or a day after the 7th of the Month.
AT: It represents the exact time of the day.
SAVE: When the rule gets applied. The time to be added to the current set local standard time gets specified under this option.
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 image, the STDOFF represents the time to be added to the local standard time. RULES is the name of the rule to be applied. FORMAT is the format for the abbreviation of the timezone. Moreover, the time when the rule changes for the location gets specified under UNTIL.
Conclusion
When using the zic timezone compiler, your best resource is the man page. There are tons of options that you can use to tweak the time conversion. In this guide, we’ve covered how to compile time from a time zone database file. Furthermore, we’ve seen how a rule gets defined. Using the details discussed, you can combine the available options and tweak the time conversion as per your need.