The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

#!perl
## no critic: TestingAndDebugging::RequireUseStrict
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2024-01-13'; # DATE
our $DIST = 'App-SubtitleUtils'; # DIST
our $VERSION = '0.013'; # VERSION
$secs_re = qr/[+-]?\d+(?:\.\d*)?/;
$hms_re = qr/\d\d?:\d\d?:\d\d?(?:,\d\d\d)?/;
$hms_re_catch = qr/(\d\d?):(\d\d?):(\d\d?)(?:,(\d\d\d))?/;
sub hms2secs { local $_=shift; /^$hms_re_catch$/ or return; $1*3600+$2*60+$3+$4*0.001 }
sub secs2hms { local $_=shift; /^$secs_re$/ or return "00:00:00,000"; my $ms=1000*($_-int($_)); $_=int($_); my $s=$_%60; $_-=$s; $_/=60; my $m=$_%60; $_-=$m; $_/=60; sprintf "%02d:%02d:%02d,%03d",$_,$m,$s,$ms }
###
die "Usage: $0 SECS_OR_HMS\nIf SECS is entered, HMS is returned. Vice versa.\n" unless @ARGV;
for (@ARGV) {
if (/^$secs_re$/) {
print "$_ secs = ", secs2hms($_), "\n";
} elsif (/^$hms_re$/) {
print "$_ = ", hms2secs($_), " secs\n";
} else {
print "Invalid input: $_\n";
}
}
# ABSTRACT: Convert H:M:S to number of seconds, and vice versa
# PODNAME: srtcalc
__END__
=pod
=encoding UTF-8
=head1 NAME
srtcalc - Convert H:M:S to number of seconds, and vice versa
=head1 VERSION
This document describes version 0.013 of srtcalc (from Perl distribution App-SubtitleUtils), released on 2024-01-13.
=head1 SYNOPSIS
Return H:M:S:
% srtcalc <secs> [FILE] ...
Return number of seconds:
% srtcalc <h:m:s> [FILE] ...
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/App-SubtitleUtils>.
=head1 SOURCE
=head1 HISTORY
2003-02-06 - first written
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on
GitHub.
Most of the time, you don't need to build the distribution yourself. You can
simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your
system), you can install L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
that are considered a bug and can be reported to me.
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2024, 2022, 2021, 2020 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-SubtitleUtils>
When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.
=cut