date_checker 1.0.0+2
date_checker: ^1.0.0+2 copied to clipboard

Convenient extension methods on DateTime plus other helpful utility methods.

📅 Date Checker #

pub package Dart

Convenient extension methods on DateTime to check if a date is today, this week, last week and so on, plus some other helpful utility mehods.

Usage #

weekStart #

Returns the beginning of the week in which date is present

var moonLanding = DateTime.parse("1969-07-20 20:18:04Z");
moonLanding.weekday == DateTime.sunday  // true

// 1969-07-14 00:00:00.000
weekStart(date: moonLanding);   

// 1969-07-20 00:00:00.000
weekStart(date: moonLanding, isMondayStartOfWeek: false)   

weekEnd #

Returns the end of the week in which date is present

var moonLanding = DateTime.parse("1969-07-20 20:18:04Z");

// 1969-07-20 23:59:59.999999
weekEnd(date: moonLanding);

// 1969-07-26 23:59:59.999999
weekEnd(date: moonLanding, isMondayStartOfWeek: false)

DateTime(1969, 7, 26).weekday == DateTime.saturday //true

If date is not specified, DateTime.now() is considered i.e. the start/end of the current week will be returned.

If isMondayStartOfWeek is not specified, defaulting to true the start/end will follow ISO 8601 and the week will be of the form [Monday...Sunday] or setting it to false will return in the form of [Sunday...Saturday]

Extension on DateTime #

Extension MethodDescription
isTodayReturns true if date is today
isTomorrowReturns true if date is tomorrow
isYesterdayReturns true if date is yesterday
isLastWeekReturns true if date is from last week
isThisWeekReturns true if date is from current week
isNextWeekReturns true if date is from following week
isThisMonthReturns true if date is present in current month

By default, isLastWeek and isThisWeek will return the result based on [Monday...Sunday] format. If the Sunday is desired as the first day of the week, use the setter sundayAsStartOfWeekto acheive the result based on [Sunday...Saturday] week format.

A simple usage example:

import 'package:date_checker/date_checker.dart';

void main() {
  var date = DateTime.now();

  final isToday = date.isToday; //true
}

Features and bugs #

Please file feature requests and bugs at the issue tracker.

5
likes
130
pub points
16%
popularity

Publisher

calvingonsalves.com

Convenient extension methods on DateTime plus other helpful utility methods.

Repository (GitHub)
View/report issues

Documentation

API reference

License

BSD (LICENSE)

More

Packages that depend on date_checker