# time 2.1.6

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




## Installing
```
export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add 'time:2.1.6'
```
Published: 2025-12-07T08:02:47.174095Z
Expected archive SHA-256: 46187cf30bffdab28c56be9a63861b36e4ab7347bf403297595d6a97e10c789f

Available in cache; verification: upstream_checksum
## Direct dependencies
- clock: >=1.1.1 <2.0.0

## Package README (untrusted upstream documentation)
# ⏰ Time


[![Build](https://github.com/jogboms/time.dart/actions/workflows/build.yml/badge.svg)](https://github.com/jogboms/time.dart/actions/workflows/build.yml) [![codecov](https://codecov.io/gh/jogboms/time.dart/branch/master/graph/badge.svg)](https://codecov.io/gh/jogboms/time.dart) [![pub package](https://img.shields.io/pub/v/time.svg)](https://pub.dartlang.org/packages/time)

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

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

## 🎖 Installation
```yaml
dependencies:
  time: "^2.1.6"
```

### ⚡ Import

```dart
import 'package:time/time.dart';
```

## 🎮 Usage

```dart
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:

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

You can also use these operations on `DateTime`:

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

`Duration` is easily convertible as it always has been:

```dart
final int twoMinutesInSeconds = 2.minutes.inSeconds;
```

You can also convert `Duration` to `DateTime`, if needed:

```dart
final DateTime timeInFuture = 5.minutes.fromNow;
final DateTime timeInPast = 5.minutes.ago;
```

Iterate through a `DateTime` range:

```dart
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);
```

Granular comparison between `DateTime` fields:

```dart
final DateTime specificDate = DateTime(2021, 01, 01);
final DateTime otherDate = DateTime(2021, 02, 01);

print(specificDate.isAtSameYearAs(otherDate)); // true
print(specificDate.isAtSameMonthAs(otherDate)); // false
print(specificDate.isAtSameDayAs(otherDate)); // false
```

You can also delay code execution:

```dart
void doSomething() async {
  await 5.seconds.delay;
  // Do the other things
}
```

You can also use the popular `copyWith`:

```dart
final initial = DateTime(2019, 2, 4, 24, 50, 45, 1, 1);
final expected = initial.copyWith(
  year: 2021,
  month: 10,
  day: 28,
  hour: 12,
  minute: 45,
  second: 10,
  millisecond: 0,
  microsecond: 12,
);
```

Visit the [API Reference](https://pub.dev/documentation/time/latest/time/time-library.html) to find out all that is available.

## 🐛 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](https://github.com/dreymonde/Time).
- Kotlin library of the same name - [Time](https://github.com/kizitonwose/Time).

## ⭐ License

MIT License

## Changelog
## 2.1.6

- Include `milliseconds` and `microseconds` in `timeOfDay` extension to `DateTime`

## 2.1.5

- Introduce `endOfDay` extension to `DateTime`

## 2.1.4

- Introduce `shift` extension to `DateTime`

## 2.1.3

- Introduce `isWeekend` extension to `DateTime`
- Introduce `isWorkday` extension to `DateTime`

## 2.1.2

- Fix `min` and `max` assertion with `clamp` extension

## 2.1.1

- Introduce `firstDayOfWeek` extension to `DateTime`
- Introduce `lastDayOfWeek` extension to `DateTime`
- Introduce `firstDayOfMonth` extension to `DateTime`
- Introduce `lastDayOfMonth` extension to `DateTime`
- Introduce `firstDayOfYear` extension to `DateTime`
- Introduce `lastDayOfYear` extension to `DateTime`
- Introduce `clamp` extension to `DateTime`
- Introduce `clamp` extension to `Duration`

## 2.1.0

- Introduce `package:clock` dependency for more predictable testing

## 2.0.1

- Implement utc support for `copyWith` operation

## 2.0.0

- Migrate to null-safety

## 1.5.0-nullsafety.1

- Introduce `isAtSameYearAs` extension to `DateTime`
- Introduce `isAtSameMonthAs` extension to `DateTime`
- Introduce `isAtSameDayAs` extension to `DateTime`
- Introduce `isAtSameHourAs` extension to `DateTime`
- Introduce `isAtSameMinuteAs` extension to `DateTime`
- Introduce `isAtSameMillisecondAs` extension to `DateTime`
- Introduce `isAtSameMicrosecondAs` extension to `DateTime`
- Introduce `isLeapYear` extension to `DateTime`
- Introduce `daysInMonth` extension to `DateTime`

```dart
final DateTime specificDate = DateTime(2021, 01, 01);
final DateTime otherDate = DateTime(2021, 02, 01);

print(specificDate.isAtSameYearAs(otherDate)); // true
print(specificDate.isAtSameMonthAs(otherDate)); // false
print(specificDate.isAtSameDayAs(otherDate)); // false
```

## 1.4.1

- Introduce `isAtSameYearAs` extension to `DateTime`
- Introduce `isAtSameMonthAs` extension to `DateTime`
- Introduce `isAtSameDayAs` extension to `DateTime`
- Introduce `isAtSameHourAs` extension to `DateTime`
- Introduce `isAtSameMinuteAs` extension to `DateTime`
- Introduce `isAtSameMillisecondAs` extension to `DateTime`
- Introduce `isAtSameMicrosecondAs` extension to `DateTime`
- Introduce `isLeapYear` extension to `DateTime`
- Introduce `daysInMonth` extension to `DateTime`

## 1.5.0-nullsafety.0
- Migrated to null-safe dart

## 1.4.0

- Introduce `isToday` extension to `Duration`
- Introduce `isTomorrow` extension to `DateTime`
- Introduce `wasYesterday` extension to `DateTime`

## 1.3.0

- Introduce `delay` extension to `Duration`
- Introduce `copyWith` extension to `DateTime`

## 1.2.0

- Iterate through a `DateTime` range:

```dart
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







 
