Skip to main content
Topic: Feature request: script/app to set local time (Read 569 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Feature request: script/app to set local time

Currently, not sure if there are other ways, you have to:
Code: [Select]
ls -R /usr/share/zoneinfo
ln -sf /usr/share/zoneinfo/(somecountry) /etc/localtime

Could you make something to do that?

Re: Feature request: script/app to set local time

Reply #1
package "system/tzdata" provides binary called "tzselect".
although I do not know how well it works. I'm perfectly fine with linking (I use runit ;b).

Re: Feature request: script/app to set local time

Reply #2
It is not system-wide right?

Code: [Select]
[...]
You can make this change permanent for yourself by appending the line
TZ='<area>/<city>'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
<area>/<city>

Re: Feature request: script/app to set local time

Reply #3

 Local time isn't covered by ntp? I'm using chrony which didn't give me till now any problems. If you want to know different times for other locations I'm using a nicely put together website time.is. Also it checks if you have any delay.

Chrony permanently adjust system time and it does that over a secure connection in sync with some high precision special servers called stratums, it's not rudimentary and insecure like ntp it's NTS (Network Time Security).

For sure chrony has what you need it has lots of features.

Re: Feature request: script/app to set local time

Reply #4
Don't ntp/chrony use the local time settings in /etc/localtime to update the time?

Re: Feature request: script/app to set local time

Reply #5
Quote
Don't ntp/chrony use the local time settings in /etc/localtime to update the time?

Nope chrony is stand alone package. If I remember correctly you need to remove even that old ntp to use chrony cos those are in conflict. Recently chrony got loads of other useful enhancements.


Re: Feature request: script/app to set local time

Reply #6
How do I tell chrony to set the localtime?

Does it do it automatically using location?
I'd like to avoid to share that.

Re: Feature request: script/app to set local time

Reply #7

 Those servers/stratum must be knowing something idk how exactly it does that perhaps based on your public ip. If you don't want to have an ip idk if you can connect to the internet at all. But if you just want to set your system time without ntp chrony or other app think you can use date command. You have to be root to do this one.
 e.g
Code: [Select]
# date -s '2023-12-25 12:34:56'

But you might need to remove ntp or chrony so those can not change back your local time. If you'll keep using this method idk if 2fa authenticator apps on your system will work properly you have to check it out as the website you try to login will determine your location based on your ip but because you changed your local time or date 2fa codes will more likely fail.

edit: you can stop ntp or chrony service without the need of uninstall them.




Re: Feature request: script/app to set local time

Reply #8
If you use date you have to set it manually, it would be nice to have a script that sets /etc/localtime.
That asks you the time zone and does the link.

It's pretty simple to do it manually, just saying that it would be more nice to have something.

For example:
Code: [Select]
cat /usr/bin/sxmo_timezonechange.sh 
#!/bin/sh
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors

# include common definitions
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

change_alpine() {
echo "Changing timezone to $1"

doas setup-timezone -z "$1"
sxmo_hook_statusbar.sh time

echo "Timezone changed ok"
}

change_systemd() {
echo "Changing timezone to $1"

timedatectl set-timezone "$1"
sxmo_hook_statusbar.sh time

echo "Timezone changed ok"
}

menu() {
zoneinfo_dir=$(xdg_data_path zoneinfo)
T="$(
find "$zoneinfo_dir" -type f |
sed  "s#^${zoneinfo_dir}/##g" |
sort |
sxmo_dmenu_with_kb.sh -p Timezone -i
)" || exit 0
sxmo_terminal.sh "$0" "$T"
}

if [ $# -gt 0 ]; then
trap "read -r" EXIT
set -e

case "$OS" in
alpine|postmarketos) change_alpine "$@";;
arch|archarm|debian) change_systemd "$@";;
nixos) echo "Change the timezone in configuration.nix with time.timeZone = \"[timezone]\"";;
artix|armtix) echo "List the zones: ls -R /usr/share/zoneinfo"
echo "Set the zone: ln -sf /usr/share/zoneinfo/(somecountry) /etc/localtime";;
*) echo "Changing the timezone isn't implemented on your distro yet";;
esac
else
menu
fi
That just tell you how.

Re: Feature request: script/app to set local time

Reply #9

 Chrony doesn't need to be permanently online to do its things. It's far better than pretty much everything that exists out there in this field including timedatectl but sure if you want a script of yourself you can do it that way.




Re: Feature request: script/app to set local time

Reply #10
How does it fetch the local time the first time?

Re: Feature request: script/app to set local time

Reply #11

 You can check chrony docs so you choose which way it fits your exact need as I can't figure it out exactly how do you wanna get your local time as you've said you don't want to get it via internet but timedatectl think it's getting it via internet though.

So it depends on your specific  requirements idk.


Re: Feature request: script/app to set local time

Reply #12
I'd like to avoid geolocalisation only.

 

Re: Feature request: script/app to set local time

Reply #13

 You can't, as a I said your public ip is tied to your location you can't escape that. Even if you use vpn, vpn server will know your real geo-location.

Maybe you can set your system time to UTC so it will create a bit of uncertainty but still your ip will reveal your local time.

ip blocks/ranges are allocated to ISP's and those are very well documented from which country network they belong. Also if you are the only one that looks like from another country via other identifiers (other than ip) you'll look more sus than not doing that.

For a better privacy you need to have your clock as precise as you can and maybe use UTC time. For that chrony is perfect just read the docs.