Period constructor

const Period({
  1. int years = 0,
  2. int months = 0,
  3. int days = 0,
  4. int hours = 0,
  5. int minutes = 0,
  6. int seconds = 0,
  7. int milliseconds = 0,
  8. int microseconds = 0,
})

Creates a Period from human-friendly units.

All parameters default to 0. You can combine them freely:

Period(years: 1, months: 6)       // ~1.5 years
Period(hours: 2, minutes: 30)     // 2.5 hours
Period(days: 7)                   // one week

Months are approximated as 30 days, and years as 365 days.

Implementation

const Period({
  int years = 0,
  int months = 0,
  int days = 0,
  int hours = 0,
  int minutes = 0,
  int seconds = 0,
  int milliseconds = 0,
  int microseconds = 0,
}) : this._microseconds(
       microseconds +
           microsecondsPerMillisecond * milliseconds +
           microsecondsPerSecond * seconds +
           microsecondsPerMinute * minutes +
           microsecondsPerHour * hours +
           microsecondsPerDay * days +
           microsecondsPerDay * 30 * months +
           microsecondsPerDay * 365 * years,
     );