SET TZ env variable in .idx/dev.nix, but not expected result

I set TZ variable on .idx/dev.nix below:

  # Sets environment variables in the workspace
  env = {
    TZ = "Asia/Tokyo";
  };

after rebuild environment, I executed ‘date’ command on terminal.

result:

expected: Tue Aug 13 01:53:07 AM JST 2024
actual: Mon Aug 12 04:53:07 PM Asia 2024

additional information.
no set TZ variable result:

Mon Aug 12 04:53:07 PM UTC 2024

Could someone please advise me on how to configure this?

You should include the time offset too in the TZ environment variable. For instance
TZ = “JST-09”. Check out https://www.gnu.org/software/libc/manual/html_node/TZ-Variable.html for more.

I’ve tried setting the timezone with no luck,

this seems to do nothing
env = {
TZ=Americas/Los_Angeles;
};

this gives error, doesn’t like “PST”
env = {
TZ=PST;
};

I wonder if it is something with the error the command tzselect gives…
/usr/bin/tzselect: line 179: /etc/zoneinfo/iso3166.tab: No such file or directory
/usr/bin/tzselect: time zone files are not set up correctly.

Actually, timezone files are missing, add them through tzdata package

packages = [
  # other packages...
  pkgs.tzdata
];

env = {
  # other environment variables...

  # default TZDIR is /etc/zoneinfo but tzdata
  # stores them at /usr/share/zoneinfo
  TZDIR = "/usr/share/zoneinfo";
  # the timezone file to use
  TZ = "Asia/Tokyo";
};

And should work as expected

4 Likes

Following your advice, I made the necessary adjustments and got the expected outcome.
I hadn’t realized that I needed to configure the package.

Thanks a lot for your help.

Thanks again,
now if we could only start the Android emulator with a -timezone flag :slightly_smiling_face:

I found this command adb shell service call alarm 3 s16 <timezone> in android - how do i change timezone using adb - Stack Overflow which directly modifies the timezone on the android device and I have no idea how it works. No gonna lie but it looks very tricky, I would like some options in the dev.idx for the android emulator instead.

Anyway, you can add it in the dev.idx file like this

{pkgs, ...}: {
  env { TZ = "..."; };

  idx.workspace.onStart = {
    android-timezone = "adb -s localhost:5555 wait-for-device && adb -s localhost:5555 shell service call alarm 3 s16 $TZ";
  };
}

thanks again! , good find,
my quick search came back with no way to set time zone when using flutter to start Android emulator.
tweaked your suggestion, and got it working… notice the double single qoutes.

onStart = {
android-timezone = ''adb -s localhost:5555 wait-for-device && adb -s localhost:5555 shell service call alarm 3 s16 $TZ ‘’;
};

and this works from the terminal,
adb -s localhost:5555 shell service call alarm 3 s16 “America/Los_Angeles”

1 Like

opening project today, emulator didn’t have the same time as env,
even though I see in the terminal what appears to be a successful response from the adb command from on start in dev.nix , but emulator time didn’t match system time after a hard restart.

at least the adb cmd from the terminal works to quickly set emulator time,