timeago 2.0.2 copy "timeago: ^2.0.2" to clipboard
timeago: ^2.0.2 copied to clipboard

outdated

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

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 and es_short. To add the remaining just call setLocaleMessages, 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.

1834
likes
0
pub points
100%
popularity

Publisher

unverified uploader

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

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on timeago