timeago 0.1.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
    print(time.timeUntil(current - (15 * 60 * 1000))); // 15 minutes from now
    
    //change locale to spanish
    await time.changeLocale("es");
    
    print(time.timeAgo(current - (15 * 60 * 1000))); // hace 15 minutos
    print(time.timeUntil(current - (15 * 60 * 1000))); // dentro de 15 minutos
}

Live Demo #

Here

To do #

  • Add more locales

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Changelog #

0.1.1 #

  • Add fr and ja locales

0.1.0 #

  • Update messages to be more concise

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(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)));
}

Use this package as a library

1. Depend on it

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


dependencies:
  timeago: ^0.1.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.