All Projects → jogboms → Time.dart

jogboms / Time.dart

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

Programming Languages

dart
5743 projects
dartlang
94 projects

Projects that are alternatives of or similar to Time.dart

Dateutil
Useful extensions to the standard Python datetime features
Stars: ✭ 1,706 (+369.97%)
Mutual labels:  library, time, datetime
duration-humanizer
361000 becomes "6 minutes, 1 second"
Stars: ✭ 61 (-83.2%)
Mutual labels:  duration, time, datetime
hs-hourglass
efficient and simpler time API for haskell
Stars: ✭ 43 (-88.15%)
Mutual labels:  time, datetime
dt
Go's missing DateTime package
Stars: ✭ 34 (-90.63%)
Mutual labels:  time, datetime
rescript-date
📆 Date manipulation in ReScript.
Stars: ✭ 101 (-72.18%)
Mutual labels:  time, datetime
qrono
🕥 Just right date time library
Stars: ✭ 111 (-69.42%)
Mutual labels:  time, datetime
rutimeparser
Recognize date and time in russian text and return datetime.datetime.
Stars: ✭ 17 (-95.32%)
Mutual labels:  time, datetime
chronos
One library to rule the time
Stars: ✭ 17 (-95.32%)
Mutual labels:  time, datetime
date-extractor
Extract dates from text
Stars: ✭ 58 (-84.02%)
Mutual labels:  time, datetime
nepali-datetime
Python's core datetime inspired nepali datetime (BS date & NPT) package 🇳🇵
Stars: ✭ 36 (-90.08%)
Mutual labels:  time, datetime
vue-timeselector
🕒 Simply customizable powerful time picker for Vue.js
Stars: ✭ 41 (-88.71%)
Mutual labels:  time, datetime
dayjs
Extended fork of Day.js - 2KB immutable date library alternative to Moment.js
Stars: ✭ 36 (-90.08%)
Mutual labels:  time, datetime
datetime
A Go (golang) library for parsing most ISO8601 timestamps
Stars: ✭ 24 (-93.39%)
Mutual labels:  time, datetime
Swift-ISO8601-DurationParser
Swift ISO8601 Parser
Stars: ✭ 24 (-93.39%)
Mutual labels:  duration, time
open hours
Time calculations using business hours
Stars: ✭ 41 (-88.71%)
Mutual labels:  time, datetime
shamsi date
A Flutter and Dart package for using Jalali (Shamsi, Solar, Persian or Jalaali) calendar. You can convert, format and manipulate Jalali and Gregorian (Miladi) date and times.
Stars: ✭ 59 (-83.75%)
Mutual labels:  time, datetime
React Datetime Picker
A datetime picker for your React app.
Stars: ✭ 294 (-19.01%)
Mutual labels:  time, datetime
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (-66.39%)
Mutual labels:  time, datetime
lit-date
Light-weight, faster datetime formatter for modern browsers.
Stars: ✭ 33 (-90.91%)
Mutual labels:  time, datetime
moment-cache
⏱ Simple utility to cache moment.js results and speed up moment calls.
Stars: ✭ 29 (-92.01%)
Mutual labels:  time, datetime

⏰ 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.0.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);

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

🐛 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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].