HTML::Microformats::Datatype::Duration - floating periods of time
my $duration = HTML::Microformats::Datatype::Duration->new($d); print "$duration\n";
$d = HTML::Microformats::Datatype::Duration->new($duration)
Creates a new HTML::Microformats::Datatype::Duration object.
$duration is a DateTime::Duration object.
$d = HTML::Microformats::Datatype::Duration->parse($string, $elem, $context)
$string is a duration represented in ISO 8601 format, for example: 'P1Y' or 'PT2H29M58.682S'. $elem is the XML::LibXML::Element being parsed. $context is the document context.
The standard way of representing durations in Microformats is as an ISO 8601 string:
<abbr class="duration" title="P4DT4H">4 and a half days</abbr>
This constructor also supports a number of experimental microformat duration patterns. ISO-31 class names are supported:
<div class="duration"> <span claa="d">4</span> and <abbr title="12" class="h">a half</abbr> days. </div>
As are metric/SI measures (in seconds):
<span class="duration">124 s</span> <span class="duration">124</span> seconds
Or using an hMeasure microformat with no 'item' property, the 'type' property either absent or a case-insensitive match of 'duration' and a unit property of 's'/'sec'/'seconds', 'min'/'minutes', 'h'/'hours' or 'd'/'days'. For example:
<span class="duration hmeasure"> <b class="unit">Days</b>: <span class="num">4.5</span> </span>
$d->duration
Returns a DateTime::Duration object.
$d->to_string
Returns an ISO 8601 formatted string representing the duration.
$d->datatype
Returns an the RDF datatype URI representing the data type of this literal.
compare($a, $b)
Compares durations $a and $b. Return values are as per 'cmp' (see perlfunc).
Note that there is not always a consistent answer when comparing durations. 30 days is longer than a month in February, but shorter than a month in January. Durations are compared as if they were applied to the current datetime (i.e. now).
This function is not exported by default.
Can also be used as a method:
$a->compare($b);
$c = add($a, $b)
Adds two durations together.
$c = $a->add($b);
$c = subtract($a, $b)
Subtracts duration $b from $a.
$c = $a->subtract($b);
Please report any bugs to http://rt.cpan.org/.
HTML::Microformats, HTML::Microformats::Datatype, DateTime::Duration.
Toby Inkster <tobyink@cpan.org>.
Copyright 2008-2010 Toby Inkster
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install HTML::Microformats, copy and paste the appropriate command in to your terminal.
cpanm
cpanm HTML::Microformats
CPAN shell
perl -MCPAN -e shell install HTML::Microformats
For more information on module installation, please visit the detailed CPAN module installation guide.