isBetween method

bool isBetween(
  1. DateTime from,
  2. DateTime to
)

Returns the bool wheather the given date are inside iterval or not.

Example:

DateTime(2000, 1, 2).isBetween(DateTime(2000, 1, 1), DateTime(2000, 1, 31)); // true
DateTime(2000, 1, 1).isBetween(DateTime(2000, 1, 1), DateTime(2000, 1, 1)); // true

Implementation

bool isBetween(DateTime from, DateTime to) {
  return (isAfter(from) && isBefore(to)) || this == from || this == to;
}