3 #=======================================================================
7 # ©opyleft 2002– Øyvind A. Holm <sunny@sunbase.org>
8 # License: GNU General Public License, see end of file for legal stuff.
9 #=======================================================================
16 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
19 push(@main::version_array
, $rcs_id);
20 $VERSION = ($rcs_id =~ / (\d+) /, $1);
23 @EXPORT = qw(&sec_to_string &sec_to_readable);
29 # Convert seconds since 1970 to "yyyy-mm-dd hh:mm:ss" with optional
32 my ($Seconds, $Sep) = @_;
33 length($Seconds) || return(undef);
34 ($Seconds =~ /^(\d*)(\.\d+)?$/) || return(undef);
35 my $Secfrac = ($Seconds =~ /^([\-\d]*)(\.\d+)$/) ?
1.0*$2 : "";
38 defined($Sep) || ($Sep = " ");
39 my @TA = gmtime($Seconds);
40 my($DateString) = sprintf("%04u-%02u-%02u%s%02u:%02u:%02u%s",
41 $TA[5]+1900, $TA[4]+1, $TA[3], $Sep,
42 $TA[2], $TA[1], $TA[0], $Secfrac);
48 # Convert seconds since 1970 to human-readable format (d:hh:mm:ss)
51 my ($Day, $Hour, $Min, $Sec) =
54 length($Seconds) || ($Seconds = 0);
55 ($Seconds =~ /^(\d*)(\.\d+)?$/) || return(undef);
56 my $Secfrac = ($Seconds =~ /^(\d*)(\.\d+)$/) ?
1.0*$2 : "";
59 $Day = int($Seconds/86400);
60 $Seconds -= $Day * 86400;
62 $Hour = int($Seconds/3600);
63 $Seconds -= $Hour * 3600;
65 $Min = int($Seconds/60);
66 $Seconds -= $Min * 60;
70 return(sprintf("%u:%02u:%02u:%02u%s",
71 $Day, $Hour, $Min, $Sec, $Secfrac));