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.0';
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));
72 $l =~ s/^(\s*)(\d+)(.*?)$/sprintf("%s%s%s", $1, sec2date($2), $3)/e;
78 ($s =~ /^\d+$/) || return $s;
85 $secc{'year'} = $secc{'day'} * 365.25;
87 my $years = int($ss / $secc{'year'});
88 $ss -= $years * $secc{'year'};
89 my $days = int(($ss % $secc{'year'}) / $secc{'day'});
90 my $hours = int(($ss % $secc{'day'}) / $secc{'hour'});
91 my $mins = int(($ss % $secc{'hour'}) / $secc{'min'});
92 my $secs = $ss % $secc{'min'};
94 return sprintf("%us", $secs) if ($s < $secc{'min'});
95 return sprintf("%um:%02us", $mins, $secs) if ($s < $secc{'hour'});
96 return sprintf("%uh:%02um:%02us",
97 $hours, $mins, $secs) if ($s < $secc{'day'});
98 return sprintf("%ud:%02uh:%02um:%02us",
99 $days, $hours, $mins, $secs) if ($s < $secc{'year'});
100 return sprintf("%uy:%ud:%02uh:%02um:%02us",
101 $years, $days, $hours, $mins, $secs);
105 # Print program version
106 print("$progname $VERSION\n");
111 # Send the help message to stdout
114 if ($Opt{'verbose'}) {
120 Convert number of seconds to date format. If no arguments are specified,
123 Usage: $progname [options] [seconds [...]]
130 Be more quiet. Can be repeated to increase silence.
132 Increase level of verbosity. Can be repeated.
134 Print version information.
141 # Print a status message to stderr based on verbosity level
142 my ($verbose_level, $Txt) = @_;
144 if ($Opt{'verbose'} >= $verbose_level) {
145 print(STDERR
"$progname: $Txt\n");
152 # This program is free software; you can redistribute it and/or modify it under
153 # the terms of the GNU General Public License as published by the Free Software
154 # Foundation; either version 2 of the License, or (at your option) any later
157 # This program is distributed in the hope that it will be useful, but WITHOUT
158 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
159 # FOR A PARTICULAR PURPOSE.
160 # See the GNU General Public License for more details.
162 # You should have received a copy of the GNU General Public License along with
164 # If not, see L<http://www.gnu.org/licenses/>.
166 # vim: set ts=8 sw=8 sts=8 noet fo+=w tw=79 fenc=UTF-8 :