hourglass 4.0.4-dev.1 copy "hourglass: ^4.0.4-dev.1" to clipboard
hourglass: ^4.0.4-dev.1 copied to clipboard

A fork of package:duration. Utilities to make working with 'Duration's easier. Formats duration in human readable form and also parses duration in human readable form to Dart's Duration.

example/hourglass_example.dart

import 'package:hourglass/hourglass.dart';
import 'package:hourglass/locale.dart';

void main() {
  // => 5 days 9 hours
  print((aDay * 5 + anHour * 9).pretty());

  // More examples

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

  // => 5 days 23 hours 59 minutes 59 seconds
  print(dur.pretty());

  // => 3.455 milliseconds
  print(prettyMilliseconds(aMicrosecond * 3455));

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

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

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

  // => 5 días 9 horas
  print((aDay * 5 + anHour * 9)
      .pretty(abbreviated: false, locale: spanishLocale));

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

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

  // => 5 days, 9 hours, 10 minute
  print((aDay * 5 + anHour * 9 + aMinute * 10).pretty(delimiter: ', '));

  // => 5 days, 9 hours and 10 minutes
  print((aDay * 5 + anHour * 9 + aMinute * 10)
      .pretty(delimiter: ', ', conjunction: ' and '));

  // => true
  print(parseDuration('1 week, 2 days, 7 hours', separator: ', ') == Duration(days: 9, hours: 7));
}
0
likes
0
points
15
downloads

Publisher

verified publisherlexedia.moe

Weekly Downloads

A fork of package:duration. Utilities to make working with 'Duration's easier. Formats duration in human readable form and also parses duration in human readable form to Dart's Duration.

Homepage
Repository (GitHub)
View/report issues

License

unknown (license)

More

Packages that depend on hourglass