The logic is a bit brain damaged in this area of mythtv-status.  To be
correct, the output needs to include days and would appear as something
like:

Next Recording In: 1 Day, -1 Hour, -34 Minutes

Indeed if the day is always printed this output would be mathematically
correct.  I prefer an always-positive value.  This is equivalent to:

Next Recording In: 22 Hours, 25 Minutes

Also, since mythtv users are often using a script in /etc/pm/sleep.d/ to
rtcwake(8) the system for the next recording or next guide update to
schedule more recordings, an accurate, predictable, and complete value for
the next scheduled recording is desirable if mythtv-status is to be used. Here
is a patch for the corrected output:


*** /usr/bin/mythtv-status      2017-01-25 15:17:10.000000000 -0500
--- mythtv-status               2018-10-21 17:23:07.716212366 -0400
***************
*** 466,484 ****
          my $err;
          my $delta   = DateCalc($c->{'date'} || 'now', $next_time, \$err,
1);
          my $seconds = Delta_Format($delta, 'approx', 0, '%sh');

!       # If the next recording is more than 1 day in the future,
!       # print out the days and hours.
!       my $str;
!       if ($seconds > 24 * 3600) {
!         $str = Delta_Format($delta, 0, '%dh Days, %hv Hours');
!       } else {
!         $str = Delta_Format($delta, 0, '%hh Hours, %mv Minutes');
!       }
!
          $str =~ s/\b1 (Day|Hour|Minute)s/1 $1/g;
-         $str =~ s/\b0 (Days|Hours)(, )?//;
-         $str =~ s/, 0 Minutes$//;

          if ($seconds <= $c->{'recording_in_warn'}) {
            $warn_present ||= 1;
--- 466,485 ----
          my $err;
          my $delta   = DateCalc($c->{'date'} || 'now', $next_time, \$err,
1);
          my $seconds = Delta_Format($delta, 'approx', 0, '%sh');
+         my $nxtsec = $seconds;

!         # Days, hours, Min output.
!         if ($nxtsec > 24 * 3600) {
!           $str = sprintf("%d Days, ", $nxtsec/24/3600);
!           $nxtsec = $nxtsec % (24 *3600);
!         }
!         if ($nxtsec > 3600) {
!           $str .= sprintf("%d Hours, ", $nxtsec/3600);
!           $nxtsec = $nxtsec % 3600;
!         }
!         $str .= sprintf("%d Minutes", $nxtsec/60);
!         $str =~ s/, $//;
          $str =~ s/\b1 (Day|Hour|Minute)s/1 $1/g;

          if ($seconds <= $c->{'recording_in_warn'}) {
            $warn_present ||= 1;

Reply via email to