timeago 0.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 49

timeago #

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

Usage #

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
}

Live Demo #

Here

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.0.1 #

  • Add en, en_short, es, and es_short locales

example/main.dart

import 'dart:html' as html;
import 'dart:async' show Timer;
import 'package:timeago/timeago.dart';

int fixedTime = new DateTime.now().millisecondsSinceEpoch;
main() {
  var autoElm = html.querySelector("#timeAgo") as html.SpanElement;

  var fuzzy = new TimeAgo();

  var updateElement = () {
    int currentTime = new DateTime.now().millisecondsSinceEpoch;
    autoElm.text = fuzzy.timeAgo(currentTime - (currentTime - fixedTime));
  };

  new Timer.periodic(new Duration(seconds: 1), (timer) {
    updateElement();
  });
  updateElement();

  //Other examples
  var otherElm = html.querySelector("#other") as html.UListElement;

  var addToOther = (str) {
    otherElm.append(new html.LIElement()..text = str);
  };

  addOtherExamples(fuzzy, addToOther);

  html.querySelectorAll("a").onClick.listen((event) async {
    var locale = event.target.text;
    await fuzzy.changeLocale(locale);
    otherElm.innerHtml = "";
    addOtherExamples(fuzzy, addToOther);
  });
}

addOtherExamples(TimeAgo fuzzy, Function addToOther) {
  addToOther(fuzzy.timeAgo(fixedTime - (1 * 44 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (1 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (5 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (50 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (5 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (25 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (5 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (5 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (13 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(fixedTime - (3 * 12 * 30 * 24 * 60 * 60 * 1000)));
  addToOther("-");
  addToOther(fuzzy.timeUntil(fixedTime - (1 * 44 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (1 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (5 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (50 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (5 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (25 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (5 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (5 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (13 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(fixedTime - (3 * 12 * 30 * 24 * 60 * 60 * 1000)));
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  timeago: ^0.0.1

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:timeago/timeago.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
98
Health:
Code health derived from static analysis. [more]
--
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
--
Overall:
Weighted score of the above. [more]
49
Learn more about scoring.

This package version is not analyzed, because it is more than two years old. Check the latest stable version for its analysis.

The package version is not analyzed, because it does not support Dart 2. Until this is resolved, the package will receive a health and maintenance score of 0.

Analysis issues and suggestions

Support Dart 2 in pubspec.yaml.

The SDK constraint in pubspec.yaml doesn't allow the Dart 2.0.0 release. For information about upgrading it to be Dart 2 compatible, please see https://dart.dev/dart-2#migration.