• Stars
    star
    538
  • Rank 82,538 (Top 2 %)
  • Language
    Dart
  • Created over 9 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

timeago

timeago is a dart library that converts a date into a humanized text. Instead of showing a date 2020-12-12 18:30 with timeago you can display something like "now", "an hour ago", "~1y", etc

timeago pub package core library
timeago_flutter pub package flutter widgets

The easiest way to use this library via top-level function format(date):

import 'package:timeago/timeago.dart' as timeago;

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

timeago library ONLY includes en and es messages loaded by default.

To add more of the supported languages use timeago.setLocaleMessages(..). See locale messages.

Standard for language code

This library uses ISO 639-1 language code to identify the language. For more information see ISO 639-1.

Adding locales

timeago.setLocaleMessages('fr', timeago.FrMessages()); // Add french messages

print(timeago.format(fifteenAgo, locale: 'es')); // environ 15 minutes

Overriding locales or adding custom messages

// Override "en" locale messages with custom messages that are more precise and short
timeago.setLocaleMessages('en', MyCustomMessages());


// my_custom_messages.dart
class MyCustomMessages implements LookupMessages {
  @override String prefixAgo() => '';
  @override String prefixFromNow() => '';
  @override String suffixAgo() => '';
  @override String suffixFromNow() => '';
  @override String lessThanOneMinute(int seconds) => 'now';
  @override String aboutAMinute(int minutes) => '${minutes}m';
  @override String minutes(int minutes) => '${minutes}m';
  @override String aboutAnHour(int minutes) => '${minutes}m';
  @override String hours(int hours) => '${hours}h';
  @override String aDay(int hours) => '${hours}h';
  @override String days(int days) => '${days}d';
  @override String aboutAMonth(int days) => '${days}d';
  @override String months(int months) => '${months}mo';
  @override String aboutAYear(int year) => '${year}y';
  @override String years(int years) => '${years}y';
  @override String wordSeparator() => ' ';
}

Scope

While there are many request for adding more complex functionality I want keep this library as simple as possible to allow minimal maintenance.

The focus of this library should be

  1. Provide a single format function that transforms a date to a humanized value
  2. Give the abstractions for users to add their own languages or overriding them as they please
  3. Provide languages contributed by the community so users can add them as they need we should not add all languages by default.
  4. Library should not depend on any dependency

timeago_flutter widgets

  • Timeago
  • TimerRefresh
  • TimerRefreshWidget

Local development

  1. Install Melos (https://pub.dev/packages/melos):

dart pub global activate melos

  1. Bootstrap dependencies:

melos bootstrap

  1. Open desired package in VSCode or Webstorm

Live Demo

Here

More Repositories

1

flutter_news

A Hacker News client made in Flutter
Dart
77
star
2

clippy

Access system clipboard in Dart (Server&Browser)
Dart
22
star
3

hanzo

Git hooks made easy from Dart code
Dart
14
star
4

ng2_hackernews

A HackerNews application made with Angular 2 Dart.
Dart
11
star
5

angular2_cheatsheet_dart

11
star
6

songwoof

Discover Music (Angular 2 application)
Dart
10
star
7

atom-angular2-snippets

Angular 2 snippets for Atom
9
star
8

ng2_dart_quickstart

An Angular 2 quick start project
HTML
7
star
9

apk_parser.dart

A pure dart library for parsing android apk data
Dart
5
star
10

flutter_fetch_widget

Make simple http requests with a Flutter widget
Dart
4
star
11

dart-ng-flow-type

FlowType port for Angular.dart
Dart
3
star
12

url_shortener_example

A simple url shortener using Redis and Dart
Dart
2
star
13

ng2_dart_hyperlapse_stream

Angular 2 Dart playground
Dart
2
star
14

lorem-dart

A simple library to generate lorem ipsum text
Dart
2
star
15

bricks

A 2048 clone in Dart
CSS
2
star
16

auth0_lock.dart

A Dart wrapper for Auth0 Lock
Dart
2
star
17

ddrive

Dart
1
star
18

ng2_dart_snapshot

Latest snapshot of angular 2 dart, just for testing
Dart
1
star
19

ng2_form_examples

Angular 2 for Dart Form Examples
Dart
1
star
20

gitwho

A simple Angular.dart application that uses github public API
Dart
1
star
21

context_blender.dart

A small library to blend HTML Canvas Contexts
Dart
1
star
22

ng2_dart_router_demo

A basic example of angular 2 router
Dart
1
star
23

chroma_dart

A wrapper for chromajs
Dart
1
star
24

swidget

Make Simple stateless widgets with state
Dart
1
star
25

changelog.dart

DEPRECATED: Use instead https://github.com/MikeMitterer/dart-changelog
Dart
1
star
26

design_library_example

Android Design Library Example
Java
1
star
27

plank

Dart
1
star
28

gradle-changelog-plugin

Conventional changelog plugin for gradle
Groovy
1
star
29

dropwizard-angular-example

Example of using AngularJS with Dropwizard
CSS
1
star
30

firebase_chat_example

CSS
1
star
31

notes

A notes app to show how to use the Android Design Support Library
Java
1
star