From: Andrew Ruthven Date: Mon, 28 Oct 2013 09:35:26 +0000 (+1300) Subject: Allow pretending to run on a specific date for testing. X-Git-Tag: 0.10.4~2 X-Git-Url: http://git.etc.gen.nz/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f37d1448edadd804099d5d01cae0fa362ab34b42;p=mythtv-status.git Allow pretending to run on a specific date for testing. --- diff --git a/ChangeLog b/ChangeLog index be3e471..3695b12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,9 @@ Fix up processing of dates with oldstyle timestamps for in progress recordings. + Add support to specify the date we're running mythtv-status on + so that we can test various scenarios. + 2013-10-27 Andrew Ruthven Handle the handling in POD in Perl 5.18. Force the return code =item lines to be handled correctly. diff --git a/bin/mythtv-status b/bin/mythtv-status index cf8dcdc..fd1b918 100755 --- a/bin/mythtv-status +++ b/bin/mythtv-status @@ -126,6 +126,7 @@ GetOptions( 'file=s' => \$c->{'xml_file'}, 's|save-file=s' => \$c->{'save_file'}, + 'date=s' => \$c->{'date'}, 'verbose' => \$verbose, 'help|?' => \$help, ) || pod2usage("\nUse --help for help.\n"); @@ -324,7 +325,11 @@ my @blocks = ( }, }, 'subs' => { - 'find_next' => sub { $warn_present ||= 1; $next_time = 'now' } + 'find_next' => + sub { + $warn_present ||= 1; + $next_time = $c->{'date'} || 'now'; + } } }, @@ -461,7 +466,7 @@ my @blocks = ( if $next_time eq 'Never' || $next_time eq 'now'; my $err; - my $delta = DateCalc('now', $next_time, \$err, 0); + my $delta = DateCalc($c->{'date'} || 'now', $next_time, \$err, 0); my $seconds = Delta_Format($delta, 'approx', 0, '%sh'); # If the next recording is more than 1 day in the future, @@ -549,6 +554,16 @@ my @blocks = ( our $today = substr(ParseDate('today'), 0, 8); our $tomorrow = substr(ParseDate('tomorrow'), 0, 8); +if ($c->{'date'}) { + $today = substr(ParseDate($c->{'date'}), 0, 8); + $tomorrow = substr(DateCalc($c->{'date'}, ParseDateDelta('1 day')), 0, 8); +} + +if ($verbose) { + print "Today: $today\n"; + print "Tomorrow: $tomorrow\n"; +} + # If we're in return code only mode then we disable all blocks # except for those explicitly enabled. if ($return_code_only) { @@ -1257,6 +1272,10 @@ about to be recorded. Use colour when showing the status of the encoder(s). +=item B<--date> + +Set the date to run as, used for debugging purposes. + =item B<-d, --description> Display the description for the scheduled recordings. diff --git a/t/01-test-help.t b/t/01-test-help.t index 6c343ee..2052686 100644 --- a/t/01-test-help.t +++ b/t/01-test-help.t @@ -29,6 +29,9 @@ Options: -c, --colour Use colour when showing the status of the encoder(s). + --date + Set the date to run as, used for debugging purposes. + -d, --description Display the description for the scheduled recordings. diff --git a/t/15-unicode.t b/t/15-unicode.t index e80e9ff..344015e 100644 --- a/t/15-unicode.t +++ b/t/15-unicode.t @@ -7,7 +7,7 @@ use FindBin qw/$Bin/; my $xml = "$Bin/xml/wide-character.xml"; # Test that the guide data warning is present. -my $out = `$Bin/../bin/mythtv-status -d --file $xml 2>&1`; +my $out = `$Bin/../bin/mythtv-status -d --file $xml --date '2012-07-07 22:12' 2>&1`; #diag($out);