On Tue, Apr 17, 2012 at 19:26, Denys Vlasenko [mailto:[email protected]] 
wrote:
>
> On Tue, Apr 17, 2012 at 4:06 PM, Brecht Ameije <[email protected]> wrote:
> >> But now I come upon something strange: the "date -u" and the "hwclock -u"
> >> commands give different results:
> >>
> >> $ export TZ=CET-1CEST,M3.5.0/2,M10.5.0/3
> >> $ ntpd -q -p 0.europe.pool.ntp.org # get current time
> >> $ hwclock -w                       # set hw clock
> >> $ date; date -u; hwclock; hwclock -u; hwclock -l
> >> Wed Apr  4 14:35:55 CEST 2012
> >> Wed Apr  4 12:35:55 UTC 2012
> >> Wed Apr  4 14:35:54 2012  0.000000 seconds
> >> Wed Apr  4 16:35:54 2012  0.000000 seconds
> >> Wed Apr  4 14:35:54 2012  0.000000 seconds
> 
> date -u means "show current time in UTC"
> whereas
> hwclock -u means "show rtc time in current timezone,
> assuming rtc clock is kept in UTC".
> 
> Your rtc clock is kept in local time.
> Therefore "hwclock -u" will misinterpret it.

Thanks, the following sequence of commands seems better. Difference is to set 
$TZ after setting the hwclock in UTC.

$ unset TZ
$ ntpd -q -p 0.europe.pool.ntp.org # get current time
$ hwclock -w                       # set hw clock
$ export TZ=CET-1CEST,M3.5.0/2,M10.5.0/3
$ echo 2 commands for local time:
$ date; hwclock -u;
$ echo 2 commands for UTC:
$ date -u; hwclock;

2 commands for local time:
Wed Apr 18 10:28:33 CEST 2012
Wed Apr 18 10:28:33 2012  0.000000 seconds
2 commands for UTC:
Wed Apr 18 08:28:33 UTC 2012
Wed Apr 18 08:28:33 2012  0.000000 seconds

Now I can use the date/hwclock commands as follows:
- date is standard in local time. Arg -u converts to UTC
- hwclock standard in UTC. Arg -u converts to local time

It's confusing but I guess this is the reasoning:
- date assumes the rtc clock is kept in UTC, and always shows local time. 
Unless you ask to see UTC time by adding -u.
- hwclock counts on the user to say whether the rtc clock is kept in local time 
(-l) or in UTC (-u). If used correctly, it will always show local time.
If the rtc clock is kept in local time, there's no way to find out UTC time 
using only the hwclock command. Therefore I now choose to keep it in UTC time. 
The implications are: when using the hwclock  arguments -w and -s (set hwclock 
to systime and vice versa), the $TZ variable should be unset.

Thanks Denys (and Harald off list) for the explanation.
Brecht

> --
> vda

_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to