1Time::Duration::Parse(3U)ser Contributed Perl DocumentatiToinme::Duration::Parse(3)
2
3
4
6 Time::Duration::Parse - Parse string that represents time duration
7
9 use Time::Duration::Parse;
10
11 my $seconds = parse_duration("2 minutes and 3 seconds"); # 123
12
14 Time::Duration::Parse is a module to parse human readable duration
15 strings like 2 minutes and 3 seconds to seconds.
16
17 It does the opposite of "duration_exact" in Time::Duration function in
18 Time::Duration and is roundtrip safe. So, the following is always
19 true.
20
21 use Time::Duration::Parse;
22 use Time::Duration;
23
24 my $seconds = int rand 100000;
25 is( parse_duration(duration_exact($seconds)), $seconds );
26
28 parse_duration
29 $seconds = parse_duration($string);
30
31 Parses duration string and returns seconds. When it encounters an
32 error in a given string, it dies with an exception saying "Unknown
33 timespec: blah blah blah". This function is exported by default.
34
36 Time::Duration::Parse::More has the same interface as this module, but
37 supports more expressions and memoization.
38
39 Time::Duration can be used for the reverse of this module: given a
40 number of seconds it will provide an English description of the
41 duration.
42
43 Time::Duration::Object provides an OO interface to Time::Duration.
44
45 Time::Duration::LocaleObject provides an OO interface to the
46 "Time::Duration::??" modules, which provide language-specific versions
47 of Time::Duration.
48
49 DateTime::Format::Duration can be used to parse natural language
50 descriptions of durations, returning an instance of DateTime::Duration,
51 which can then be converted to seconds using the "in_units()" method.
52
54 <https://github.com/neilb/Time-Duration-Parse>
55
57 Tatsuhiko Miyagawa <miyagawa@bulknews.net>
58
60 This library is free software; you can redistribute it and/or modify it
61 under the same terms as Perl itself.
62
63 Some internal code is taken from Cache and Cache::Cache modules on
64 CPAN.
65
66
67
68perl v5.28.2 2019-05-12 Time::Duration::Parse(3)