Skip to content
Type-safe DateTime and Duration calculations, powered by extensions.
Dart
Branch: master
Clone or download
Latest commit 0e99283 Nov 19, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example Introduce support for other variants of num Oct 29, 2019
lib
test Fix breaking change with deprecation warning Nov 19, 2019
.gitignore v1.1.1 Nov 19, 2019
.travis.yml Introduce travis CI Oct 14, 2019
CHANGELOG.md v1.1.1 Nov 19, 2019
LICENSE Initial commit Oct 12, 2019
README.md v1.1.1 Nov 19, 2019
analysis_options.yaml Code generation Oct 12, 2019
pubspec.yaml v1.1.1 Nov 19, 2019

README.md

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.1.1"

⚡ Import

import 'package:time/time.dart';

🎮 Usage

final Duration tenMinutes = 10.minutes;
final Duration oneHourThirtyMinutes = 1.5.hours;
final DateTime afterTenMinutes = DateTime.now() + 10.minutes;
final Duration tenMinutesAndSome = 10.minutes + 15.seconds;
final int tenMinutesInSeconds = 10.minutes.inSeconds;
final DateTime tenMinutesFromNow = 10.minutes.fromNow;

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.fromNow;
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

You can’t perform that action at this time.