• Stars
    star
    491
  • Rank 86,646 (Top 2 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

⏰ Time

Build 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: "^2.1.3"

⚡ 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);

Granular comparison between DateTime fields:

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:

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

You can also use the popular copyWith:

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 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.
  • Kotlin library of the same name - Time.

⭐ License

MIT License

More Repositories

1

flutter_spinkit

✨ A collection of loading indicators animated with flutter. Heavily Inspired by http://tobiasahlin.com/spinkit.
Dart
2,921
star
2

flutter_offline

✈️ A tidy utility to handle offline/online connectivity like a Boss
Dart
912
star
3

tailor_made

✄ Managing a Fashion designer's daily routine.
Dart
323
star
4

flutter_ravepay

Flutter integration for Flutterwave's Rave payment platform
Dart
59
star
5

iirc

🤔 IIRC (If I remember correctly): For keeping track of important recurring events.
Dart
48
star
6

ovavue

💸 A tidy budget overview planner.
Dart
41
star
7

rijksbook

🖼 A basic Flutter app built for educational purposes
Dart
38
star
8

pnyws

💰 Pnyws (PennyWise): An expense tracker.
Dart
34
star
9

flutter_scale_aware

🎗 Scale-based layouts with a bit more ease, powered by extensions.
Dart
25
star
10

ravepay.dart

💳 RavePay by Flutterwave Dart SDK. http://rave.flutterwave.com
Dart
21
star
11

registry.dart

🤿 A super-tiny service locator, \o/
Dart
19
star
12

nativescript-paystack

Nativescript integration for Paystack payment platform
TypeScript
15
star
13

EziNote

A simply beautiful notepad.
JavaScript
13
star
14

developer-story

StackOverflow is sunsetting the developer story feature. See https://meta.stackoverflow.com/questions/415293/sunsetting-jobs-developer-story
TypeScript
9
star
15

bunq.dart

🌈 Minimal Dart API layer for Bunq https://www.bunq.com
Dart
8
star
16

playground

Dart
8
star
17

nativescript-animate-sass

Use animate.css on your Nativescript + SASS apps
CSS
6
star
18

money.dart

💵 A currency formatting utility
Dart
6
star
19

nativescript-ng-gradient

An angular directive to add gradients to Nativescipt elements
TypeScript
6
star
20

quidpay.dart

Dart SDK for Quidpay's payment gateway
Dart
6
star
21

mfsao

⚙️ My flutter-specific analysis options
Dart
6
star
22

ngx-numeral

An Angular pipe module for interfacing the Awesome Numeraljs library.
TypeScript
4
star
23

awesome-flutter-showcase

A showcase of interesting demos written in flutter.
4
star
24

push

A minimal PHP-driven platform for rapid web application development
PHP
4
star
25

voute

A personal information vault.
Dart
3
star
26

ns-ngrx-debugger

A minimal nativescript debugger for ngrx-store & ngrx-effects
TypeScript
3
star
27

ns-ng-plugin-seed

A minimal Nativescript + Angular plugin seed
TypeScript
3
star
28

flutter_guild_demo

Dart
3
star
29

flutter_introductory_workshop

Dart
2
star
30

microservice-demos

A expedition into the world or micro services with https://github.com/zeit/micro
JavaScript
2
star
31

Event-Bus

A micro event emitting and management system for PHP
PHP
2
star
32

duck_duck_shop

Dart
2
star
33

ClinicRegistry

CSS
2
star
34

DentalRegistry

An Angular4 + NWjs patient registry software.
CSS
1
star
35

jogboms.github.io

Personal website
HTML
1
star