RHEL - Localization and Internationalization

Dates and Timezones

Determining time on a Unix/Linux system

Time is tracked from the “epoch”, which is a special date known as the “birthday” of Unix systems, or January 1st, 1970. It exists as a timestamp, in seconds, since that time.

The system clock is a kernel module that responds with time values when writing files or being queried on date/time.

The hardware clock is the clock that is on the system motherboard (or on the virtual host’s motherboard), usually set and then maintained by battery during power off. The hwclock command allows you to work with the hardware clock directly, it outputs the hardware clock date/time.

For example: return something like Mon 19 Jun 201709:13:54 PMUTC -0.965537 seconds

    hwclock

The offset at the end is the amount of time from when the command was executed and the clock was read until display of the value.

Note: The hardware clock is unaware of time zones

Synchronize the hardware and system clock:

  • hwclock -w (or –systohc): Will synchronize the system clock to the hardware clock
  • hwclock -s (or –hctosys): Will synchronize the hardware clock to the system clock

date

Displays the current date and time along with the configured timezone.

You can control the format of the output with the + character followed by special formatting instructions.

  • %d: Two digit date
  • %H: Two digit hour, 24 hour format
  • %m: Two digit month
  • %M: Two digit minute
  • %Y: Four digit year
  • %z: Time zone offset

For example:

    date +"%H:%M-%m%d%Y-%z"

Would display the time as 23:11-04212017-0500.

Note: The -u option Displays the system UTC time

Time zone

A name representing an “offset” from theUTC (UniversalCoordinated Time), also known as GMT (Greenwhich Mean Time).

/usr/share/zoneinfo is the top level directory containing all time zone definitions.

Note: These are binary files and cannot simply by viewed on the console.

/etc/localtime is the system time zone (can be a full time zone copy OR a link to the configured time zone)

TZ (variable) allows you to override the system wide time zone setting in the above directory. Often set in a user’s home directory as part of the .bashrc file.

tzselect allows you to find the name of the time zone you want to use.

Note: This command does not change the time zone.

timedatectl (Red Hat based systems):

  • list-timezones: List all the timezones to choose from
  • set-timezone [country/zone]: Set to the indicated timezone
  • Make the actual changes, setting the /etc/localtime system setting to the time zone chosen

/etc/timezone is a local file that Debian systems use to store the name of the time zone configured.

/etc/adjtime contains values that track calibration to the clock and a final value to display time in LOCAL or UTC time If the file does not exist, no calibration has ever been done and time will default to UTC.

Network Time Protocol

Knowing when something happened accurately will allow you to figure out issues much faster, especially problems that happen across multiple systems.

Time is kept in sync using NTP. It allows you to define a pool of network servers that are synchronized to a globally distributed network of time servers and advertise the correct time (based on an atomic clock or GPS data) for other servers to sync to. There are different tiers of strata for NTP servers.

There is a list of publicly available NTP servers (aliases commonly configured: 0.pool.ntp.org through 3.pool.ntp.org).

status - General information about the time and date on the server. Also NTP sync information.

  • set-time Force the time to be set
  • set-timezone Set a timezone
  • set-ntp Turn NTP on or off

ntpdate This command allows you to set the clock against the indicated NTP server.

ntpq This command allows you to query an NTP server for stats and connect to local system by default. It invokes a special prompt:

  • Peers: Time hosts already associated with
  • Associations: More details on each server

When a clock is off, the NTP service will have the accurate time and use an algorithm to determine how much to change the value of 1 second to bring the clock back to correct.

The service that manages NTP on your server is chrony.

The service is named chronyd and the program used to interact with the service is chronyc. A few useful commands are:

    chronyc tracking

Where do we get this information from?

    chronyc sources -v

Locales and Character Encoding

Linux and Locales

locale is a way of representing your language, country and encoding type. The -a option shows you the locales that are installed on your system.

GNU gettext is a library that handles internationalization. It relies on environment variables to determine which locale is necessary:

  • LANGUAGE: Used when displaying messages, but does not affect formatting
  • LC_ALL: Force the indicated locale even if other variables are set differently
  • LC_XXX: Administrator variable to override a locale for any element in the locale
  • LANG: Encoding type

ASCII

American Standard Code for Information Exchange. ASCII is encoded into 7 bits, giving 128 total possible characters. Once those characters ran out, storing went to 8 bits, giving another 128 possible characters.

Code pages

Character set definitions (where unused characters are assigned their own character). Code pages are vendor specific, changing between the characters requires changing the code page.

ISO-8859 standard - Definition of standard code pages:

  • ISO-8859-1: Latin alphabet with english characters
  • ISO-8859-3: Turkish characters with other language characters

Was determined to be too chaotic/sprawling.

unicode

Defines every character as a number (code point). Unicode was originally encoded in 2 bytes, giving you 16k possible characters (called UCS-2).

Once again, the number of characters in this spec was exceeded.

  • UTF-16 was introduced to allow any character over 16k to be represented with a second pair of bytes
  • UTF-8 allows 1 to 6 bytes to be used to encode a character, with the character length encoded into the high order bits of the character number and maintains full compatibility with the original spec 128 character ASCII code.

iconv

iconv is a utility used to convert between character encodings:

  • -c: Clears unknown characters
  • -f [type]: From indicated type
  • -t [type]: To the indicated type
  • -l: Lists all available encoding types

For exmaple:

    iconv -c -f ASCII -t MACCYRILLIC VNCHOWTO > VNCHOWTO.new.cyrillic

Would clear any unknown characters in the file stream fromVNCHOWTO, and convert fromASCII to MACCYRILLIC encoding,writing the new file the VNCHOWTO.new.cyrillic.

Note: This is not a language translator, simply a character encoding translator.