pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

colorls: mangled timestamps with non-"C"-locale



With LC_TIME=C, colorls -l displays timestamps as expected:
| /tmp/foobar $ env LC_TIME=C colorls -l
| total 0
| -rw-r--r--  1 fstd  wheel  0 Sep  8 01:52 bar
| -rw-r--r--  1 fstd  wheel  0 Sep  8 01:52 foo

This is because colorls uses strftime(3) with "%c" (which means "show time in locale-specific format") and then, ugh:
> strftime(longstring, sizeof(longstring), "%c", localtime(&ftime));
> for (i = 4; i < 11; ++i)
> 	(void)putchar(longstring[i]);
(a pretty filthy hack IMO)

Which obviously works well for %c as produced by a "C" locale:
| /tmp/foobar $ env LC_TIME=C date +%c
| Tue Sep  8 01:53:35 2015
      ^^^^^^^
..but not so much for others:
| /tmp/foobar $ env LC_TIME=en_US.UTF-8 date +%c
| September  8, 2015 at 01:53:31 AM CEST
      ^^^^^^^

The result is (note the "ember")
| /tmp/foobar $ env LC_TIME=en_US.UTF-8 colorls -l
| total 0
| -rw-r--r--  1 fstd  wheel  0 ember  8, 20 bar
| -rw-r--r--  1 fstd  wheel  0 ember  8, 20 foo


--
Timo Buhrmester


Home | Main Index | Thread Index | Old Index