搜索插件、代码仓与 APP 分类

GitHub 代码仓desktop-dart/duration

持续时间

用于简化 Duration 操作的工具。

持续时间 项目封面
星标
53
复刻
55
最近推送(UTC)
2024年8月21日
项目状态
未归档

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

duration pub package

Utilities to make working with 'Duration's easier.

Format duration

Use Duration.pretty() method or prettyDuration function to format a duration.

main() {
  final dur = Duration(
    days: 5,
    hours: 23,
    minutes: 59,
    seconds: 59,
    milliseconds: 999,
    microseconds: 999,
  );

  // => 5d, 23h, 59m, 59s
  print(dur.pretty());

  // => 3 seconds
  print((aMillisecond * 3000).pretty());

  // => 2 seconds 250 milliseconds
  print((aMillisecond * 2250).pretty);

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

With desired locale

Use locale parameter to format with desired locale.

main() {
  // => 5 días 9 horas
  final dur = aDay * 5 + anHour * 9;
  print(
      dur.pretty(
        abbreviated: false,
        locale: DurationLocale.fromLanguageCode('ru'),
      ));
}

Abbreviate units

Use abbreviated parameter to use abbreviated units.

main() {
  final dur = Duration(
    days: 5,
    hours: 23,
    minutes: 59,
    seconds: 59,
    milliseconds: 999,
    microseconds: 999,
  );

  // => 5d, 23h, 59m, 59s, 999ms, 999us
  print(dur.pretty(abbreviated: true, tersity: DurationTersity.all));
}

Spacer

Use spacer to add a string between amount and unit.

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

Delimiter

Use delimiter to separate each individual part with a string.

main() {
  // => 5 days, 9 hours and 10 minute
  print((aDay * 5 + anHour * 9 + aMinute * 10).pretty(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
  print(
      (aDay * 5 + anHour * 9 + aMinute * 10).pretty(
        delimiter: ', ',
        conjugation: ' and ',
      ));
}

Parse duration

Parse duration

main() {
  final Duration dur = parseDuration('245:09:08.007006');
  print(dur);
}

Parse time

main() {
  final Duration dur = parseTime('245:09:08.007006');
  print(dur);
}
desktop-dart GitHub avatar
GitHub 作者

desktop-dart ↗

语言Dart

分类

此仓库发布的插件

使用的依赖

依赖清单 2 项

  • test开发依赖^1.16.7
  • lints开发依赖^2.1.1

如何选择适合项目的代码仓?

先按使用场景筛选,再比较项目活跃情况,最后到原始仓库核对使用要求。

  1. 通过仓库名、作者或描述搜索,再按技术分类缩小范围。
  2. 结合星标、复刻与最近推送比较项目;星标反映社区关注,不代表质量保证。
  3. 使用前在 GitHub 核对 README、许可证与 Issues。

来源与维护

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗