Changing timezone while traveling

A recent trip took me to a different timezone.  Since I am running linux,  it was easy to make a temporary timezone change, and that’s what I will describe in this post.  I am actually using openSUSE 12.1 with KDE 4.7.2 as desktop.  However, the suggestions here should work with any unix system and any desktop on that unix system.

I’m a csh (c-shell) user, so I’ll start by describing what I did using csh.  Then I’ll give the equivalent steps for users of bash or sh.

As a csh user, I simply added the following line to the “.login” file in my home directory:

if ( -r $HOME/timezone.csh ) source $HOME/timezone.csh

I then created a text file “timezone.csh”, also in my home directory, containing:

setenv TZ US/Eastern

And that is all I have to do to switch to the Eastern time zone (or EST, Eastern Standard Time).  At the end of the trip, I could simply delete that “timezone.csh” file and revert to my normal timezone.  For a different timezone, I would put the appropriate information for that zone in the “timezone.csh” file.

The reason this works, is that the “.login” file is a standard user startup file for csh.  The desktop environment, as part of its startup, checks the user shell and runs the shell startup files (using that shell).  That puts TZ in the environment, where it is seen by all subsequent processes in that desktop environment.  And, because most unix software uses the standard library to check time, it will use that “$TZ” variable value in determining the time.

So, when I logged in to my KDE session, the clock at the right of the panel showed Eastern time, as did other processes that were time sensitive.  However, logs from system daemons continued to use my normal timezone settings, since they did not see the TZ environment variable.  Incidentally, I did check that this also worked when using Gnome or XFCE as desktop environment.

If you are using sh or bash as your shell, then the equivalent change will be to add the following lines to the “.profile” file in your home directory.

### check for a temporary timezone change.
if [ -r $HOME/timezone.sh ] ; then
        . $HOME/timezone.sh
fi

And then create a file “timezone.sh” containing:

TZ=US/Eastern
export TZ

I once experimented with doing something similar in Windows.  It did not work.  It seems that most processes in Windows directly get the system time and don’t check the value of TZ.  Admittedly, that was a few years ago.  I have not bothered to check since, but I doubt that much has changed in this aspect of Windows.

Advertisements

About Neil Rickert

Retired mathematician and computer scientist who dabbles in cognitive science.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: