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 = Duration(seconds: 10);
var dateForComparison = DateTime.now().add(secondsToAdd);
var moment = Moment.now();
// should print "in a few seconds"print(moment.from(dateForComparison));
Moment rawDate = Moment.parse("2020-07-03");
// should print "2020-08-03 00:00:00.000print(rawDate.add(months: 1));
// should print "2019-07-03 00:00:00.000print(rawDate.subtract(years: 1));
//should print "03-07-2020 00:00"print(rawDate.format("dd-MM-yyyy HH:mm"));
}
Locales
Set the locale for all usages of Moment:
Moment.setLocaleGlobally(newLocaleDe());
Set the locale only for the current instance of Moment:
var moment = newMoment.now().locale(newLocaleDe());
Adding your own locale:
Just create a class that implements ILocaleData and assign that to your Moment instance or set it globally.
// create new Moment instance with german localevar moment = Moment.now().locale(LocaleDe(), useInFormat: true);
// initialize intlawaitinitializeDateFormatting(moment.usedLocale.localeString);
// format and print the current month in germanvar formattedString = moment.format("LLLL");
print(formattedString);
Features and bugs
Please file feature requests and bugs at the issue tracker.