Skip to content

A simple implementation of the Moment.js features for relative time in Dart

License

Notifications You must be signed in to change notification settings

ramoncarreras/simple_moment

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

simple_moment Pub Build Status

A simple implementation of the Moment.js features for relative time in Dart.

Usage

A simple usage example:

import 'package:simple_moment/simple_moment.dart';

main() {
    var secondsToAdd = new Duration(seconds: 10);
    var dateForComparison = new DateTime.now().add(secondsToAdd);
    var moment = new Moment.now();

    // should print "in a few seconds"
    print(moment.from(dateForComparison));
}

Locales

Set the locale for all usages of Moment:

Moment.setLocaleGlobally(new LocaleDe());

Set the locale only for the current instance of Moment:

var moment = new Moment.now().locale(new LocaleDe());

Adding your own locale:

Just create a class that implements ILocaleData and assign that to your Moment instance or set it globally.

Overwriting existing locales:

class ShortLocaleEn extends LocaleEn {
  String get seconds => '%is';

  String get aMinute => '%im';
  String get minutes => '%im';

  String get anHour => '%ih';
  String get hours => '%ih';

  String get aDay => '%id';
  String get days => '%id';
}

Features and bugs

Please file feature requests and bugs at the issue tracker.

About

A simple implementation of the Moment.js features for relative time in Dart

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Dart 100.0%