Web lists-archives.com

Re: date(1) in stretch and buster




I managed to build a locale with a customized LC_TIME setting under
buster.  It's not documented in a straightforward manner anywhere I
could find, so I'm going to spell it all out here.


Step 1: Start with an existing locale definition.

In my case, I am starting with Debian buster's en_US locale, and I am
only going to change one of the variables in the LC_TIME section.


Step 2: Create some directories.

mkdir -p ~/.locale/src

The ~/.locale directory is where the custom locale is going to end up when
it's all done.  In addition to that, you need a temporary working directory
where the locale definition (source) files are going to live.  In my case,
I chose to make this a permanent home rather than a temporary directory.


Step 3: Copy the existing locale definition to the work directory.

cp /usr/share/i18n/locales/en_US ~/.locale/src/

This is a text file that defines the locale's behavior.  You can edit it
with any standard text editor.  You might want to take a moment to look
through it and figure out how it's laid out.  It's pretty straightforward.


Step 4: Modify the locale definition file.

In my case, I wanted to change the date_fmt variable inside the LC_TIME
section.  So first, I logged into a stretch box and found what it was
using:

stretch:~$ locale -k LC_TIME | grep date_fmt
date_fmt="%a %b %e %H:%M:%S %Z %Y"

Next, I edited the ~/.locale/src/en_US file and replaced the date_fmt line.

BEFORE:

% Appropriate date and time representation for date(1)
date_fmt "%a %d %b %Y %r %Z"

AFTER:

% Appropriate date and time representation for date(1)
date_fmt "%a %b %e %H:%M:%S %Z %Y"


Step 5: Compile the locale.

I18NPATH=~/.locale/src/ localedef -f UTF-8 -i en_US ~/.locale/en_US.UTF-8

This creates the directory ~/.locale/en_US.UTF-8 containing several binary
files.  This is what the C library uses.


Step 6: Test it.

buster:~$ date
Mon 08 Apr 2019 02:52:34 PM EDT
buster:~$ LOCPATH=~/.locale date
Mon Apr  8 14:52:38 EDT 2019


Step 7: Set environment variables to make this your new locale upon login.

All you need (assuming you use bash) is:

export LOCPATH="$HOME/.locale"

This will be either really easy, or really hard, depending on how you
login and what kind of Desktop Environment (if any) you use.  Suggested
reading:

https://mywiki.wooledge.org/DotFiles
https://wiki.debian.org/Xsession

In particular, it would be great to hear from anyone who manages to get
this working under GNOME, which is notorious for not allowing easy
customizations of the login environment.