simple_moment 1.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 90

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 #

1.0.3 #

  • Add italian locale, add french locale ([#7])

1.0.2 #

  • added pt_BR locale (#3)

1.0.1 #

  • make pub analyzer happy

1.0.0 #

  • upgraded to Dart SDK 2.0

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: ^1.0.3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

with Flutter:


$ flutter pub get

Alternatively, your editor might support pub get or flutter 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';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
85
Health:
Code health derived from static analysis. [more]
92
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
90
Learn more about scoring.

We analyzed this package on Nov 7, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.6.0
  • pana: 0.12.21

Platforms

Detected platforms: Flutter, web, other

No platform restriction found in primary library package:simple_moment/simple_moment.dart.

Health issues and suggestions

Document public APIs. (-1 points)

134 out of 134 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/src/simple_moment_base.dart. (-6.78 points)

Analysis of lib/src/simple_moment_base.dart reported 14 hints, including:

line 22 col 18: Use = to separate a named parameter from its default value.

line 60 col 7: DO use curly braces for all flow control structures.

line 62 col 7: DO use curly braces for all flow control structures.

line 64 col 7: DO use curly braces for all flow control structures.

line 66 col 7: DO use curly braces for all flow control structures.

Format lib/src/locales/it.dart.

Run dartfmt to format lib/src/locales/it.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
Dev dependencies
test ^1.3.0