tz-util
Command line utility that allows you to get and set timezone ID, as well as look up the timezone offset in minutes.
tz-util
to your configurationTo add tz-util
and its tests to your configuration, add the following to your fx set
command line:
--with=//src/sys/tz-util --with=//src/syz/tz-util:tests
Once done, fx build
will rebuild the program.
To use a freshly-built tz-util
, ensure that fx serve
is running in your Fuchsia development environment.
tz-util
can be ran from the shell command line or by reference to its component manifest.
Running just the binary will show usage:
fx shell run fuchsia-pkg://fuchsia.com/tz-util#meta/tz-util.cmx Usage: tz-util [--help|--set_timezone_id=ID|--get_timezone_id|--get_offset_minutes]
You get a similar effect by referring only to the short manifest name. The full manifest URI can be substituted in this, and all examples below.
fx shell run tz-util.cmx Usage: tz-util [--help|--set_timezone_id=ID|--get_timezone_id|--get_offset_minutes]
Set the timezone like this:
fx shell run tz-util.cmx --set_timezone_id=America/Los_Angeles
Note that you can not set an invalid timezone ID:
fx shell run tz-util.cmx --set_timezone_id=Roger/Rabbit ERROR: Unable to set ID: 1
The error message reports the status (with “1”, meaning FAILED), as handed down from the underlying FIDL protocol fuchsia.settings.Intl
Get the timezone like this:
fx shell run tz-util.cmx --get_timezone_id America/Los_Angeles
Get the timezone offset in minutes like this:
fx shell run tz-util.cmx --get_offset_minutes -480
The result shows that an accurate clock in Los Angeles shows 8 hours less than an accurate clock in UTC.
tz-util
functionality is guarded by integration tests. It is possible to run the tz-util
integration tests with fx run-test
as usual:
fx run-test tz-util_test
However, since tz-util
is part of the base package, the former command will also trigger a time consuming OTA. To avoid waiting on the OTA, you can also run the tests directly using:
fx shell run fuchsia-pkg://fuchsia.com/tz-util_test#meta/tz-util_test.cmx
However, in this case:
fx build
first, if you have changed somethingfx log
so when running the tests this way, you want to watch the fx log
output as well.