25

TL;DR

What is the best practice for customizing my date and time format settings, while sticking to the DRY-principle, i.e. without repeating stuff unnecessarily?


I'd like to customize exclusively the date and time format for my system, while sticking to the rest of the locale as is. I know that environment variable LC_TIME will make it possible to customize that aspect only by pointing to an alternate locale. Since I am using Linux (Ubuntu 14.04 to be precise), I want to use the format understood by localedef as input.

I have read the following three pieces of documentation:

The last one was particularly helpful.

Now, I only want to customize the section for LC_TIME and would like to inherit verything else.

So I copied en_US to a file named isodate in /usr/share/i18n/locales and adjusted the values I care about. After sifting through the documentation I decided also to replace all other section contents with a copy-keyword.

Question: It's not clear to me what method is supposed to be best practice. Does anyone know that (or even another alternative than those given by me)?

For example, since I care only about a few values (d_t_fmt, d_fmt, t_fmt, t_fmt_ampm, am_pm, date_fmt) it would be sweet to inherit all of en_US for LC_TIME and then merely overwrite those values with my ISO-like format (ISO 8601). However, the documentation about copy states (emphasis mine):

copy

Specify the name of an existing locale which shall be used as the definition of this category. If this keyword is specified, no other keyword shall be specified.

This means I cannot simply throw in a copy and then add more keywords.

Also, might it be legit to only define the LC_TIME section or will localedef outright refuse to compile that?


What I came up with so far:

escape_char /
comment_char %

LC_IDENTIFICATION
copy "en_US"
END LC_IDENTIFICATION

LC_CTYPE
copy "en_US"
END LC_CTYPE

LC_COLLATE
copy "en_US"
END LC_COLLATE

LC_MONETARY
copy "en_US"
END LC_MONETARY

LC_NUMERIC
copy "en_US"
END LC_NUMERIC

LC_TIME
abday   "<U0053><U0075><U006E>";"<U004D><U006F><U006E>";/
    "<U0054><U0075><U0065>";"<U0057><U0065><U0064>";/
    "<U0054><U0068><U0075>";"<U0046><U0072><U0069>";/
    "<U0053><U0061><U0074>"
day "<U0053><U0075><U006E><U0064><U0061><U0079>";/
    "<U004D><U006F><U006E><U0064><U0061><U0079>";/
    "<U0054><U0075><U0065><U0073><U0064><U0061><U0079>";/
    "<U0057><U0065><U0064><U006E><U0065><U0073><U0064><U0061><U0079>";/
    "<U0054><U0068><U0075><U0072><U0073><U0064><U0061><U0079>";/
    "<U0046><U0072><U0069><U0064><U0061><U0079>";/
    "<U0053><U0061><U0074><U0075><U0072><U0064><U0061><U0079>"

week    7;19971130;7
first_weekday   1
first_workday   2
abmon   "<U004A><U0061><U006E>";"<U0046><U0065><U0062>";/
    "<U004D><U0061><U0072>";"<U0041><U0070><U0072>";/
    "<U004D><U0061><U0079>";"<U004A><U0075><U006E>";/
    "<U004A><U0075><U006C>";"<U0041><U0075><U0067>";/
    "<U0053><U0065><U0070>";"<U004F><U0063><U0074>";/
    "<U004E><U006F><U0076>";"<U0044><U0065><U0063>"
mon "<U004A><U0061><U006E><U0075><U0061><U0072><U0079>";/
    "<U0046><U0065><U0062><U0072><U0075><U0061><U0072><U0079>";/
    "<U004D><U0061><U0072><U0063><U0068>";/
    "<U0041><U0070><U0072><U0069><U006C>";/
    "<U004D><U0061><U0079>";/
    "<U004A><U0075><U006E><U0065>";/
    "<U004A><U0075><U006C><U0079>";/
    "<U0041><U0075><U0067><U0075><U0073><U0074>";/
    "<U0053><U0065><U0070><U0074><U0065><U006D><U0062><U0065><U0072>";/
    "<U004F><U0063><U0074><U006F><U0062><U0065><U0072>";/
    "<U004E><U006F><U0076><U0065><U006D><U0062><U0065><U0072>";/
    "<U0044><U0065><U0063><U0065><U006D><U0062><U0065><U0072>"
% Appropriate date and time representation (%c)
%   "%Y-%m-%d %H:%M:%S"
d_t_fmt "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064><U0020><U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
%
% Appropriate date representation (%x)
%   "%Y-%m-%d"
d_fmt   "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064>"
%
% Appropriate time representation (%X)
%   "%H:%M:%S"
t_fmt   "<U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
%
t_fmt_ampm ""
%
am_pm   "";""
%
% Appropriate date representation (date(1))   "%Y-%m-%d %H:%M:%S"
date_fmt    "<U0025><U0059><U002D><U0025><U006D><U002D><U0025><U0064><U0020><U0025><U0048><U003A><U0025><U004D><U003A><U0025><U0053>"
END LC_TIME

LC_MESSAGES
copy "en_US"
END LC_MESSAGES

LC_PAPER
copy "en_US"
END LC_PAPER

LC_NAME
copy "en_US"
END LC_NAME


LC_ADDRESS
copy "en_US"
END LC_ADDRESS

LC_TELEPHONE
copy "en_US"
END LC_TELEPHONE

LC_MEASUREMENT
copy "en_US"
END LC_MEASUREMENT
3
  • 3
    It's ok to only define one section and copy the other ones... May 17, 2015 at 23:23
  • 3
    You might want to take a look at en_DK.UTF-8 :) I guess it's what you want. Oct 17, 2018 at 10:07
  • 1
    I created a very similar locale recently and as Pierre-Alain suggested I used en_DK.UTF-8 as my template. I don't think that there are any strict best practices as can be seen by looking at the differences between the standard locales that are shipped with most Linux distributions. You can read about how I solved my problem on my web site and look at the final result on gitlab.
    – gam3
    Oct 23, 2018 at 12:07

1 Answer 1

1

As pointed out in some of the comments, you can either copy the rest of the sections and customize LC_TIME in your custom locales file, or configure LC_TIME in /etc/locale.conf. As the locale.conf(5) man-page suggests, you could also use the kernel commandline option locale.LC_TIME= to override the setting at boot time.

1
  • 3
    Hi. Thanks for the answer. I didn't quite get your edit on the question, but whatever. My main issue is not so much to get a particular effect (I think my question demonstrates I have found it). The core of my question is whether there is a canonical way of doing this and what it is. The reason I asked it because without a canonical way I run the risk of changing stuff that I shouldn't change and run into all kinds of conflicts (such as with package management). You probably don't see them, but there were three (now deleted) answers like yours before. Still +1. Mar 1, 2020 at 15:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .