simple_moment 0.1.1

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

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

with Flutter:


$ flutter packages get

Alternatively, your editor might support pub get or flutter packages 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

Analysis

We analyzed this package on Jun 22, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0-dev.63.0
  • pana: 0.11.3

Scores

Popularity:
Describes how popular the package is relative to other packages. [more]
79 / 100
Health:
Code health derived from static analysis. [more]
95 / 100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100 / 100
Overall score:
Weighted score of the above. [more]
88
Learn more about scoring.

Platforms

Detected platforms: Flutter, web, other

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

Suggestions

  • Fix .analysis_options.

    We were unable to parse .analysis_options.

  • Package is pre-v1 release.

    While there is nothing inherently wrong with versions of 0.*.*, it usually means that the author is still experimenting with the general direction API.

  • Fix analysis and formatting issues.

    Analysis or formatting checks reported 6 hints.

    Run dartfmt to format lib/simple_moment.dart.

    Run dartfmt to format lib/src/identifier_position.dart.

    Similar analysis of the following files failed:

    • lib/src/localedata.dart (hint)
    • lib/src/locales/de.dart (hint)
    • lib/src/locales/en.dart (hint)
    • lib/src/simple_moment_base.dart (hint)
  • Use analysis_options.yaml.

    Rename old .analysis_options file to analysis_options.yaml.

  • Enable strong mode analysis.

    Strong mode helps you to detect bugs and potential issues earlier.Start your analysis_options.yaml file with the following:

    analyzer:
      strong-mode: true
    

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.0.0 <2.0.0
Dev dependencies
test >=0.12.0 <0.13.0