LocalDate constructor

LocalDate(
  1. int year,
  2. int month,
  3. int day
)

Creates a new LocalDate instance for a specific year, month, and day.

Throws InvalidArgumentException if the date is not valid (e.g. April 31).

Example:

final d = LocalDate(2023, 2, 28);

Represents a calendar date without time or timezone.

This class provides date-only operations such as computing weekdays, adding or subtracting days/months/years, and converting from/to strings.

It ensures valid dates (e.g. February never has more than 29 days).

Example

final date = LocalDate(2024, 6, 27);
print(date); // "2024-06-27"

Implementation

LocalDate(this.year, this.month, this.day) {
  _validateDate(year, month, day);
}