Release of new module DateTime::Format::RelativeTime
[email protected] (Jacques Deguest) Fri, 17 Jan 2025 05:13:43 +0900
| Newsgroups | perl.datetime |
|---|---|
| Organization | DEGUEST Pte. Ltd. |
| Message-ID | <[email protected]> |
--------------V66P2SJ100n301xx1ufsZ5G9
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: quoted-printable
I have the pleasure to announce the release of the new Perl module=20
DateTime::Format::RelativeTime=20
<https://metacpan.org/pod/DateTime::Format::RelativeTime>, which is=20
designed to mirror its equivalent Web API Intl.RelativeTimeFormat=20
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global=
_Objects/Intl/RelativeTimeFormat>
It requires only Perl v5.10.1 to run, and uses an exception class to=20
return error or to die (if the option fatal is provided and set to a=20
true value).
You can use it the same way as the Web API:
use DateTime::Format::RelativeTime; my $fmt =3D=20
DateTime::Format::RelativeTime->new( =C2=A0=C2=A0=C2=A0 # You can use en-=
GB (Unicode /=20
web-style) or en_GB (system-style), it does not matter. =C2=A0=C2=A0=C2=A0=
'en_GB', {=20
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 localeMatcher =3D> 'best fit'=
, =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # see=20
getNumberingSystems() in Locale::Intl for the supported number systems=20
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 numberingSystem =3D> 'latn', =
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Possible values are: long,=20
short or narrow =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 style =3D> 'sh=
ort', =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Possible values are:=20
always or auto =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 numeric =3D> 'a=
lways', =C2=A0=C2=A0=C2=A0 }, ) || die(=20
DateTime::Format::RelativeTime->error ); # Format relative time using=20
negative value (-1). $fmt->format( -1, 'day' ); # "1 day ago" # Format=20
relative time using positive value (1). $fmt->format( 1, 'day' ); # "in=20
1 day"
You can read more about it on Perl.com here:=20
https://www.perl.com/article/release-of-new-module-datetime-format-relati=
vetime/#author-bio-jacques-deguest
Regards,
Jacques Deguest
--------------V66P2SJ100n301xx1ufsZ5G9
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html>
<html>
<head>
<meta http-equiv=3D"content-type" content=3D"text/html; charset=3DUTF=
-8">
</head>
<body>
<font face=3D"Avenir">I have the pleasure to announce the release of
the new Perl module <a
href=3D"https://metacpan.org/pod/DateTime::Format::RelativeTime">=
DateTime::Format::RelativeTime</a>,
which is designed to mirror its equivalent Web API <a
href=3D"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference=
/Global_Objects/Intl/RelativeTimeFormat">Intl.RelativeTimeFormat</a><br>
<br>
It requires only Perl v5.10.1 to run, and uses an exception class
to return error or to die (if the option fatal is provided and set
to a true value).<br>
<br>
You can use it the same way as the Web API:<br>
<br>
</font>
<pre><font face=3D"Courier New, Courier, monospace">use DateTime::For=
mat::RelativeTime;
my $fmt =3D DateTime::Format::RelativeTime->new(
=C2=A0=C2=A0=C2=A0 # You can use en-GB (Unicode / web-style) or en_GB (sy=
stem-style), it does not matter.
=C2=A0=C2=A0=C2=A0 'en_GB', {
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 localeMatcher =3D> 'best fi=
t',
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # see getNumberingSystems() in=
Locale::Intl for the supported number systems
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 numberingSystem =3D> 'latn'=
,
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Possible values are: long, s=
hort or narrow
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 style =3D> 'short',
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 # Possible values are: always =
or auto
=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 numeric =3D> 'always',
=C2=A0=C2=A0=C2=A0 },
) || die( DateTime::Format::RelativeTime->error );
# Format relative time using negative value (-1).
$fmt->format( -1, 'day' ); # "1 day ago"
# Format relative time using positive value (1).
$fmt->format( 1, 'day' ); # "in 1 day"
</font></pre>
<font face=3D"Avenir"><br>
You can read more about it on Perl.com here:
<a class=3D"moz-txt-link-freetext" href=3D"https://www.perl.com/article/r=
elease-of-new-module-datetime-format-relativetime/#author-bio-jacques-deg=
uest">https://www.perl.com/article/release-of-new-module-datetime-format-=
relativetime/#author-bio-jacques-deguest</a><br>
<br>
Regards,<br>
Jacques Deguest<br>
<br>
</font>
</body>
</html>
--------------V66P2SJ100n301xx1ufsZ5G9--