operator [] method

int operator [](
  1. PeriodUnits unit
)

Gets or sets the value of a single unit.

The type of this indexer is System.Int64 for uniformity, but any date unit (year, month, week, day) will only ever have a value in the range of System.Int32.

For the PeriodUnits.nanoseconds unit, the value is converted to Int64 when reading from the indexer, causing it to fail if the value is out of range (around 250 years). To access the values of very large numbers of nanoseconds, use the nanoseconds property directly.

  • unit: A single value within the PeriodUnits enumeration.

ArgumentError: unit is not a single unit, or a value is provided for a date unit which is outside the range of System.Int32.

Implementation

int operator [](PeriodUnits unit) {
  if (_indexGetterFunctionMap.containsKey(unit)) return _indexGetterFunctionMap[unit]!(this);
  throw ArgumentError('Indexer for PeriodBuilder only takes a single unit');
}