cvsdist a5082c
#!/usr/bin/perl -w
cvsdist a5082c
#
cvsdist a5082c
# test.pl - tests validity of lexer/parser for at(1)
cvsdist a5082c
#
cvsdist a5082c
# Copyright 2001 David D. Kilzer
cvsdist a5082c
#
cvsdist a5082c
# Licensed under the GNU Public License
cvsdist a5082c
#
cvsdist a5082c
# Environment variables:
cvsdist a5082c
#   TEST_VERBOSE
cvsdist a5082c
#     0 - no verbosity
cvsdist a5082c
#     1 - verbose output only on failed tests, and all stderr output
cvsdist a5082c
#   > 1 - verbose output on every test, and all stderr output
cvsdist a5082c
#
cvsdist a5082c
cvsdist a5082c
use strict;
cvsdist a5082c
cvsdist a5082c
use constant SECOND => 1;		# seconds per second
cvsdist a5082c
use constant MINUTE => 60*SECOND;	# seconds per minute
cvsdist a5082c
use constant HOUR   => 60*MINUTE;	# seconds per hour
cvsdist a5082c
use constant DAY    => 24*HOUR;		# seconds per day
cvsdist a5082c
use constant WEEK   =>  7*DAY;		# seconds per week
cvsdist a5082c
cvsdist a5082c
use vars qw($verbose);
cvsdist a5082c
cvsdist a5082c
use POSIX;				# strftime
cvsdist a5082c
use Time::Local;			# timelocal() and timegm()
cvsdist a5082c
cvsdist a5082c
BEGIN { $| = 1; }			# no output buffering
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Subroutines
cvsdist a5082c
#
cvsdist a5082c
sub is_dst (;$);			# is time in DST?
cvsdist a5082c
sub get_utc_offset (;$);		# calculate hours offset from UTC
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Data structures containing test data
cvsdist a5082c
#
cvsdist a5082c
my @date_tests; 		# date strings
cvsdist a5082c
my @time_tests; 		# time strings
cvsdist a5082c
my @date_time_tests_time; 	# time + date strings (just times)
cvsdist a5082c
my @date_time_tests_date; 	# time + date strings (just dates)
cvsdist a5082c
my @inc_dec_tests;		# increment and decrement strings
cvsdist a5082c
my @misc_tests;			# miscellaneous strings (mostly for DST)
cvsdist a5082c
cvsdist a5082c
my $num_tests;			# number of tests
cvsdist a5082c
my $show_stderr;		# set to "2> /dev/null" if (! $verbose)
cvsdist a5082c
my $utc_off;			# timezone offset in minutes west of UTC
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Set variables before running tests
cvsdist a5082c
#
cvsdist a5082c
$verbose = $ENV{'TEST_VERBOSE'} || 0;
cvsdist a5082c
cvsdist a5082c
$show_stderr = ($verbose > 0 ? "" : "2> /dev/null");
cvsdist a5082c
cvsdist a5082c
$utc_off = get_utc_offset();
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Tests for dates only
cvsdist a5082c
#   These tests include both relative and specific dates.
cvsdist a5082c
#   They are not combined with any other tests.
cvsdist a5082c
#
cvsdist a5082c
# Format: "string", month, day, year, hour, minute, [offset]
cvsdist a5082c
#
cvsdist a5082c
@date_tests = 
cvsdist a5082c
(
cvsdist a5082c
[ "dec 31",		12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31",		12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "DEC 31",		12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "december 31",	12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "December 31",	12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "DECEMBER 31",	12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31 10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31 10",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31,10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31, 10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31,10",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31, 10",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31,2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31, 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31,2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31, 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "sun",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 0 ? 7 : ((7 - $wd + 0) % 7)) * DAY)' ],
cvsdist a5082c
[ "Sun",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 0 ? 7 : ((7 - $wd + 0) % 7)) * DAY)' ],
cvsdist a5082c
[ "SUN",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 0 ? 7 : ((7 - $wd + 0) % 7)) * DAY)' ],
cvsdist a5082c
[ "sunday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 0 ? 7 : ((7 - $wd + 0) % 7)) * DAY)' ],
cvsdist a5082c
[ "Sunday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 0 ? 7 : ((7 - $wd + 0) % 7)) * DAY)' ],
cvsdist a5082c
[ "SUNDAY",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 0 ? 7 : ((7 - $wd + 0) % 7)) * DAY)' ],
cvsdist a5082c
[ "Mon",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 1 ? 7 : ((7 - $wd + 1) % 7)) * DAY)' ],
cvsdist a5082c
[ "Monday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 1 ? 7 : ((7 - $wd + 1) % 7)) * DAY)' ],
cvsdist a5082c
[ "Tue",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 2 ? 7 : ((7 - $wd + 2) % 7)) * DAY)' ],
cvsdist a5082c
[ "Tuesday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 2 ? 7 : ((7 - $wd + 2) % 7)) * DAY)' ],
cvsdist a5082c
[ "Wed",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 3 ? 7 : ((7 - $wd + 3) % 7)) * DAY)' ],
cvsdist a5082c
[ "Wednesday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 3 ? 7 : ((7 - $wd + 3) % 7)) * DAY)' ],
cvsdist a5082c
[ "Thu",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 4 ? 7 : ((7 - $wd + 4) % 7)) * DAY)' ],
cvsdist a5082c
[ "Thursday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 4 ? 7 : ((7 - $wd + 4) % 7)) * DAY)' ],
cvsdist a5082c
[ "Fri",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 5 ? 7 : ((7 - $wd + 5) % 7)) * DAY)' ],
cvsdist a5082c
[ "Friday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 5 ? 7 : ((7 - $wd + 5) % 7)) * DAY)' ],
cvsdist a5082c
[ "Sat",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 6 ? 7 : ((7 - $wd + 6) % 7)) * DAY)' ],
cvsdist a5082c
[ "Saturday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 6 ? 7 : ((7 - $wd + 6) % 7)) * DAY)' ],
cvsdist a5082c
[ "now",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "Now",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "NOW",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "today",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "Today",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "TODAY",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "tomorrow",		'$mo', '$d', '$y', '$h', '$mi', '1 * DAY' ],
cvsdist a5082c
[ "Tomorrow",		'$mo', '$d', '$y', '$h', '$mi', '1 * DAY' ],
cvsdist a5082c
[ "TOMORROW",		'$mo', '$d', '$y', '$h', '$mi', '1 * DAY' ],
cvsdist a5082c
[ "10-12-31",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "2010-12-31",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31.12.10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31.12.2010",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31 Dec",		12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "31 December",	12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "31 Dec 10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31 Dec 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31 December 10",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31 December 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "12/31/10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "12/31/2010",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "13010",		01, 30, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "1302010",		01, 30, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "013010",		01, 30, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "01302010",		01, 30, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "123110",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "12312010",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "next minute",	'$mo', '$d', '$y', '$h', '$mi', '1 * MINUTE' ],
cvsdist a5082c
[ "next hour",		'$mo', '$d', '$y', '$h', '$mi', '1 * HOUR' ],
cvsdist a5082c
[ "next day",		'$mo', '$d', '$y', '$h', '$mi', '1 * DAY' ],
cvsdist a5082c
[ "next week",		'$mo', '$d', '$y', '$h', '$mi', '1 * WEEK' ],
cvsdist a5082c
[ "next month",		'($mo == 12 ? 1 : $mo + 1)', '$d', '($mo == 12 ? $y + 1 : $y)', '$h', '$mi' ],
cvsdist a5082c
[ "next year",		'$mo', '$d', '$y + 1', '$h', '$mi' ],
cvsdist a5082c
);
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Tests for times only
cvsdist a5082c
#   These tests include specific times and time aliases.
cvsdist a5082c
#   They are not combined with any other tests.
cvsdist a5082c
#
cvsdist a5082c
# Format: "string", month, day, year, hour, minute, [offset]
cvsdist a5082c
#
cvsdist a5082c
@time_tests = 
cvsdist a5082c
(
cvsdist a5082c
[ "0800",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "2300",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8:00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08:00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "23:00",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8'00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08'00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "23'00",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8.00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08.00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "23.00",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8h00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08h00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "23h00",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8,00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08,00",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "23,00",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8:00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08:00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "11:00 pm",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8'00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08'00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "11'00 pm",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8.00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08.00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "11.00 pm",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8h00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08h00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "11h00 pm",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "8,00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "08,00 am",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 8*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "11,00 pm",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
			'(($h*60+$mi) < (23*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "0800 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "2300 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8:00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08:00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "23:00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8'00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08'00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "23'00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8.00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08.00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "23.00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8h00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08h00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "23h00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8,00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08,00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "23,00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8:00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08:00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "11:00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8'00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08'00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "11'00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8.00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08.00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "11.00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8h00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08h00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "11h00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "8,00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "08,00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 8*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "11,00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (23*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "noon",		'$mo', '$d', '$y', 12, 0,
cvsdist a5082c
			'(($h*60+$mi) < (12*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "Noon",		'$mo', '$d', '$y', 12, 0,
cvsdist a5082c
			'(($h*60+$mi) < (12*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "NOON",		'$mo', '$d', '$y', 12, 0,
cvsdist a5082c
			'(($h*60+$mi) < (12*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "midnight",		'$mo', '$d', '$y',  0, 0,
cvsdist a5082c
			'(($h*60+$mi) < ( 0*60+0) ? 1 * DAY : 1 * DAY)' ],
cvsdist a5082c
[ "teatime",		'$mo', '$d', '$y', 16, 0,
cvsdist a5082c
			'(($h*60+$mi) < (16*60+0) ? 0 : 1 * DAY)' ],
cvsdist a5082c
[ "noon utc",		'$mo', '$d', '$y', 12, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (12*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "noon UTC",		'$mo', '$d', '$y', 12, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (12*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "midnight utc",	'$mo', '$d', '$y',  0, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < ( 0*60+0) ? 1 * DAY : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
[ "teatime utc",	'$mo', '$d', '$y', 16, 0,
cvsdist a5082c
	'(($h*60+$mi+$utc_off) < (16*60+0) ? 0 : 1 * DAY) - $utc_off * MINUTE' ],
cvsdist a5082c
);
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Tests for combining times and dates and inc/dec
cvsdist a5082c
#   These tests include specific times and time aliases that are
cvsdist a5082c
#   combined with @date_time_tests_date and with @inc_dec_tests
cvsdist a5082c
#   during testing.
cvsdist a5082c
#
cvsdist a5082c
# Format: "string", month, day, year, hour, minute, [offset]
cvsdist a5082c
#
cvsdist a5082c
@date_time_tests_time = 
cvsdist a5082c
(
cvsdist a5082c
[ "0800",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "2300",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8:00",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "23:00",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8'00",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "23'00",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8.00",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "23.00",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8h00",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "23h00",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8,00",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "23,00",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8:00 am",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "11:00 pm",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8'00 am",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "11'00 pm",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8.00 am",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "11.00 pm",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8h00 am",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "11h00 pm",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "8,00 am",		'$mo', '$d', '$y',  8, 0 ],
cvsdist a5082c
[ "11,00 pm",		'$mo', '$d', '$y', 23, 0 ],
cvsdist a5082c
[ "0800 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "2300 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8:00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "23:00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8'00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "23'00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8.00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "23.00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8h00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "23h00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8,00 utc",		'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "23,00 utc",		'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8:00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "11:00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8'00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "11'00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8.00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "11.00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8h00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "11h00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "8,00 am utc",	'$mo', '$d', '$y',  8, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "11,00 pm utc",	'$mo', '$d', '$y', 23, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "noon",		'$mo', '$d', '$y', 12, 0 ],
cvsdist a5082c
[ "midnight",		'$mo', '$d', '$y',  0, 0 ],
cvsdist a5082c
[ "teatime",		'$mo', '$d', '$y', 16, 0 ],
cvsdist a5082c
[ "noon utc",		'$mo', '$d', '$y', 12, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "midnight utc",	'$mo', '$d', '$y',  0, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
[ "teatime utc",	'$mo', '$d', '$y', 16, 0,
cvsdist a5082c
	'- $utc_off * MINUTE' ],
cvsdist a5082c
);
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Tests for combining times and dates and inc/dec
cvsdist a5082c
#   These tests include both relative and specific dates that are
cvsdist a5082c
#   combined with @date_time_tests_time and with @inc_dec_tests
cvsdist a5082c
#   during testing.
cvsdist a5082c
#
cvsdist a5082c
# Format: "string", month, day, year, hour, minute, [offset]
cvsdist a5082c
#
cvsdist a5082c
@date_time_tests_date = 
cvsdist a5082c
(
cvsdist a5082c
[ "Dec 31",		12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31 10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Dec 31, 10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "December 31, 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "Monday",		'$mo', '$d', '$y', '$h', '$mi',
cvsdist a5082c
			'(($wd == 1 ? 7 : ((7 - $wd + 1) % 7)) * DAY)' ],
cvsdist a5082c
[ "today",		'$mo', '$d', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "tomorrow",		'$mo', '$d', '$y', '$h', '$mi', '1 * DAY' ],
cvsdist a5082c
[ "10-12-31",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "2010-12-31",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31.12.10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31.12.2010",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31 Dec",		12, 31, '$y', '$h', '$mi' ],
cvsdist a5082c
[ "31 Dec 10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "31 Dec 2010",	12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "12/31/10",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "12/31/2010",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "13010",		01, 30, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "1302010",		01, 30, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "123110",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "12312010",		12, 31, 2010, '$h', '$mi' ],
cvsdist a5082c
[ "next minute",	'$mo', '$d', '$y', '$h', '$mi', '1 * MINUTE' ],
cvsdist a5082c
[ "next hour",		'$mo', '$d', '$y', '$h', '$mi', '1 * HOUR' ],
cvsdist a5082c
[ "next day",		'$mo', '$d', '$y', '$h', '$mi', '1 * DAY' ],
cvsdist a5082c
[ "next week",		'$mo', '$d', '$y', '$h', '$mi', '1 * WEEK' ],
cvsdist a5082c
[ "next month",		'($mo == 12 ? 1 : $mo + 1)', '$d', '($mo == 12 ? $y + 1 : $y)', '$h', '$mi' ],
cvsdist a5082c
[ "next year",		'$mo', '$d', '$y + 1', '$h', '$mi' ],
cvsdist a5082c
);
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Tests for combining times and dates and inc/dec
cvsdist a5082c
#   These tests include both increments and decrements that are
cvsdist a5082c
#   combined with @date_time_tests_time and with @date_time_tests_date
cvsdist a5082c
#   during testing.  Note how these tests refer to elements from
cvsdist a5082c
#   the data structures that they will be combined with ($$i[N]).
cvsdist a5082c
#
cvsdist a5082c
# Format: "string", month, day, year, hour, minute, [offset]
cvsdist a5082c
#
cvsdist a5082c
@inc_dec_tests = 
cvsdist a5082c
(
cvsdist a5082c
[ "- 1 min",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '-  1 * MINUTE' ],
cvsdist a5082c
[ "- 1 minute",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '-  1 * MINUTE' ],
cvsdist a5082c
[ "- 1 hour",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '-  1 * HOUR'   ],
cvsdist a5082c
[ "- 1 day",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '-  1 * DAY'    ],
cvsdist a5082c
[ "- 1 week",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '-  1 * WEEK'   ],
cvsdist a5082c
[ "- 1 month",		'($$i[1] == 1 ? 12 : $$i[1] - 1)', '$$i[2]', '($$i[1] == 1 ? $$i[3] - 1 : $$i[3])', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "- 1 year",		'$$i[1]', '$$i[2]', '$$i[3] -  1', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "- 10 min",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '- 10 * MINUTE' ],
cvsdist a5082c
[ "- 10 minutes",	'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '- 10 * MINUTE' ],
cvsdist a5082c
[ "- 10 hours",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '- 10 * HOUR'   ],
cvsdist a5082c
[ "- 10 days",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '- 10 * DAY'    ],
cvsdist a5082c
[ "- 10 weeks",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '- 10 * WEEK'   ],
cvsdist a5082c
[ "- 10 months",	'($$i[1] > 10 ? $$i[1] - 10 : $$i[1] + 2)', '$$i[2]', '($$i[1] > 10 ? $$i[3]: $$i[3] - 1)', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "- 10 years",		'$$i[1]', '$$i[2]', '$$i[3] - 10', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "+ 1 min",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+  1 * MINUTE' ],
cvsdist a5082c
[ "+ 1 minute",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+  1 * MINUTE' ],
cvsdist a5082c
[ "+ 1 hour",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+  1 * HOUR'   ],
cvsdist a5082c
[ "+ 1 day",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+  1 * DAY'    ],
cvsdist a5082c
[ "+ 1 week",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+  1 * WEEK'   ],
cvsdist a5082c
[ "+ 1 month",		'($$i[1] == 12 ? 1 : $$i[1] + 1)', '$$i[2]', '($$i[1] == 12 ? $$i[3] + 1 : $$i[3])', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "+ 1 year",		'$$i[1]', '$$i[2]', '$$i[3] +  1', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "+ 10 min",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+ 10 * MINUTE' ],
cvsdist a5082c
[ "+ 10 minutes",	'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+ 10 * MINUTE' ],
cvsdist a5082c
[ "+ 10 hours",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+ 10 * HOUR'   ],
cvsdist a5082c
[ "+ 10 days",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+ 10 * DAY'    ],
cvsdist a5082c
[ "+ 10 weeks",		'$$i[1]', '$$i[2]', '$$i[3]', '$$i[4]', '$$i[5]', '+ 10 * WEEK'   ],
cvsdist a5082c
[ "+ 10 months",	'($$i[1] < 3 ? $$i[1] + 10 : $$i[1] - 2)', '$$i[2]', '($$i[1] < 3 ? $$i[3] : $$i[3] + 1)', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
[ "+ 10 years",		'$$i[1]', '$$i[2]', '$$i[3] + 10', '$$i[4]', '$$i[5]' ],
cvsdist a5082c
);
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Miscellaneous tests
cvsdist a5082c
#   These tests include any specific test cases that won't fit easily
cvsdist a5082c
#   into the test data above.  
cvsdist a5082c
#   They are not combined with any other tests.
cvsdist a5082c
#
cvsdist a5082c
# Format: "string", month, day, year, hour, minute, [offset]
cvsdist a5082c
#
cvsdist a5082c
@misc_tests = 
cvsdist a5082c
(
cvsdist a5082c
# Test moving back and forth across DST
cvsdist a5082c
[ "March 1 + 3 months",		 '6', '1', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "June 1 - 3 months",		 '3', '1', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "September 1 + 3 months",	'12', '1', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "December 1 - 3 months",	 '9', '1', '$y', '$h', '$mi' ],
cvsdist a5082c
[ "March 1 + 12 weeks",		 '3', '1', '$y', '$h', '$mi', '+12 * WEEK' ],
cvsdist a5082c
[ "June 1 - 12 weeks",		 '6', '1', '$y', '$h', '$mi', '-12 * WEEK' ],
cvsdist a5082c
[ "September 1 + 12 weeks",	 '9', '1', '$y', '$h', '$mi', '+12 * WEEK' ],
cvsdist a5082c
[ "December 1 - 12 weeks",	'12', '1', '$y', '$h', '$mi', '-12 * WEEK' ],
cvsdist a5082c
);
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
$num_tests =   ($#date_tests + 1)
cvsdist a5082c
	     + ($#time_tests + 1)
cvsdist a5082c
	     + ($#misc_tests + 1)
cvsdist a5082c
	     + ($#date_time_tests_time + 1) * ($#date_time_tests_date + 1)
cvsdist a5082c
	     + ($#date_time_tests_time + 1) * ($#inc_dec_tests        + 1)
cvsdist a5082c
	     + ($#date_time_tests_date + 1) * ($#inc_dec_tests        + 1)
cvsdist a5082c
	     ;
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Print out the number of tests to perform
cvsdist a5082c
#
cvsdist a5082c
print "1..$num_tests\n";
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Run date, time and miscellaneous tests
cvsdist a5082c
#
cvsdist a5082c
foreach my $i (@date_tests, @time_tests, @misc_tests)
cvsdist a5082c
{
cvsdist a5082c
    my $s;	# current second
cvsdist a5082c
    my $mi;	# current minute
cvsdist a5082c
    my $h;	# current hour
cvsdist a5082c
    my $d;	# current day
cvsdist a5082c
    my $mo;	# current month
cvsdist a5082c
    my $y;	# current year
cvsdist a5082c
    my $wd;	# current week day
cvsdist a5082c
    my $yd;	# current year day
cvsdist a5082c
    my $dst;	# is daylight savings time?
cvsdist a5082c
cvsdist a5082c
    my $epoch_time;	# time string in epoch seconds
cvsdist a5082c
    my $offset = 0;	# offset for test in epoch seconds
cvsdist a5082c
    my $t;		# time string to test against
cvsdist a5082c
cvsdist a5082c
    my $o;		# output of parsetest command
cvsdist a5082c
    my $run_time;	# internal timestamp used for comparison
cvsdist a5082c
cvsdist a5082c
    ## WARNING:  Next two statements could run in different minutes!
cvsdist a5082c
    $o = `./parsetest \"$$i[0]\" $show_stderr`;
cvsdist a5082c
    $run_time = time();
cvsdist a5082c
cvsdist a5082c
    ## Set variables for $run_time before calculating $offset
cvsdist a5082c
    ($s, $mi, $h, $d, $mo, $y, $wd, $yd, $dst) = localtime($run_time);
cvsdist a5082c
    $mo += 1;
cvsdist a5082c
    $y += 1900;
cvsdist a5082c
cvsdist a5082c
    $offset = eval "$$i[6]" if (defined $$i[6]);
cvsdist a5082c
cvsdist a5082c
    $epoch_time = strftime("%s",
cvsdist a5082c
			   0,
cvsdist a5082c
			   eval "$$i[5]",
cvsdist a5082c
			   eval "$$i[4]",
cvsdist a5082c
			   eval "$$i[2]",
cvsdist a5082c
			   eval "$$i[1] - 1",
cvsdist a5082c
			   eval "$$i[3] - 1900",
cvsdist a5082c
			   -1, # wday
cvsdist a5082c
			   -1, # yday
cvsdist a5082c
			   -1, # isdst
cvsdist a5082c
			  );
cvsdist a5082c
cvsdist a5082c
    ## Adjust +-1 hour when moving in or out of DST
cvsdist a5082c
    if (     is_dst($epoch_time) && ! is_dst($epoch_time + $offset))
cvsdist a5082c
    {	# DST to no DST
cvsdist a5082c
	$epoch_time += 1 * HOUR;
cvsdist a5082c
    }
cvsdist a5082c
    elsif (! is_dst($epoch_time) &&   is_dst($epoch_time + $offset))
cvsdist a5082c
    {	# no DST to DST
cvsdist a5082c
	$epoch_time -= 1 * HOUR;
cvsdist a5082c
    }
cvsdist a5082c
cvsdist a5082c
    $t = strftime("%a %b %e %H:%M:00 %Y", localtime($epoch_time + $offset));
cvsdist a5082c
cvsdist a5082c
    chomp $o;
cvsdist a5082c
cvsdist a5082c
    print $o eq $t ? "ok" : "not ok", "\n";
cvsdist a5082c
cvsdist a5082c
    print "'", $$i[0], "': '$o' =? '$t'\n"
cvsdist a5082c
	if ($verbose > 1 || ($verbose == 1 && $o ne $t));
cvsdist a5082c
}
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Run time + date tests
cvsdist a5082c
#
cvsdist a5082c
foreach my $i (@date_time_tests_time)
cvsdist a5082c
{
cvsdist a5082c
    foreach my $j (@date_time_tests_date)
cvsdist a5082c
    {
cvsdist a5082c
        my $s;	# current second
cvsdist a5082c
        my $mi;	# current minute
cvsdist a5082c
        my $h;	# current hour
cvsdist a5082c
        my $d;	# current day
cvsdist a5082c
        my $mo;	# current month
cvsdist a5082c
        my $y;	# current year
cvsdist a5082c
        my $wd;	# current week day
cvsdist a5082c
        my $yd;	# current year day
cvsdist a5082c
        my $dst;	# is daylight savings time?
cvsdist a5082c
cvsdist a5082c
	my $epoch_time;	# time string in epoch seconds
cvsdist a5082c
	my $offset = 0;	# offset for test in epoch seconds
cvsdist a5082c
	my $t;		# time string to test against
cvsdist a5082c
cvsdist a5082c
        my $o;		# output of parsetest command
cvsdist a5082c
        my $run_time;	# internal timestamp used for comparison
cvsdist a5082c
cvsdist a5082c
        ## WARNING:  Next two statements could run in different minutes!
cvsdist a5082c
        $o = `./parsetest \"$$i[0] $$j[0]\" $show_stderr`;
cvsdist a5082c
        $run_time = time();
cvsdist a5082c
cvsdist a5082c
        ## Set variables for $run_time before calculating $offset
cvsdist a5082c
        ($s, $mi, $h, $d, $mo, $y, $wd, $yd, $dst) = localtime($run_time);
cvsdist a5082c
        $mo += 1;
cvsdist a5082c
        $y += 1900;
cvsdist a5082c
cvsdist a5082c
	if (defined $$i[6])
cvsdist a5082c
	{
cvsdist a5082c
	    if (defined $$j[6])
cvsdist a5082c
	    {
cvsdist a5082c
	        $offset = eval "($$i[6]) + ($$j[6])";
cvsdist a5082c
	    }
cvsdist a5082c
	    else
cvsdist a5082c
	    {
cvsdist a5082c
	        $offset = eval "$$i[6]";
cvsdist a5082c
	    }
cvsdist a5082c
	}
cvsdist a5082c
	elsif (defined $$j[6])
cvsdist a5082c
	{
cvsdist a5082c
	    $offset = eval "$$j[6]";
cvsdist a5082c
	}
cvsdist a5082c
cvsdist a5082c
	$epoch_time = strftime("%s",
cvsdist a5082c
			       0,
cvsdist a5082c
			       eval "$$i[5]",
cvsdist a5082c
			       eval "$$i[4]",
cvsdist a5082c
			       eval "$$j[2]",
cvsdist a5082c
			       eval "$$j[1] - 1",
cvsdist a5082c
			       eval "$$j[3] - 1900",
cvsdist a5082c
			       -1, # wday
cvsdist a5082c
			       -1, # yday
cvsdist a5082c
			       -1, # isdst
cvsdist a5082c
			      );
cvsdist a5082c
cvsdist a5082c
	## Adjust +-1 hour when moving in or out of DST
cvsdist a5082c
	if (     is_dst($epoch_time) && ! is_dst($epoch_time + $offset))
cvsdist a5082c
	{   # DST to no DST
cvsdist a5082c
	    $epoch_time += 1 * HOUR;
cvsdist a5082c
	}
cvsdist a5082c
	elsif (! is_dst($epoch_time) &&   is_dst($epoch_time + $offset))
cvsdist a5082c
	{   # no DST to DST
cvsdist a5082c
	    $epoch_time -= 1 * HOUR;
cvsdist a5082c
	}
cvsdist a5082c
cvsdist a5082c
	$t = strftime("%a %b %e %H:%M:00 %Y", localtime($epoch_time + $offset));
cvsdist a5082c
cvsdist a5082c
        chomp $o;
cvsdist a5082c
cvsdist a5082c
        print $o eq $t ? "ok" : "not ok", "\n";
cvsdist a5082c
cvsdist a5082c
        print "'$$i[0] $$j[0]': '$o' =? '$t'\n"
cvsdist a5082c
	    if ($verbose > 1 || ($verbose == 1 && $o ne $t));
cvsdist a5082c
    }
cvsdist a5082c
}
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Run time + inc_dec and date + inc_dec tests
cvsdist a5082c
#
cvsdist a5082c
foreach my $i (@date_time_tests_time, @date_time_tests_date)
cvsdist a5082c
{
cvsdist a5082c
    foreach my $j (@inc_dec_tests)
cvsdist a5082c
    {
cvsdist a5082c
        my $s;	# current second
cvsdist a5082c
        my $mi;	# current minute
cvsdist a5082c
        my $h;	# current hour
cvsdist a5082c
        my $d;	# current day
cvsdist a5082c
        my $mo;	# current month
cvsdist a5082c
        my $y;	# current year
cvsdist a5082c
        my $wd;	# current week day
cvsdist a5082c
        my $yd;	# current year day
cvsdist a5082c
        my $dst;	# is daylight savings time?
cvsdist a5082c
cvsdist a5082c
	my $epoch_time;	# time string in epoch seconds
cvsdist a5082c
	my $offset = 0;	# offset for test in epoch seconds
cvsdist a5082c
	my $t;		# time string to test against
cvsdist a5082c
cvsdist a5082c
        my $o;	# output of parsetest command
cvsdist a5082c
        my $run_time;	# internal timestamp used for comparison
cvsdist a5082c
cvsdist a5082c
        ## WARNING:  Next two statements could run in different minutes!
cvsdist a5082c
        $o = `./parsetest \"$$i[0] $$j[0]\" $show_stderr`;
cvsdist a5082c
        $run_time = time();
cvsdist a5082c
cvsdist a5082c
        ## Set variables for $run_time before calculating $offset
cvsdist a5082c
        ($s, $mi, $h, $d, $mo, $y, $wd, $yd, $dst) = localtime($run_time);
cvsdist a5082c
        $mo += 1;
cvsdist a5082c
        $y += 1900;
cvsdist a5082c
cvsdist a5082c
	if (defined $$i[6])
cvsdist a5082c
	{
cvsdist a5082c
	    if (defined $$j[6])
cvsdist a5082c
	    {
cvsdist a5082c
	        $offset = eval "($$i[6]) + ($$j[6])";
cvsdist a5082c
	    }
cvsdist a5082c
	    else
cvsdist a5082c
	    {
cvsdist a5082c
	        $offset = eval "$$i[6]";
cvsdist a5082c
	    }
cvsdist a5082c
	}
cvsdist a5082c
	elsif (defined $$j[6])
cvsdist a5082c
	{
cvsdist a5082c
	    $offset = eval "$$j[6]";
cvsdist a5082c
	}
cvsdist a5082c
cvsdist a5082c
        $epoch_time = strftime("%s",
cvsdist a5082c
			       0,
cvsdist a5082c
			       eval "$$i[5]",
cvsdist a5082c
			       eval "$$i[4]",
cvsdist a5082c
			       eval "eval \"$$j[2]\"",
cvsdist a5082c
			       eval "eval \"$$j[1] - 1\"",
cvsdist a5082c
			       eval "eval \"$$j[3] - 1900\"",
cvsdist a5082c
			       -1, # wday
cvsdist a5082c
			       -1, # yday
cvsdist a5082c
			       -1, # isdst
cvsdist a5082c
			      );
cvsdist a5082c
cvsdist a5082c
	## Adjust +-1 hour when moving in or out of DST
cvsdist a5082c
	if (     is_dst($epoch_time) && ! is_dst($epoch_time + $offset))
cvsdist a5082c
	{   # DST to no DST
cvsdist a5082c
	    $epoch_time += 1 * HOUR;
cvsdist a5082c
	}
cvsdist a5082c
	elsif (! is_dst($epoch_time) &&   is_dst($epoch_time + $offset))
cvsdist a5082c
	{   # no DST to DST
cvsdist a5082c
	    $epoch_time -= 1 * HOUR;
cvsdist a5082c
	}
cvsdist a5082c
cvsdist a5082c
	$t = strftime("%a %b %e %H:%M:00 %Y", localtime($epoch_time + $offset));
cvsdist a5082c
cvsdist a5082c
        chomp $o;
cvsdist a5082c
cvsdist a5082c
        print $o eq $t ? "ok" : "not ok", "\n";
cvsdist a5082c
cvsdist a5082c
        print "'$$i[0] $$j[0]': '$o' =? '$t'\n"
cvsdist a5082c
	    if ($verbose > 1 || ($verbose == 1 && $o ne $t));
cvsdist a5082c
    }
cvsdist a5082c
}
cvsdist a5082c
cvsdist a5082c
exit 0;
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Subroutine:
cvsdist a5082c
#   is_dst
cvsdist a5082c
#
cvsdist a5082c
# Description:
cvsdist a5082c
#   returns true if the time passed in is in DST, else
cvsdist a5082c
#   returns false if the time passed in is not in DST
cvsdist a5082c
#
cvsdist a5082c
# Arg 1:
cvsdist a5082c
#   [Optional] time in epoch seconds; defaults to the current 
cvsdist a5082c
#   time if no argument is given
cvsdist a5082c
#
cvsdist a5082c
sub is_dst (;$)
cvsdist a5082c
{
cvsdist a5082c
    my $t = shift || time();
cvsdist a5082c
    return ((localtime($t))[8] > 0);
cvsdist a5082c
}
cvsdist a5082c
cvsdist a5082c
cvsdist a5082c
#
cvsdist a5082c
# Subroutine:
cvsdist a5082c
#   get_utc_offset
cvsdist a5082c
#
cvsdist a5082c
# Description:
cvsdist a5082c
#   returns the number of offest hours from UTC for the current timezone
cvsdist a5082c
#
cvsdist a5082c
# Arg 1:
cvsdist a5082c
#   [Optional] time in epoch seconds; defaults to the current 
cvsdist a5082c
#   time if no argument is given
cvsdist a5082c
#
cvsdist a5082c
sub get_utc_offset (;$)
cvsdist a5082c
{
cvsdist a5082c
    my $t = shift || time();
cvsdist a5082c
    my @t = localtime($t);
cvsdist a5082c
    my $is_dst = $t[8];
cvsdist a5082c
    return ((timelocal(@t) - timegm(@t) + ($is_dst > 0 ? HOUR : 0)) / MINUTE);
cvsdist a5082c
}
cvsdist a5082c