3 #=======================================================================
5 # File ID: 624dab98-fafa-11dd-831c-000475e441b9
8 # ©opyleft 2002– Øyvind A. Holm <sunny@sunbase.org>
9 # License: GNU General Public License, see end of file for legal stuff.
10 #=======================================================================
17 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
20 push(@main::version_array
, $rcs_id);
21 $VERSION = ($rcs_id =~ / (\d+) /, $1);
24 @EXPORT = qw(&sec_to_string &sec_to_readable);
30 # Convert seconds since 1970 to "yyyy-mm-dd hh:mm:ss" with optional
33 my ($Seconds, $Sep) = @_;
34 length($Seconds) || return(undef);
35 ($Seconds =~ /^(\d*)(\.\d+)?$/) || return(undef);
36 my $Secfrac = ($Seconds =~ /^([\-\d]*)(\.\d+)$/) ?
1.0*$2 : "";
39 defined($Sep) || ($Sep = " ");
40 my @TA = gmtime($Seconds);
41 my($DateString) = sprintf("%04u-%02u-%02u%s%02u:%02u:%02u%s",
42 $TA[5]+1900, $TA[4]+1, $TA[3], $Sep,
43 $TA[2], $TA[1], $TA[0], $Secfrac);
49 # Convert seconds since 1970 to human-readable format (d:hh:mm:ss)
52 my ($Day, $Hour, $Min, $Sec) =
55 length($Seconds) || ($Seconds = 0);
56 ($Seconds =~ /^(\d*)(\.\d+)?$/) || return(undef);
57 my $Secfrac = ($Seconds =~ /^(\d*)(\.\d+)$/) ?
1.0*$2 : "";
60 $Day = int($Seconds/86400);
61 $Seconds -= $Day * 86400;
63 $Hour = int($Seconds/3600);
64 $Seconds -= $Hour * 3600;
66 $Min = int($Seconds/60);
67 $Seconds -= $Min * 60;
71 return(sprintf("%u:%02u:%02u:%02u%s",
72 $Day, $Hour, $Min, $Sec, $Secfrac));