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

outdatedDart 1 only

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

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(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) {
  int currentTime = new DateTime.now().millisecondsSinceEpoch;
  addToOther(fuzzy.timeAgo(currentTime - (1 * 44 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (1 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (5 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (50 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (5 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (25 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (5 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (5 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (13 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeAgo(currentTime - (3 * 12 * 30 * 24 * 60 * 60 * 1000)));
  addToOther("-");
  addToOther(fuzzy.timeUntil(currentTime - (1 * 44 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (1 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (5 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (50 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (5 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (25 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (5 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (5 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (13 * 30 * 24 * 60 * 60 * 1000)));
  addToOther(fuzzy.timeUntil(currentTime - (3 * 12 * 30 * 24 * 60 * 60 * 1000)));
}
1824
likes
35
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

MIT (license)

Dependencies

intl

More

Packages that depend on timeago