time 1.0.0 copy "time: ^1.0.0" to clipboard
time: ^1.0.0 copied to clipboard

outdated

Type-safe DateTime and Duration calculations, powered by extensions.

⏰ 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

345
likes
0
pub points
93%
popularity

Publisher

verified publisherogbomo.com

Type-safe DateTime and Duration calculations, powered by extensions.

Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on time