28 Sep 2014 08:44:24 UTC
- Distribution: DateTimeX-Format-Ago
- Module version: 0.005
- Source (raw)
- Browse (raw)
- How to Contribute
- Repository (git clone)
- Issues (0)
- Testers (1182 / 148 / 0)
- KwaliteeBus factor: 1
- 87.13% Coverage
- License: perl_5
- Perl: v5.10.0
- Activity24 month
- Download (17.88KB)
- MetaCPAN Explorer
- Subscribe to distribution
- This version
- Latest version++ed by:2 non-PAUSE usersTOBYINK Toby Inkster
- BUGS AND LIMITATIONS
- SEE ALSO
- COPYRIGHT AND LICENCE
- DISCLAIMER OF WARRANTIES
DateTimeX::Format::Ago - I should have written this module "3 years ago"
my $then = DateTime->now->subtract(days => 3); say DateTimeX::Format::Ago->format_datetime($then); # "3 days ago"
Ever wished DateTime::Format::Natural had a
format_datetimemethod? This module provides human-friendly datetime formatting, outputting strings like "3 days ago".
Primary use case: websites that show a list of a person's recent activities.
new(language => $lang)
Creates a formatter object for the given language (a BCP47 language code). If the language is omitted, extracts it from
Decent English ('en'), German ('de'), French ('fr'), Portuguese ('pt'), Korean ('ko'), and Indonesian ('id') support is provided. Castillian Spanish ('es') is also provided, but some of the strings were translated with Google Translate, so they might not be perfect.
Returns something like "3 days ago", "just now" or "hace un año".
Croaks. Don't use this.
Imagine the time is currently 2020-01-01T12:00:00.200. If you try to format the time 2020-01-01T12:00:00.100 you'll get back the result "in the future". So what's going on? DateTimeX::Format::Ago figures out when "now" is using
DateTime->now, which rounds back to the nearest whole second.
If you know you're going to be dealing with high resolution datetimes, and don't want to occasionally see "in the future" for times in the very recent past, then use Time::HiRes.
use Time::HiRes qw();
That's all you need to do. Merely loading it will give DateTimeX::Format::Ago an indication that you want it to use a more accurate idea of "now".
This module only supports a handful of languages. I'm seeking translations. Feel free to attach patches for other languages as bug reports.
Please report any bugs to http://rt.cpan.org/Dist/Display.html?Queue=DateTimeX-Format-Ago.
Toby Inkster <email@example.com>.
This software is copyright (c) 2011-2012, 2014 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
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.
Module Install Instructions
To install DateTimeX::Format::Ago, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell install DateTimeX::Format::Ago
For more information on module installation, please visit the detailed CPAN module installation guide.