Ticket #11079: mythtv.perlutc.patch

File mythtv.perlutc.patch, 2.7 KB (added by Bradley Baetz <bbaetz@…>, 8 years ago)

Patch for mythtv perl bindings

  • mythtv/bindings/perl/Makefile.PL

    diff --git a/mythtv/bindings/perl/Makefile.PL b/mythtv/bindings/perl/Makefile.PL
    index d072d29..49c4930 100644
    a b WriteMakefile( 
    1818                            'Config'           => 0,
    1919                            'DBI'              => 0,
    2020                            'DBD::mysql'       => 0,
    21                             'Date::Manip'      => 0,
    2221                            'Fcntl'            => 0,
    2322                            'File::Copy'       => 0,
    2423                            'HTTP::Request'    => 0,
  • mythtv/bindings/perl/MythTV.pm

    diff --git a/mythtv/bindings/perl/MythTV.pm b/mythtv/bindings/perl/MythTV.pm
    index cb0d055..fae7b77 100644
    a b package MythTV; 
    2323    use DBI;
    2424    use HTTP::Request;
    2525    use LWP::UserAgent;
    26     use Time::Local;
     26    use POSIX;
    2727
    2828# Load the UPNP libraries if we have them, but die nicely if we don't.
    2929    BEGIN {
    EOF 
    372372                                      $self->{'db_user'},
    373373                                      $self->{'db_pass'})
    374374            or die "Cannot connect to database: $!\n\n";
     375        $self->{'dbh'}->do("SET time_zone = 'UTC'")
     376            or die "Can't set timezone: $!\n\n";
    375377
    376378    # Check for supported schema version
    377379        $self->{'schema_version'} = $self->backend_setting('DBSchemaVer');
    EOF 
    798800        if ($time =~ /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
    799801            return "$1-$2-${3}T$4:$5:$6";
    800802        }
    801     # Otherwise, format it as necessary.  We have to use MySQL here because
    802     # Date::Manip is not aware of DST differences.  Yay.  Blech.
    803         my $sh = $self->{'dbh'}->prepare('SELECT FROM_UNIXTIME(?)');
    804         $sh->execute($time);    # Assumed to be a correct epoch time (in GMT)
    805         ($time) = $sh->fetchrow_array();
    806         $time =~ s/\s/T/;
    807         return $time;
     803    # Otherwise, format it as necessary.
     804        return POSIX::strftime("%Y-%m-%dT%H:%M:%S", gmtime($time));
    808805    }
    809806
    810807# Format a MythTV timestamp into a unix timestamp.  This function is exported.
    811 # We have to use MySQL here because Date::Manip is not aware of DST.
     808# We have to use MySQL here because it was used historically, and so the
     809# formats that MySQL supports is effectively the API...
    812810    sub myth_to_unix_time {
    813811        my $self = (ref $_[0] ? shift : $MythTV::last);
    814812        my $time = shift;
    815813        my $sh = $self->{'dbh'}->prepare('SELECT UNIX_TIMESTAMP(?)');
    816814        $sh->execute($time);
    817815        ($time) = $sh->fetchrow_array();
    818         my @t = localtime(time);
    819         my $offset = timegm(@t) - timelocal(@t);
    820         return $time - $offset;
     816        return $time;
    821817    }
    822818
    823819# Create a new MythTV::Program object