timeago 2.0.5 timeago: ^2.0.5 copied to clipboard
A library useful for creating fuzzy timestamps. (e.g. "15 minutes ago")
timeago #
A library useful for creating fuzzy timestamps. (e.g. "5 minutes ago")
About v2 #
-
v2 of this library does not depend on package
intl
anymore, It didn't make sense for the small amount of text and now we can use the same code for browser, Flutter and server. -
API is now a lot simpler, no need to create instance just use the
format
method. -
Allows to add and override locales messages with
setLocaleMessages
-
All v1 locale messages are available to use, currently library only loads by default
en
,en_short
,es
andes_short
. To add the remaining just callsetLocaleMessages
, see example.
Usage #
The easiest way to use this library via top-level function timeAgo(date)
:
import 'package:timeago/timeago.dart' as timeago;
main() {
final fifteenAgo = new DateTime.now().subtract(new Duration(minutes: 15));
print(timeago.format(fifteenAgo)); // 15 minutes ago
print(timeago.format(fifteenAgo, locale: 'en_short')); // 15m
print(timeago.format(fifteenAgo, locale: 'es')); // hace 15 minutos
}
Adding new locales #
main() {
final fifteenAgo = new DateTime.now().subtract(new Duration(minutes: 15));
// Add a new locale messages
timeago.setLocaleMessages('fr', timeago.FrMessages());
// Override a locale message
timeago.setLocaleMessages('en', CustomMessages());
print(timeago.format(fifteenAgo)); // 15 min ago
print(timeago.format(fifteenAgo, locale: 'fr')); // environ 15 minutes
}
Features and bugs #
Please file feature requests and bugs at the issue tracker.