Skip to content

Repository files navigation

dart_date

Dart Extensions for DateTime

dart_date provides the most comprehensive, yet simple and consistent toolset for manipulating Dart dates.

Inspired by date-fns

Usage

  • Use instance.method() for added methods.
  • Use instance.property for added getter properties.
  • Use Date.method() for added static methods.
  • Use Date.property for added static getter properties.
DE (String): Heute ist 18-Juni-2020
DE (Date): 2020-06-18 00:00:00.000
ES (Timeago): hace 3 meses
EN (Format): June 18 2020, 8:33:52 AM
.UTC: 2006-06-06 11:06:06.006006Z
Closest to now (2020-06-18 08:33:52.683698): 2020-06-16 08:33:52.610450 (2 days ago)
true
Human String: Thu Nov 20 2014 16:51:30
Yesterday: 2020-06-17 08:33:52.700225
Tomorrow: 2020-06-19 08:33:52.700579
const pattern ='\'Heute ist\' dd-MMMM-yyyy';
final n =DateTime.now();
final de_String =DateTime.now().format(pattern, 'de_DE');
final de_Date =Date.parse(de_String, pattern: pattern, locale:'de_DE');
print(
'DE (String): $de_String',
);
print(
'DE (Date): $de_Date',
);
final es_Timeago =DateTime.now().subDays(100).timeago(locale:'es');
print("ES (Timeago): $es_Timeago");
final en_Format =DateTime.now().format('MMMM dd y, h:mm:ss a');
print("EN (Format): $en_Format");
final utc =DateTime(2006, 6, 6, 6, 6, 6, 6, 6).UTC;
print(".UTC: $utc");
var now =DateTime.now();
var closest = now.closestTo(
[
n.nextWeek,
n.previousDay.previousDay,
n.previousWeek.nextDay,
n.nextMonth,
n.nextYear,
],
);
print('Closest to now ($now): $closest (${closest.timeago()})');
print(Date.today isDateTime);
print("Human String: "+DateTime.parse('2014-11-20T16:51:30.000Z').toHumanString());
print("Yesterday: "+ (Date.today -Duration(days:1)).toString());
print("Tomorrow: "+ (Date.today +Duration(days:1)).toString());

LICENSE

MIT

API

Check full docs

Date extension on DateTime

Properties

clone → DateTime
endOfDay → DateTime
endOfHour → DateTime
endOfISOWeek → DateTime
endOfMinute → DateTime
endOfMonth → DateTime
endOfSecond → DateTime
endOfWeek → DateTime
endOfYear → DateTime
getDate → int
getDay → int
getDayOfYear → int
getDaysInMonth → int
getDaysInYear → int
getHours → int
getMicroseconds → int
getMicrosecondsSinceEpoch → int
getMilliseconds → int
getMillisecondsSinceEpoch → int
getMinutes → int
getMonth → int
getSeconds → int
getTime → int
getTimeZoneName → String
getTimeZoneOffset → Duration
getWeekday → int
getYear → int
getWeekYear → int
getWeek → int
getISOWeek → int
getISOWeeksInYear → int
isFirstDayOfMonth → bool
isFriday → bool
isFuture → bool
isLastDayOfMonth → bool
isLeapYear → bool
isMonday → bool
isPast → bool
isSaturday → bool
isSunday → bool
isThisHour → bool
isThisMinute → bool
isThisMonth → bool
isThisSecond → bool
isThisYear → bool
isThursday → bool
isToday → bool
isTomorrow → bool
isTuesday → bool
isUTC → bool
isWednesday → bool
isWeekend → bool
isYesterday → bool
local → DateTime
nextDay → DateTime
nextMonth → DateTime
nextWeek → DateTime
nextYear → DateTime
previousDay → DateTime
previousMonth → DateTime
previousWeek → DateTime
previousYear → DateTime
secondsSinceEpoch → int
startOfDay → DateTime
startOfHour → DateTime
startOfISOWeek → DateTime
startOfMinute → DateTime
startOfMonth → DateTime
startOfSecond → DateTime
startOfWeek → DateTime
startOfYear → DateTime
startOfWeekYear → DateTime
startOfISOWeekYear → DateTime
timestamp → int
toLocalTime → DateTime
toUTC → DateTime
utc → DateTime

Methods

addDays(int amount) → DateTimeaddHours(int amount) → DateTimeaddMicroseconds(int amount) → DateTimeaddMilliseconds(int amount) → DateTimeaddMinutes(int amount) → DateTimeaddMonths(int amount) → DateTimeaddQuarters(int amount) → DateTimeaddSeconds(int amount) → DateTimeaddWeeks(int amount) → DateTimeaddYears(int amount) → DateTimeclosestIndexTo(Iterable<DateTime> datesArray) → intclosestTo(Iterable<DateTime> datesArray) → DateTimecompare(DateTime other) → intdiff(DateTime other) → DurationdifferenceInDays(DateTime other) → intdifferenceInHours(DateTime other) → intdifferenceInMicroseconds(DateTime other) → intdifferenceInMilliseconds(DateTime other) → intdifferenceInMinutes(DateTime other) → intdifferenceInSeconds(DateTime other) → inteachDay(DateTime date) → Iterable<DateTime>
equals(DateTime other) → boolformat(String pattern, [String locale ='en_US']) → StringisEqual(dynamic other) → boolisSameDay(DateTime other) → boolisSameHour(DateTime other) → boolisSameMinute(DateTime other) → boolisSameMonth(DateTime other) → boolisSameOrAfter(DateTime other) → boolisSameOrBefore(DateTime other) → boolisSameSecond(DateTime other) → boolisSameYear(DateTime other) → boolisWithinInterval(Interval interval) → boolisWithinRange(DateTime startDate, DateTime endDate) → boolsetDay(int day, [int hour, int minute, int second, int millisecond, int microsecond]) → DateTimesetWeekDay(int weekday, [int weekStartsOn]) → DateTimesetHour(int hour, [int minute, int second, int millisecond, int microsecond]) → DateTimesetMicrosecond(int microsecond) → DateTimesetMillisecond(int millisecond, [int microsecond]) → DateTimesetMinute(int minute, [int second, int millisecond, int microsecond]) → DateTimesetMonth(int month, [int day, int hour, int minute, int second, int millisecond, int microsecond]) → DateTimesetSecond(int second, [int millisecond, int microsecond]) → DateTimesetYear(int year, [int month, int day, int hour, int minute, int second, int millisecond, int microsecond]) → DateTimesub(Duration duration) → DateTimesubDays(int amount) → DateTimesubHours(int amount) → DateTimesubMicroseconds(dynamic amount) → DateTimesubMilliseconds(dynamic amount) → DateTimesubMinutes(dynamic amount) → DateTimesubMonths(dynamic amount) → DateTimesubSeconds(dynamic amount) → DateTimesubtract(Duration duration) → DateTimesubYears(dynamic amount) → DateTimetimeago({String locale, DateTime clock, bool allowFromNow}) → StringtoHumanString() → String

Operators

operator<(DateTime other) → booloperator<=(DateTime other) → booloperator>(DateTime other) → booloperator>=(DateTime other) → booloperator-(Duration other) → DateTimeoperator+(Duration other) → DateTime

Static Properties

endOfToday → DateTime
endOfTomorrow → DateTime
endOfYesterday → DateTime
startOfToday → DateTime
today → DateTime
tomorrow → DateTime
yesterday → DateTime

Static Methods

areRangesOverlapping(DateTime initialRangeStartDate, DateTime initialRangeEndDate, DateTime comparedRangeStartDate, DateTime comparedRangeEndDate) → boolcompareAsc(DateTime dateLeft, DateTime dateRight) → intcompareDesc(DateTime dateLeft, DateTime dateRight) → intfromSecondsSinceEpoch(int secondsSinceEpoch, {bool isUtc:false}) → DateTimeisDate(dynamic argument) → boolmax(DateTime left, DateTime right) → DateTimemin(DateTime left, DateTime right) → DateTimeparse(String dateString, {String pattern, String locale:'en_US', bool isUTC:false}) → DateTimeunix(int seconds) → DateTime

Interval class

// ConstructorsInterval(DateTime start, DateTime end)
// Properties
duration → Duration
end → DateTime
hashCode → int
runtimeType → Type
start → DateTime// Methodscontains(Interval interval) → boolcross(Interval other) → booldifference(Interval other) → Intervalequals(Interval other) → boolincludes(DateTime date) → boolintersection(Interval other) → IntervalsymetricDiffetence(Interval other) → List<Interval>
toString() → Stringunion(Interval other) → Interval// Operatorsoperator<(Interval other) → booloperator<=(Interval other) → booloperator==(dynamic other) → booloperator>(Interval other) → booloperator>=(Interval other) → bool

Duration Class

// Operatorsoperator-(Duration other) → Durationoperator+(Duration other) → Durationoperator*(num other) → Durationoperator/(num other) → Duration

About

Dart Date Manipulation Library with the aim of being the default way of doing operations with dates

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages