timeago 2.0.28

Dart native js
Flutter Android iOS web

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

support

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 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
}

Adding new locales #

main() {
    final fifteenAgo = DateTime.now().subtract(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
}

Live Demo #

Here

Features and bugs #

Please file feature requests and bugs at the issue tracker.

318
likes
105
pub points
98%
popularity

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

Repository (GitHub)
View/report issues

Documentation

API reference

Uploader

a.araujo.azua@gmail.com

License

MIT (LICENSE)

More

Packages that depend on timeago