Monday, 27 April 2015

Dart POW - ( Package Of The Week) #5 : timeago

Sorry for the lack of posts - April has been busy! A combination of holidays, work deadlines and writing a book has made blogging impossible. The good news is that it is a Dart book - more details as I can share them!

Who is ready for another - Dart POW? A weekly look at an interesting Package on pub.dartlang.org

timeago is a Dart library for creating fuzzy timestamps, such as "15 minutes ago". Great for human friendly labeling of dynamic interfaces.

import 'package:timeago/timeago.dart';

main() async {
    TimeAgo time = new TimeAgo();
    int current = new DateTime.now().millisecondsSinceEpoch;
    
    print(time.timeAgo(current - (15 * 60 * 1000))); // 15 minutes ago
    
    //change locale
    await time.changeLocale("es");
    
    print(time.timeAgo(current - (15 * 60 * 1000))); // hace 15 minutos
}

Try out the live demo here.

Feel free to leave a comment with suggestions for the next Dart POW post! Don't be too shy to suggest your own package :-)