janet-lang / janet

A dynamic language and bytecode vm
https://janet-lang.org
MIT License
3.38k stars 217 forks source link

`os/strftime` doesn't respect environment variables. #1443

Closed amano-kenji closed 1 month ago

amano-kenji commented 2 months ago

%a of os/strftime can change according to locale.

Setting locale through environment variables like LANG and LC_ALL doesn't work.

Even though my system uses glibc, os/strftime doesn't respect environment variables.

bakpakin commented 1 month ago

I don't know if there is something Janet should do here besides expose setlocale - we don't do anything to set or unset locales from environment variables, so if your OS or libc is not doing it, then Janet isn't doing it either.

bakpakin commented 1 month ago

Add os/setlocale as a very bare bones wrapper around setlocale. I spent some time trying to make thread local setlocale work, but each platform has it's own way of doing it and it was hard to make it consistent.

Example with os/strftime:

(os/setlocale (os/getenv "LC_ALL" "C")) # call at script start
(print (os/strftime "%A %c" (os/time)))
amano-kenji commented 1 month ago

Thread local?