HTML::...ration(3pm)

πŸ’– HTML::Microformats::Datatype::Duration β€” bestie edition πŸ’–

okay so you found the docs for HTML::Microformats::Datatype::Duration, a Perl module from the User Contributed Perl Documentation collection, and honestly? it's giving "floating periods of time" and we're obsessed. πŸ’…


✨ NAME ✨

HTML::Microformats::Datatype::Duration β€” floating periods of time πŸ•°οΈβœ¨


🌸 SYNOPSIS 🌸

my $duration = HTML::Microformats::Datatype::Duration->new($d);
print "$duration\n";

literally that's it, that's the whole vibe check. πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

πŸŽ€ Constructors πŸŽ€

  • $d = HTML::Microformats::Datatype::Duration->new($duration) β€” makes you a brand new HTML::Microformats::Datatype::Duration object, no cap.

$duration is a DateTime::Duration object. periodt.

  • $d = HTML::Microformats::Datatype::Duration->parse($string, $elem, $context) β€” also makes you a shiny new HTML::Microformats::Datatype::Duration object, but from parsing. slay.

$string is a duration written in ISO 8601 format, like for example: 'P1Y' or 'PT2H29M58.682S'. $elem is the XML::LibXML::Element that's being parsed. $context is the document context.

The standard way of representing durations in Microformats is as an ISO 8601 string, iykyk:

<abbr class="duration" title="P4DT4H">4 and a half days</abbr>

but wait, there's more πŸ’– This constructor also supports a bunch 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>

(yes bestie, that claa is in the original, we do not edit, we only report πŸ“)

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>

πŸ’… Public Methods πŸ’…

  • $d->duration β€” hands you back a DateTime::Duration object. 🫢
  • $d->to_string β€” hands you back an ISO 8601 formatted string that represents the duration. ✨
  • $d->datatype β€” returns the RDF datatype URI that represents the data type of this literal. 🌈

🧚 Functions 🧚

  • compare($a, $b) β€” compares durations $a and $b. The return values are exactly as per 'cmp' (go peek at perlfunc if you need a refresher). πŸ‘‘
⚠️ real talk bestie: 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. math but make it cute πŸ“

This function is not exported by default.

Can also be used as a method:

$c = $a->add($b);
  • $c = subtract($a, $b) β€” subtracts duration $b from $a. πŸ’€

This function is not exported by default.

Can also be used as a method:

$c = $a->subtract($b);

😭 BUGS 😭

please report any bugs to <http://rt.cpan.org/>. we're listening, bestie 🫢


⭐ SEE ALSO ⭐

HTML::Microformats, HTML::Microformats::Datatype, DateTime::Duration. the holy trinity of "go read these next" πŸ’œ


πŸ‘‘ AUTHOR πŸ‘‘

Toby Inkster <tobyink@cpan.org>. iconic. ✨


Copyright 2008-2012 Toby Inkster

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


πŸ’€ DISCLAIMER OF WARRANTIES πŸ’€

THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.

fr fr, no warranty, we said what we said. 😀

and that's the whole page, bestie πŸ’… this was HTML::...ration(3pm) from perl v5.32.1, dated 2021-09-12 β€” go forth and parse those durations, main character. πŸ¦‹πŸ’–

πŸ“¦ where this page comes from