# ⏰ Time #

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.2.0"
``````

### ⚡ 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;
``````

Iterate through a `DateTime` range:

``````final DateTime start = DateTime(2019, 12, 2);
final DateTime end = start + 1.weeks;
final DateTime tuesday = start.to(end).firstWhere((date) => date.weekday == DateTime.tuesday);
``````

## 🐛 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.

## 1.2.0 #

• Iterate through a `DateTime` range:
``````final DateTime start = DateTime(2019, 12, 2);
final DateTime end = start + 1.weeks;
final DateTime tuesday = start.to(end).firstWhere((date) => date.weekday == DateTime.tuesday);
``````

## 1.1.1 #

• Fix breaking change from v1.1.0 by introducing @deprecated flag

## 1.1.0 #

• Breaking Change: renamed `later` to `fromNow` to align with other ecosystems
• Introduced support for other variants of `num` i.e `double`

## 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() {
// Num Extensions
print(1.weeks);
print(1.5.weeks);
print(7.days);
print(7.5.days);
print(22.hours);
print(22.5.hours);
print(45.minutes);
print(45.5.minutes);
print(30.seconds);
print(30.5.seconds);
print(15.milliseconds);
print(15.5.milliseconds);
print(10.microseconds);
print(10.5.microseconds);
print(5.nanoseconds);
print(5.5.nanoseconds);

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

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

DateTime.now().to(1.weeks.fromNow, by: 1.days).forEach(print);
}
``````

## Use this package as a library

### 1. Depend on it

``````
dependencies:
time: ^1.2.0

``````

### 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:time/time.dart';
``````
 Popularity: Describes how popular the package is relative to other packages. [more] 91 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] 96

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

• Dart: 2.7.1
• pana: 0.13.6

#### Health suggestions

Format `lib/src/extensions.dart`.

Run `dartfmt` to format `lib/src/extensions.dart`.

#### Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.6.0-dev <3.0.0
Dev dependencies
pedantic ^1.8.0
test ^1.9.0
test_coverage