duration 1.0.0 copy "duration: ^1.0.0" to clipboard
duration: ^1.0.0 copied to clipboard

outdatedDart 1 only

Utilities to make working with 'Duration's easier.

duration #

Utilities to make working with 'Duration's easier.

Format duration #

Use printDuration to print a human readable durations. By default, printDuration will print the duration down to the second. It uses english locale by default.

main() {
    final dur = new Duration(
        days: 5,
        hours: 23,
        minutes: 59,
        seconds: 59,
        milliseconds: 999,
        microseconds: 999);
    // => 5d, 23h, 59m, 59s
    printDuration(dur);
  
  // => 3 seconds
  printDuration(aMillisecond * 3000);

  // => 2 seconds 250 milliseconds
  printDuration(aMillisecond * 2250);

  // => 1 day 3 hours 2 minutes
  printDuration(aMillisecond * 97320000);
}

With desired locale #

Use locale parameter to format with desired locale.

main() {
  // => 5 días 9 horas
  printDuration(aDay * 5 + anHour * 9,
      abbreviated: false, locale: spanishLocale);
}

Abbreviate units #

Use abbreviated parameter to use abbreviated units.

main() {
  final dur = new Duration(
      days: 5,
      hours: 23,
      minutes: 59,
      seconds: 59,
      milliseconds: 999,
      microseconds: 999);
  // => 5d, 23h, 59m, 59s, 999ms, 999us
  printDuration(dur, abbreviated: true, tersity: DurationTersity.all);
}

Spacer #

Use spacer to add a string between amount and unit.

main() {
  // => 5 whole days 9 whole hours
  printDuration(aDay * 5 + anHour * 9, spacer: ' whole ');
}

Delimiter #

Use delimiter to separate each individual part with a string.

main() {
  // => 5 days, 9 hours and 10 minute
  printDuration(aDay * 5 + anHour * 9 + aMinute * 10, delimiter: ', ');
}

Conjugation #

Use conjugation to add a string before the final unit. Use it in conjunction with delimiter to add ',' and 'and' to separate individual parts.

main() {
  // => 5 days, 9 hours and 10 minutes
  printDuration(aDay * 5 + anHour * 9 + aMinute * 10,
      delimiter: ', ', conjugation: ' and ');
}
143
likes
30
pub points
97%
popularity

Publisher

unverified uploader

Utilities to make working with 'Duration's easier.

Repository (GitHub)
View/report issues

License

BSD-3-Clause (LICENSE)

Dependencies

quiver_time

More

Packages that depend on duration