Time::D...n::Parse(3)

✨ NAME ✨

okay bestie, welcome to the Time::Duration::Parse(3) page from the User Contributed Perl Documentation πŸ’… β€” this is the module for parsing human-readable duration strings like 2 minutes and 3 seconds into seconds. It’s literally giving β€œturn vibes into numbers.” ✨

🌸 SYNOPSIS 🌸

use Time::Duration::Parse;

my $seconds = parse_duration("2 minutes and 3 seconds"); # 123

πŸ¦‹ DESCRIPTION πŸ¦‹

Time::Duration::Parse is a module to parse human readable duration strings like 2 minutes and 3 seconds to seconds. πŸŽ€

It does the opposite of the "duration_exact" in Time::Duration function in Time::Duration, and it is roundtrip safe. So bestie, the following is always true:

use Time::Duration::Parse;
use Time::Duration;

my $seconds = int rand 100000;
is( parse_duration(duration_exact($seconds)), $seconds );

πŸŽ€ FUNCTIONS πŸŽ€

πŸ’– parse_duration πŸ’–

$seconds = parse_duration($string);

Parses a duration string and returns seconds. When it encounters an error in a given string, it dies with an exception saying "Unknown timespec: blah blah blah". This function is exported by default. ✨

πŸ‘‘ SEE ALSO πŸ‘‘

  • Time::Duration::Parse::More has the same interface as this module, but supports more expressions and memoization. πŸ¦‹
  • Time::Duration can be used for the reverse of this module: given a number of seconds it will provide an English description of the duration. 🌸
  • Time::Duration::Object provides an OO interface to Time::Duration. πŸ’œ
  • Time::Duration::LocaleObject provides an OO interface to the "Time::Duration::??" modules, which provide language-specific versions of Time::Duration. πŸŽ€
  • DateTime::Format::Duration can be used to parse natural language descriptions of durations, returning an instance of DateTime::Duration, which can then be converted to seconds using the in_units() method. ✨

πŸ“¦ REPOSITORY πŸ“¦

The repo lives right here, bestie:

<https://github.com/neilb/Time-Duration-Parse>

πŸ’Œ AUTHOR πŸ’Œ

Tatsuhiko Miyagawa <miyagawa@bulknews.net> 🫢

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

Some internal code is taken from Cache and Cache::Cache modules on CPAN. ✨


later bestie 🫢 β€” this page comes from perl v5.42.0, dated 2021-05-20. πŸ’…

πŸ“¦ where this page comes from