regolith-linux / regolith-desktop

Meta package for the Regolith Desktop Environment
1.5k stars 31 forks source link

Datetime in i3bar automatically uses user's region format #227

Closed kgilmer closed 4 years ago

kgilmer commented 4 years ago

From slack:

Jens Klein  2:31 AM
Whats the recommended way to the bar's time and date format?
Whats shown: 02/10 and time as am/pm.
If have a bit mixed locale, but LC_TIME is set to a de_AT.UTF8
$ locale
LANG=en_US.UTF-8
LANGUAGE=en_US
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=de_AT.UTF-8
LC_TIME=de_AT.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=de_AT.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=de_AT.UTF-8
LC_NAME=de_AT.UTF-8
LC_ADDRESS=de_AT.UTF-8
LC_TELEPHONE=de_AT.UTF-8
LC_MEASUREMENT=de_AT.UTF-8
LC_IDENTIFICATION=de_AT.UTF-8
LC_ALL= (edited) 
kgilmer commented 4 years ago

Related/duplicate: https://github.com/regolith-linux/regolith-desktop/issues/196

kgilmer commented 4 years ago

I am aware of two sources for date/time formatting in Regolith: locale (provided by libc_bin) and GNOME settings:

$ gsettings get org.gnome.desktop.interface clock-show-seconds
false
$ gsettings get org.gnome.desktop.interface clock-format
'12h'
$ gsettings get org.gnome.desktop.interface clock-show-date
false

The issue with locale is that is for i3bar, due to wanting to keep things concise, displaying the year and the second is undesirable. The former as this is (hopefully) already in the user's head and doesn't need to take up static screen space. The latter because of the frequency of update leading to an undesirable amount of noise.

There is no "compact format" defined in locale, nor is there any obvious way (according to the man page) to say something like "give me the locale date/time but without year and second fields". Due to the variable nature of what can come out of date based on the user's locacle, string parsing seems likely to be far too complex and error prone.

To break the problem down:

Time: since HH:MM ordering is seemingly universal, we can just rely on GNOME settings to determine 12/24 format. Optionally we could add seconds if the clock setting was set as such although I don't see any UI that exposes that to the end user.

Date: We want to remove the year, so that limits us to two variations: MM/DD and DD/MM. This table breaks this down to a small set of categories: https://en.wikipedia.org/wiki/Date_format_by_country It should be possible to read locale and guess at the correct date time based on country. Unfortunately it seems roughly divided in half, so there is no obvious smaller subset from which to identify the correct form. Which means brute force a conditional expression with all of these would need to be generated and executed upon each clock update:

aa_DJ
aa_ER
aa_ER@saaho
aa_ET
af_ZA
agr_PE
ak_GH
am_ET
an_ES
anp_IN
ar_AE
ar_BH
ar_DZ
ar_EG
ar_IN
ar_IQ
ar_JO
ar_KW
ar_LB
ar_LY
ar_MA
ar_OM
ar_QA
ar_SA
ar_SD
ar_SS
ar_SY
ar_TN
ar_YE
as_IN
ast_ES
ayc_PE
az_AZ
az_IR
be_BY
be_BY@latin
bem_ZM
ber_DZ
ber_MA
bg_BG
bhb_IN
bho_IN
bho_NP
bi_VU
bn_BD
bn_IN
bo_CN
bo_IN
br_FR
br_FR@euro
brx_IN
bs_BA
byn_ER
C
ca_AD
ca_ES
ca_ES@euro
ca_ES@valencia
ca_FR
ca_IT
ce_RU
chr_US
ckb_IQ
cmn_TW
cns11643_stroke
crh_UA
csb_PL
cs_CZ
cv_RU
cy_GB
da_DK
de_AT
de_AT@euro
de_BE
de_BE@euro
de_CH
de_DE
de_DE@euro
de_IT
de_LI
de_LU
de_LU@euro
doi_IN
dv_MV
dz_BT
el_CY
el_GR
el_GR@euro
en_AG
en_AU
en_BW
en_CA
en_DK
en_GB
en_HK
en_IE
en_IE@euro
en_IL
en_IN
en_NG
en_NZ
en_PH
en_SC
en_SG
en_US
en_ZA
en_ZM
en_ZW
eo
eo_US
es_AR
es_BO
es_CL
es_CO
es_CR
es_CU
es_DO
es_EC
es_ES
es_ES@euro
es_GT
es_HN
es_MX
es_NI
es_PA
es_PE
es_PR
es_PY
es_SV
es_US
es_UY
es_VE
et_EE
eu_ES
eu_ES@euro
eu_FR
eu_FR@euro
fa_IR
ff_SN
fi_FI
fi_FI@euro
fil_PH
fo_FO
fr_BE
fr_BE@euro
fr_CA
fr_CH
fr_FR
fr_FR@euro
fr_LU
fr_LU@euro
fur_IT
fy_DE
fy_NL
ga_IE
ga_IE@euro
gd_GB
gez_ER
gez_ER@abegede
gez_ET
gez_ET@abegede
gl_ES
gl_ES@euro
gu_IN
gv_GB
hak_TW
ha_NG
he_IL
hif_FJ
hi_IN
hne_IN
hr_HR
hsb_DE
ht_HT
hu_HU
hy_AM
i18n
i18n_ctype
ia_FR
id_ID
ig_NG
ik_CA
is_IS
iso14651_t1
iso14651_t1_common
iso14651_t1_pinyin
it_CH
it_IT
it_IT@euro
iu_CA
ja_JP
kab_DZ
ka_GE
kk_KZ
kl_GL
km_KH
kn_IN
kok_IN
ko_KR
ks_IN
ks_IN@devanagari
ku_TR
kw_GB
ky_KG
lb_LU
lg_UG
li_BE
lij_IT
li_NL
ln_CD
lo_LA
lt_LT
lv_LV
lzh_TW
mag_IN
mai_IN
mai_NP
mfe_MU
mg_MG
mhr_RU
mi_NZ
miq_NI
mjw_IN
mk_MK
ml_IN
mni_IN
mn_MN
mr_IN
ms_MY
mt_MT
my_MM
nan_TW
nan_TW@latin
nb_NO
nds_DE
nds_NL
ne_NP
nhn_MX
niu_NU
niu_NZ
nl_AW
nl_BE
nl_BE@euro
nl_NL
nl_NL@euro
nn_NO
nr_ZA
nso_ZA
oc_FR
om_ET
om_KE
or_IN
os_RU
pa_IN
pap_AW
pap_CW
pa_PK
pl_PL
POSIX
ps_AF
pt_BR
pt_PT
pt_PT@euro
quz_PE
raj_IN
ro_RO
ru_RU
ru_UA
rw_RW
sa_IN
sat_IN
sc_IT
sd_IN
sd_IN@devanagari
sd_PK
se_NO
sgs_LT
shn_MM
shs_CA
sid_ET
si_LK
sk_SK
sl_SI
sm_WS
so_DJ
so_ET
so_KE
so_SO
sq_AL
sq_MK
sr_ME
sr_RS
sr_RS@latin
ss_ZA
st_ZA
sv_FI
sv_FI@euro
sv_SE
sw_KE
sw_TZ
szl_PL
ta_IN
ta_LK
tcy_IN
te_IN
tg_TJ
the_NP
th_TH
ti_ER
ti_ET
tig_ER
tk_TM
tl_PH
tn_ZA
to_TO
tpi_PG
translit_circle
translit_cjk_compat
translit_cjk_variants
translit_combining
translit_compat
translit_font
translit_fraction
translit_hangul
translit_narrow
translit_neutral
translit_small
translit_wide
tr_CY
tr_TR
ts_ZA
tt_RU
tt_RU@iqtelif
ug_CN
ug_CN@latin
uk_UA
unm_US
ur_IN
ur_PK
uz_UZ
uz_UZ@cyrillic
ve_ZA
vi_VN
wa_BE
wa_BE@euro
wae_CH
wal_ET
wo_SN
xh_ZA
yi_US
yo_NG
yue_HK
yuw_PG
zh_CN
zh_HK
zh_SG
zh_TW
zu_ZA
kgilmer commented 4 years ago

Proposal:

kgilmer commented 4 years ago

This should be fixed in 1.3.1.