simple_moment 0.1.1

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 41

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.

Changelog

0.1.1

  • added missing export for IdentifierPosition

0.1.0

  • added locale functionality (#2)

0.0.3

  • fixed bug for diff under one second (#1)

0.0.2

  • fixed a few bugs
  • better rounding

0.0.1

  • Initial version

example/simple_moment_example.dart

// Copyright (c) 2016, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

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

Use this package as a library

1. Depend on it

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


dependencies:
  simple_moment: ^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:simple_moment/simple_moment.dart';
  
Version Uploaded Documentation Archive
0.1.1 Jun 22, 2018 Go to the documentation of simple_moment 0.1.1 Download simple_moment 0.1.1 archive
0.1.0 Jun 22, 2018 Go to the documentation of simple_moment 0.1.0 Download simple_moment 0.1.0 archive
0.0.3 May 14, 2018 Go to the documentation of simple_moment 0.0.3 Download simple_moment 0.0.3 archive
0.0.2 Dec 31, 2016 Go to the documentation of simple_moment 0.0.2 Download simple_moment 0.0.2 archive
0.0.1 Dec 31, 2016 Go to the documentation of simple_moment 0.0.1 Download simple_moment 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
82
Health:
Code health derived from static analysis. [more]
0
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
0
Overall:
Weighted score of the above. [more]
41
Learn more about scoring.

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://www.dartlang.org/dart-2#migration.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0