3 #==============================================================================
5 # File ID: cbb80cc6-a45e-11ea-944f-4f45262dc9b5
7 # Convert number of seconds to date format.
10 # ©opyleft 2020– Øyvind A. Holm <sunny@sunbase.org>
11 # License: GNU General Public License version 2 or later, see end of file for
13 #==============================================================================
31 $progname =~ s/^.*\/(.*?)$/$1/;
32 our $VERSION = '0.1.2';
34 Getopt
::Long
::Configure
('bundling');
37 'help|h' => \
$Opt{'help'},
38 'quiet|q+' => \
$Opt{'quiet'},
39 'verbose|v+' => \
$Opt{'verbose'},
40 'version' => \
$Opt{'version'},
42 ) || die("$progname: Option error. Use -h for help.\n");
44 $Opt{'verbose'} -= $Opt{'quiet'};
45 $Opt{'help'} && usage
(0);
46 if ($Opt{'version'}) {
56 if (defined($ARGV[0])) {
58 while (defined($ARGV[$i])) {
59 print(parse_line
($ARGV[$i]) . "\n");
63 while (my $line = <STDIN
>) {
64 print(parse_line
($line));
80 sprintf("%s%s%s%s", $1, $2, sec2date
($3), $4)
87 ($s =~ /^\d+$/) || return $s;
94 $secc{'year'} = $secc{'day'} * 365.25;
96 my $years = int($ss / $secc{'year'});
97 $ss -= $years * $secc{'year'};
98 my $days = int(($ss % $secc{'year'}) / $secc{'day'});
99 my $hours = int(($ss % $secc{'day'}) / $secc{'hour'});
100 my $mins = int(($ss % $secc{'hour'}) / $secc{'min'});
101 my $secs = $ss % $secc{'min'};
103 return sprintf("%us", $secs) if ($s < $secc{'min'});
104 return sprintf("%um:%02us", $mins, $secs) if ($s < $secc{'hour'});
105 return sprintf("%uh:%02um:%02us",
106 $hours, $mins, $secs) if ($s < $secc{'day'});
107 return sprintf("%ud:%02uh:%02um:%02us",
108 $days, $hours, $mins, $secs) if ($s < $secc{'year'});
109 return sprintf("%uy:%ud:%02uh:%02um:%02us",
110 $years, $days, $hours, $mins, $secs);
114 # Print program version
115 print("$progname $VERSION\n");
120 # Send the help message to stdout
123 if ($Opt{'verbose'}) {
129 Convert number of seconds to date format. If no arguments are specified,
132 Usage: $progname [options] [seconds [...]]
139 Be more quiet. Can be repeated to increase silence.
141 Increase level of verbosity. Can be repeated.
143 Print version information.
150 # Print a status message to stderr based on verbosity level
151 my ($verbose_level, $Txt) = @_;
153 if ($Opt{'verbose'} >= $verbose_level) {
154 print(STDERR
"$progname: $Txt\n");
161 # This program is free software; you can redistribute it and/or modify it under
162 # the terms of the GNU General Public License as published by the Free Software
163 # Foundation; either version 2 of the License, or (at your option) any later
166 # This program is distributed in the hope that it will be useful, but WITHOUT
167 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
168 # FOR A PARTICULAR PURPOSE.
169 # See the GNU General Public License for more details.
171 # You should have received a copy of the GNU General Public License along with
173 # If not, see L<http://www.gnu.org/licenses/>.
175 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :