timeago 3.1.0
timeago: ^3.1.0 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")

Pub

Build Status

Usage #

The easiest way to use this library via top-level function format(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
}
IMPORTANT

You need to add the locales you are going to use in your app otherwise you will get the default english messages.

Currently, it has only english preloaded and spanish. But the library provides messages for several locales, see locale messages.

Adding locales #

main() {
    final fifteenAgo = DateTime.now().subtract(Duration(minutes: 15));

    // Add a new locale messages
    timeago.setLocaleMessages('fr', timeago.FrMessages());

    // You can override locale messages, with you own like this
    // where [MyCustomMessages] is a class that extends LookupMessages
    timeago.setLocaleMessages('en', MyCustomMessages());

    print(timeago.format(fifteenAgo)); // 15 min ago
    print(timeago.format(fifteenAgo, locale: 'fr')); // environ 15 minutes
}

For a complete example of adding all provided locales see example

Live Demo #

Here

Features and bugs #

Please file feature requests and bugs at the issue tracker.

685
likes
115
pub points
99%
popularity

A library useful for creating fuzzy timestamps. (e.g. "15 minutes ago")

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on timeago