JSCalendar-Duration
view release on metacpan or search on metacpan
lib/JSCalendar/Duration.pm view on Meta::CPAN
while ($toparse >= 60) {
$minutes++;
$toparse -= 60;
}
$durtime .= "${minutes}M" if $minutes;
my $seconds = 0;
while ($toparse >= 1) {
$seconds++;
$toparse -= 1;
}
$durtime .= "${seconds}" if $seconds;
if ($dec) {
$durtime .= $durtime ? ".${dec}S" : "0.${dec}S";
} elsif ($seconds) {
$durtime .= "S";
}
# P<zero>D
return "P0D" unless $durday || $durtime;
$durtime = "T$durtime" if $durtime;
return "P" . $durday . $durtime;
}
1;
=pod
=encoding UTF-8
=head1 NAME
JSCalendar::Duration - Convert seconds to JSCalendar durations and back
=head1 VERSION
version 0.004
=head1 SYNOPSIS
use JSCalendar::Duration qw(
seconds_to_duration
duration_to_seconds
);
# 104403.1
my $seconds = duration_to_seconds("P1DT5H3.1S");
# P1D
my $duration = seconds_to_duration('86400');
=head1 DESCRIPTION
This module converts between a duration of time as specified by seconds and
a JSCalendar duration (L<https://tools.ietf.org/html/draft-ietf-calext-jscalendar-00#section-3.2.3>).
=head1 PERL VERSION
This module should work on any version of perl still receiving updates from
the Perl 5 Porters. This means it should work on any version of perl released
in the last two to three years. (That is, if the most recently released
version is v5.40, then this module should work on both v5.40 and v5.38.)
Although it may work on older versions of perl, no guarantee is made that the
minimum required version will not be increased. The version may be increased
for any reason, and there is no promise that patches will be accepted to lower
the minimum required perl.
=head1 EXPORTS
=head2 seconds_to_duration
my $duration = seconds_to_duration("86401.2");
Converts seconds to a JSCalendar duration representation.
=head2 duration_to_seconds
my $seconds = duration_to_seconds("P1DT4H");
Converts a JSCalendar duration to seconds.
=head1 SEE ALSO
=over 4
=item L<https://tools.ietf.org/html/draft-ietf-calext-jscalendar-00#section-3.2.3>
The JSCalendar duration spec.
=back
=head1 AUTHOR
Matthew Horsfall <wolfsage@gmail.com>
=head1 CONTRIBUTORS
=for stopwords Mohammad S Anwar Ricardo Signes
=over 4
=item *
Mohammad S Anwar <mohammad.anwar@yahoo.com>
=item *
Ricardo Signes <rjbs@semiotic.systems>
=back
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2018 by Matthew Horsfall.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
__END__
#pod =head1 SYNOPSIS
#pod
#pod use JSCalendar::Duration qw(
#pod seconds_to_duration
#pod duration_to_seconds
#pod );
#pod
#pod # 104403.1
#pod my $seconds = duration_to_seconds("P1DT5H3.1S");
#pod
#pod # P1D
#pod my $duration = seconds_to_duration('86400');
#pod
#pod =head1 DESCRIPTION
#pod
#pod This module converts between a duration of time as specified by seconds and
#pod a JSCalendar duration (L<https://tools.ietf.org/html/draft-ietf-calext-jscalendar-00#section-3.2.3>).
#pod
#pod =head1 EXPORTS
#pod
#pod =head2 seconds_to_duration
#pod
#pod my $duration = seconds_to_duration("86401.2");
#pod
#pod Converts seconds to a JSCalendar duration representation.
#pod
#pod =head2 duration_to_seconds
#pod
#pod my $seconds = duration_to_seconds("P1DT4H");
#pod
#pod Converts a JSCalendar duration to seconds.
#pod
#pod =head1 SEE ALSO
#pod
#pod =over 4
#pod
#pod =item L<https://tools.ietf.org/html/draft-ietf-calext-jscalendar-00#section-3.2.3>
#pod
#pod The JSCalendar duration spec.
#pod
#pod =back
#pod
#pod =cut
( run in 1.567 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )