📜 ⬆️ ⬇️

We are preparing Debian to transfer the clock October 26, 2014

It is approaching October 26, 2014 - the day when at 2 am in most regions of Russia, the next time (and as promised again last), the watch will be set back one hour. In addition, in some regions there is a change of time zone. You can get acquainted in detail where and what changes are possible in the Federal Law of 21.07.2014 No. 248- “On Amendments to the Federal Law“ On the Calculation of Time ” .

In this post I want to focus on the issue of bringing up to date the data on time zones in Debian.

Debian uses the timezone database (short name tzdata) to store information about all time zones in the world. This database contains complete data on all changes in time zones that occurred in the world for one reason or another, which allows you to conduct accurate local time calculations at any time starting from January 1, 1970. In particular, the current version of tzdata allows you to get the exact local time both in the period before the entry into force of Federal Law No. 248-, and after (starting from 2 am on October 26, 2014). In Debian, the tzdata database is distributed as a package of the same name.

The changes introduced by Federal Law No. 248- are reflected in the tzdata database starting from version 2014f. As of October 18, 2014 in the official Debian repositories for Wheezy (stable) and Squeeze (oldstable), the tzdata package has an earlier version 2014e, which does not yet have hours on October 26, 2014 in Russia. At the same time, for Jessi (testing) (Update1: from 10/19/2014 and for Wheezy (Stable) , the current version 2014h has already been posted. Thus, in Wheezy and Squueze, to calculate the time after October 26, you will need to install the package yourself simply:
')
wget ftp.ru.debian.org/debian/pool/main/t/tzdata/tzdata_2014h-2_all.deb

dpkg -i tzdata_2014h-2_all.deb


After that, an updated version of tzdata will be installed on the system, however, in order to start using services already running on the system (in particular, syslog), you will need to restart them.

I will also give an example of a simple script that will allow you to verify that the correct time zone database is used on your system. The tzdata.sh script performs a check for the Moscow time zone:

tzcheck.sh:
 #!/bin/sh T1=$(LC_ALL=C TZ=Europe/Moscow date -d @1409067890) if [ "$T1" != 'Tue Aug 26 19:44:50 MSK 2014' ] ; then echo FAIL! Wrong TZ BEFORE 26 Oct 2014! exit 1 fi T2=$(LC_ALL=C TZ=Europe/Moscow date -d @1416667890) if [ "$T2" != 'Sat Nov 22 17:51:30 MSK 2014' ] ; then echo FAIL! Wrong TZ AFTER 26 Oct 2014! exit 2 fi echo OK 


If everything is OK, OK will be displayed.

If Java is installed on your system, then updating the tzdata package will not work. Both OpenJDK and Sun / Oracle Java use their own, separate from system-wide, time zone databases. They also need to be updated.

In the case of OpenJDK, the base is the tzdata-java package, which has the same version numbers as the tzdata package. Update it just by analogy:

wget ftp.ru.debian.org/debian/pool/main/t/tzdata/tzdata-java_2014h-2_all.deb
dpkg -i tzdata-java_2014h-2_all.deb

In the case of Java, Sun / Oracle will need to use the special Java Time Zone Updater Tool , downloading it from the Oracle website. To update the time zone database, you will need to run it with the -u key

java -jar tzupdater.jar -u

Please note that if you have ever downloaded this utility before, you cannot use this old version - it will not update anything. With each update of the time zone database, Oracle releases a new version of this utility, to get the most current database, you need to use the current version.

As with regular services, already running Java applications may require a restart in order for them to start using the updated version of the time zone database.

Below is a sample Java code that will allow you to check for the Moscow time zone, that you are fine with Java time calculus:

tzcheck.java:
 import java.util.*; import java.text.DateFormat; public class tzcheck { public static void main(String[] args) { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("Europe/Moscow")); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.US); df.setCalendar(cal); cal.setTimeInMillis(1409067890L * 1000L); if (!df.format(cal.getTime()).equals("Tuesday, August 26, 2014 7:44:50 PM MSK")) { System.out.println("FAIL! Wrong TZ BEFORE 26 Oct 2014!"); System.exit(1); } cal.setTimeInMillis(1416667890L * 1000L); if (!df.format(cal.getTime()).equals("Saturday, November 22, 2014 5:51:30 PM MSK")) { System.out.println("FAIL! Wrong TZ AFTER 26 Oct 2014!"); System.exit(2); } System.out.println("OK"); System.exit(0); } } 

Compile and run:

javac tzcheck.java
java tzcheck

If everything is OK, OK will be displayed.

Update1: At the weekend, while the post was moderated for Wheezy, a regular package was released with the current tzdata + version 2014h-2 released, the links changed in the text.

Source: https://habr.com/ru/post/240915/


All Articles