home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / perl / 5323 < prev    next >
Encoding:
Text File  |  1992-08-14  |  1.4 KB  |  50 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!destroyer!gatech!concert!rock!cole
  3. From: cole@concert.net (Derrick C. Cole)
  4. Subject: help with timelocal.pl
  5. Message-ID: <1992Aug14.190949.10466@rock.concert.net>
  6. Sender: news@rock.concert.net
  7. Organization: MCNC Data Operations
  8. Date: Fri, 14 Aug 1992 19:09:49 GMT
  9. Lines: 39
  10.  
  11. Greetings, again!
  12.  
  13. Does anyone have a good subroutine for computing the difference in seconds
  14. between two time stamps?  I'm trying to use timelocal() in mine, but it never
  15. returns:
  16.  
  17. require "/usr/local/lib/perl/timelocal.pl";
  18. chop($year = `date +\"\%y\"`);
  19.  
  20. %months = ('Jan', 0, 'Feb', 1, ...);
  21.  
  22. sub timediff {
  23.    local($now, $then) = @_; # $now and $then of the form "Mon Day H:M:S"
  24.  
  25.    ($nM, $nD, $nh, $nm, $ns) = $now =~ /^(\w+) (\d+) (\d+):(\d+):(.*)/;
  26.    ($tM, $tD, $th, $tm, $ts) = $then =~ /^(\w+) (\d+) (\d+):(\d+):(.*)/;
  27.  
  28.    $tsec = timelocal($ts, $tm, $th, $tD, $months{$tM}, $year);
  29.  
  30.    if ($months{$nM} < $months{$tM}) {
  31.       $year++;
  32.    }
  33.  
  34.    $nsec = timelocal($ns, $nm, $nh, $nD, $months{$nM}, $year);
  35.  
  36.    $diff = $nsec - $tsec;
  37. }
  38.  
  39. I'm doing something wrong, but can't figure out what it is (don't use packages
  40. very often, if that's it...)  Can anyone improve upon/fix this subroutine?
  41.  
  42. Any and all help greatly appreciated!
  43. Derrick Cole
  44.  
  45. -- 
  46. "If all the salmon caught in Canada in one year were laid end to end across the
  47. Sahara Desert, the smell would be absolutely awful."
  48.                        -- unknown
  49. ======
  50.