ms_dart 1.0.4

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

ms_dart #

Build Status Join the community on Spectrum

Use this package to easily convert various time formats to milliseconds.

Install #

Add in pubspec.yaml

dependencies:
  ms_dart: 1.0.4

Examples #

MS.toMs('2 days')  // 172800000
MS.toMs('1d')      // 86400000
MS.toMs('10h')     // 36000000
MS.toMs('2.5 hrs') // 9000000
MS.toMs('2h')      // 7200000
MS.toMs('1m')      // 60000
MS.toMs('5s')      // 5000
MS.toMs('1y')      // 31557600000
MS.toMs('100')     // 100
MS.toMs('-3 days') // -259200000
MS.toMs('-1h')     // -3600000
MS.toMs('-200')    // -200

Convert from Milliseconds #

MS.fromMs(60000)             // "1m"
MS.fromMs(2 * 60000)         // "2m"
MS.fromMs(-3 * 60000)        // "-3m"
MS.fromMs(ms('10 hours'))    // "10h"

Time Format Written-Out #

MS.fromMs(60000, { long: true })                // "1 minute"
MS.fromMs(2 * 60000, { long: true })            // "2 minutes"
MS.fromMs(-3 * 60000, { long: true })           // "-3 minutes"
MS.fromMs(MS.toMs('10 hours'), { long: true })  // "10 hours"

Features #

  • Works both in dart vm, flutter, and in the browser
  • If a number is supplied to MS.fromMS(), a string with a unit is returned
  • If a string that contains the number is supplied to MS.toMs(), it returns it as a number (e.g.: it returns 100 for '100')
  • If you pass a string with a number and a valid unit to MS.toMs(), the number of equivalent milliseconds is returned
  • ms - Based on the ms javascript package.

Caught a Bug? #

  1. Fork this repository to your own GitHub account and then clone it to your local device
  2. You can run the tests using: dart test/ms_dart_test_dart

1.0.0 #

  • Initial version, created by Stagehand

1.0.1 #

  • minor edit

1.0.2 #

  • description in pubspec.yaml modified

1.0.3 #

  • fix length of description in pubspec.yaml

1.0.3-a #

  • fix of README.md - documentation

1.0.4 #

  • fix of version

example/ms_dart_example.dart

import 'package:ms_dart/ms_dart.dart';

void main() {
  print('MS.fromMs(3000): ${MS.fromMs(3000)}');
}

Use this package as a library

1. Depend on it

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


dependencies:
  ms_dart: ^1.0.4

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:ms_dart/ms_dart.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
28
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

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

  • Dart: 2.8.2
  • pana: 0.13.8-dev

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.5.0 <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.6.0