[tz] How to compute the moment of the next DST change

John Haxby john.haxby at oracle.com
Tue Apr 2 09:23:59 UTC 2013

On 02/04/13 09:58, Simon Perreault wrote:
> I want to write a cron job or similar that activates one week prior to
> daylight saving time changes. (Or, more generically, one week prior to
> any time jumps, for any reason, DST or else.)
> Any pointers?
> I have looked at the usual places: POSIX time functions, various
> date/time modules on CPAN, etc. Nothing seems to do that computation. Do
> I need to parse the tz database myself?

If you're on Linux:

TZ1=$(date +%Z)
TZ2=$(date =d 'next week' +%Z)
if [ $TZ1 != $TZ2 ]; then
    echo clocks change next week

You can also use localtime(3) with the current time and the current time
plus 7*24*2600 and compare the tm_hour field.


More information about the tz mailing list