LocalDate constructor

LocalDate(
  1. int year,
  2. int month,
  3. int day, [
  4. CalendarSystem? calendar,
  5. Era? era,
])

Constructs an instance for the given year, month and day in the specified or ISO calendar.

  • year: The year. This is the 'absolute year', so a value of 0 means 1 BC, for example.
  • month: The month of year.
  • day: The day of month.
  • calendar: Calendar system in which to create the date, which defaults to the ISO calendar.
  • era: The era within which to create a date. Must be a valid era within the specified calendar.

Returns: The resulting date.

  • RangeError: The parameters do not form a valid date.

Implementation

factory LocalDate(int year, int month, int day, [CalendarSystem? calendar, Era? era])
{
  CalendarOrdinal ordinal;
  if (calendar == null) {
    if (era != null) year = CalendarSystem.iso.getAbsoluteYear(year, era);
    GregorianYearMonthDayCalculator.validateGregorianYearMonthDay(year, month, day);
    ordinal = CalendarOrdinal.iso;
  } else {
    if (era != null) year = calendar.getAbsoluteYear(year, era);
    ICalendarSystem.validateYearMonthDay(calendar, year, month, day);
    ordinal = ICalendarSystem.ordinal(calendar);
  }

  return LocalDate._trusted(YearMonthDayCalendar(year, month, day, ordinal));
}