How can I change the time zone of bandwidthd?

Is there any way to change the UTC offset for the graphs generated by bandwidthd?


The source code does use and store timestamps, that are then provided to the C functions ctime() and localtime() in order to display the date at the top of the page, and at the bottom of the graphs.

These Unix timestamps are time-zone-less, the number of seconds since 1970-01-01.
To get a human readable time, ctime() and localtime() automatically adjust the time zone to be used according to your system time zone (via a call to tzset()).

Forcing the TZ the time of a command

You can force anyway the time zone to a given value just for the time of a command execution, or during a whole daemon session, like bandwidthd. The environment variable TZ is read by tzset() to adjust the timezone, if set.

First have a look at the time zone definitions in /usr/share/zoneinfo

Then for instance, cd to your home dir in a terminal, and do a simple ls -lrt to see the most recent files at the bottom of the list. Then set the timezone to Paris, France, for instance

export TZ="Europe/Paris"

and do another ls -lrt, the time should be different (if you happen to have a system configured with a timezone set to France you may want to choose another TZ!).

Now unset the TZ var, just to prevent some mistakes based on time displayed in the terminal.

unset TZ


Changing the TZ of bandwidthd

I assume you installed the bandwidthd package from Ubuntu apt-get, and you should have an init file for it to start as a service. Do a copy somewhere of the file and then edit it as root (vi or another editor)

sudo cp -p /etc/init.d/bandwidthd ~/bandwidthd.save
sudo vi /etc/init.d/bandwidthd

Near the top you see a few variables definitions

NAME=bandwidthd
DESC=BandwidthD
...

add one (eg, for Paris)

MYTZ="Europe/Paris"

then, further below in the startd() function, you should see

    cd $WORKDIR && start-stop-daemon --start --quiet \
            --pidfile $PIDFILE \
            --chdir $WORKDIR \
            --exec $DAEMON -- $DAEMON_OPTS

change it to

    cd $WORKDIR && start-stop-daemon --start --quiet \
            --pidfile $PIDFILE \
            --chdir $WORKDIR \
            --exec /usr/bin/env TZ="$MYTZ" $DAEMON -- $DAEMON_OPTS

(notice the /usr/bin/env TZ="$MYTZ" between --exec and $DAEMON).


Restart the process

sudo service bandwidthd restart

and, could take a few seconds, the files should be updated, in a browser open file:///var/lib/bandwidthd/htdocs/index.html (or the dir where the files are written) to check.