time 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • new30

⏰ Time #

Build Status - Travis codecov pub package

With shiny extensions, if you have ever written something like this, then look no further:

final DateTime fourHoursFromNow = DateTime.now() + Duration(hours: 4);

🎖 Installation #

dependencies:
  time: "^1.0.0"

⚡ Import #

import 'package:time/time.dart';

🎮 Usage #

final Duration tenMinutes = 10.minutes;
final DateTime afterTenMinutes = DateTime.now() + 10.minutes;
final Duration tenMinutesAndSome = 10.minutes + 15.seconds;
final int tenMinutesInSeconds = 10.minutes.inSeconds;
final DateTime tenMinutesLater = 10.minutes.later;

You can perform all basic arithmetic operations on Duration as you always have been:

final Duration interval = 10.minutes + 15.seconds - 3.minutes + 2.hours;
final Duration doubled = interval * 2;

You can also use these operations on DateTime:

final DateTime oneHourAfter = DateTime() + 1.hours;

Duration is easily convertible as it always has been:

final int twoMinutesInSeconds = 2.minutes.inSeconds;

You can also convert Duration to DateTime, if needed:

final DateTime timeInFuture = 5.minutes.later;
final DateTime timeInPast = 5.minutes.ago;

🐛 Bugs/Requests #

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on Github and I'll look into it. Pull request are also welcome.

👏 Inspiration #

  • Swift library of the same name - Time.
  • Kotlin library of the same name - Time.

⭐ License #

MIT License

1.0.0 #

  • Named extensions to allow discoverability
  • Introduced quality control test cases

0.0.1+1 #

  • Unify extensions for int, Duration & DateTime

0.0.1 #

  • Initial version

example/time_example.dart

import 'package:time/time.dart';

void main() {
  // Integer Extensions
  print(1.weeks);
  print(7.days);
  print(22.hours);
  print(45.minutes);
  print(30.seconds);
  print(15.milliseconds);
  print(10.microseconds);
  print(5.nanoseconds);

  // DateTime Extensions
  print(DateTime.now() + 7.days);
  print(DateTime.now() - 7.days);

  // Duration Extensions
  print(7.days.inWeeks);
  print(7.days.later);
  print(7.days.ago);
}

Use this package as a library

1. Depend on it

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


dependencies:
  time: ^1.0.0

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

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

  • Dart: 2.5.1
  • pana: 0.12.21

Platforms

Detected platforms:

Error(s) prevent platform classification:

Make sure dartfmt successfully runs on your package's source files.

Analysis issues and suggestions

Make sure dartfmt successfully runs on your package's source files.

Running dartfmt -n . failed with the following output:

Exception: dartfmt on lib/ failed with exit code 65
Could not format because the source could not be parsed:

line 1, column 1 of lib/src/extensions.dart: This requires the 'extension-methods' experiment to be enabled.
  ╷
1 │ extension IntTimeExtension on int {
  │ ^^^^^^^^^
  ╵
line 1, column 31 of lib/src/extensions.dart: Functions must have an explicit list of parameters.
  ╷

Fix dependencies in pubspec.yaml.

Running pub upgrade failed with the following output:

ERR: The current Dart SDK version is 2.5.1.
 
 Because time requires SDK version >=2.6.0-dev <3.0.0, version solving failed.

Maintenance issues and suggestions

Fix platform conflicts. (-20 points)

Error(s) prevent platform classification:

Make sure dartfmt successfully runs on your package's source files.

Make sure dartdoc successfully runs on your package's source files. (-10 points)

Dependencies were not resolved.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev <3.0.0