Commits

Burak Gürsoy  committed a6b2510

Use gmtime for parser tests

  • Participants
  • Parent commits fc54607

Comments (0)

Files changed (4)

 Revision history for Perl extension Sys::Info::Driver::OSX.
 
+0.7951 Thu May 19 01:13:52 2011
+    => Use gmtime for parser tests.
+
 0.795 Mon May 16 04:09:54 2011
     => Swap support.
 

File lib/Sys/Info/Driver/OSX.pm

 use Capture::Tiny qw( capture );
 use Carp          qw( croak   );
 
-our $VERSION = '0.795';
+our $VERSION = '0.7951';
 our @EXPORT  = qw(
     fsysctl
     nsysctl

File lib/Sys/Info/Driver/OSX/OS.pm

 }
 
 sub _parse_uptime {
-    my($value, $key) = @_;
+    my($value, $key, $use_gmtime) = @_;
 
     if ( my @m = $value =~ m<\A[{](.+?)[}]\s+?(.+?)\z>xms ) {
         my($data, $stamp) = @m;
         my($hour, $min, $sec) = split m{:}xms, $hms;
 
         require Time::Local;
-        return Time::Local::timelocal(
-            $sec, $min, $hour, $mday, $mon, $year
-        );
+        my $converter = $use_gmtime ? \&Time::Local::timegm
+                                    : \&Time::Local::timelocal;
+        return $converter->( $sec, $min, $hour, $mday, $mon, $year );
     }
 
     return;

File t/01-parsers.t

     my $p     = \&Sys::Info::Driver::OSX::OS::_parse_uptime;
 
     my $stamp = q~Thu May 12 00:51:29 2011~;
-    my $up_10 = $p->( q~{ sec = 1305150689, usec = 0 } Thu May 12 00:51:29 2011~,
+    my $up_10 = $p->( q~{ sec = 1305161489, usec = 0 } Thu May 12 00:51:29 2011~,
                         'kern.boottime' );
-    my $up_08 = $p->( $stamp , 'kern.boottime' );
+    my $up_08 = $p->( $stamp , 'kern.boottime', 1 );
 
     ok( $up_10, 'Got uptime for v10' );
     ok( $up_08, 'Got uptime for v8'  );
 
-    is( scalar localtime $up_10, $stamp, 'Correct uptime for v10');
-    is( scalar localtime $up_08, $stamp, 'Correct uptime for v8' );
+    is( scalar gmtime $up_10, $stamp, 'Correct uptime for v10');
+    is( scalar gmtime $up_08, $stamp, 'Correct uptime for v8' );
 }