1ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#!/usr/bin/perl 2ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru# 3ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru# Copyright (C) 2007-2007, International Business Machines 4ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru# Corporation and others. All Rights Reserved. 5ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru# 6ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 7ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruif ($ARGV[0] eq '-h' || $ARGV[0] eq '--help') { 8ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru print "Usage: tzone [year month day hour minute]\n"; 9ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru exit(0); 10ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 11ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 12ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $LIBRARY = '../../lib'; 13ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 14ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy @TZONE_RAW = `locate zoneinfo | grep '^/usr/share/zoneinfo/' | grep -v 'tab\$' | grep -v '/right/' | grep -v '/posix/' | grep -v '/posixrules\$' | grep -v '/Factory\$'`; 15ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy @TZONE; 16ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $index = 0; 17ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $USECURRENT = 0; 18ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $year = 0; 19ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $month = 0; 20ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $day = 0; 21ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $hour = 0; 22ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Querumy $minute = 0; 23ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 24ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 25ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruif (scalar(@ARGV) == 5) { 26ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru ($year, $month, $day, $hour, $minute) = @ARGV; 27ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru print "The date we are using is: $month-$day-$year $hour:$minute.\n"; 28ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} else { 29ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru print "We are using the current date.\n"; 30ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru $USECURRENT = 1; 31ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 32ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 33ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#filter out the time zones 34ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruforeach my $tzone (@TZONE_RAW) { 35ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru chomp($tzone); 36ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (-e $tzone) { 37ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru $TZONE[$index] = substr($tzone, 20); 38ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru $index++; 39ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 40ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 41ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 42ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru#go through each timezone and test 43ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru$count = 0; 44ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru$ENV{'LD_LIBRARY_PATH'} = $LIBRARY; 45ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 46ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprint "The following time zones had wrong results.\n"; 47ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 48ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruforeach my $tzone (@TZONE) { 49ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru #set system time zone 50ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru $ENV{'TZ'} = "$tzone"; 51ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 52ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru my @result = `./tzdate $year $month $day $hour $minute $USECURRENT`; 53ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 54ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru #if the result is wrong print the time zone information to a log file 55ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru if (scalar(@result) > 0) { 56ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru print "\nTIME ZONE: $tzone\n"; 57ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru print "@result\n"; 58ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru $count++; 59ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru } 60ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru} 61ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 62ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprint "\nThe number of time zones with wrong results: $count out of $index\n"; 63ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queru 64ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruprint("\n\nGood Bye!\n"); 65ac04d0bbe12b3ef54518635711412f178cb4d16Jean-Baptiste Queruexit(0); 66