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 #

  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


import 'package:time/time.dart';

void main() {
  // Integer Extensions

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

  // Duration Extensions

Use this package as a library

1. Depend on it

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

  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';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
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


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.


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