DurationPrinter class

Prints Duration objects in custom ways.

For example, to print dates in the format YYYY-MM-DD call the constructor and configure the printer as such:

 final printer = DurationPrinter((builder) => builder
  ..part(TimeUnit.year, printer: FixedNumberPrinter<int>(padding: 4))
  ..literal(':')
  ..part(TimeUnit.month, printer: FixedNumberPrinter<int>(padding: 2))
  ..literal(':')
  ..part(TimeUnit.day, printer: FixedNumberPrinter<int>(padding: 2)));
print(printer(const Duration(days: 1234, seconds: 56789)));  // 0003-04-19
Inheritance

Constructors

DurationPrinter(Callback1<DurationPrinterBuilder> callback, {Map<TimeUnit, num> conversion = casualConversion})
Constructor to build a DurationPrinter.
factory

Properties

defaultToStringPrinter ObjectPrinter
Override to configure the empty ObjectPrinter.
no setterinherited
hashCode int
The hash code for this object.
no setterinherited
printers Iterable<Printer<Duration>>
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
toStringPrinter ObjectPrinter
Override and call super to add values to the ObjectPrinter.
no setterinherited

Methods

call(Duration object) String
Prints the object.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
print(Duration object) String
Returns the printed object.
inherited
printOn(Duration object, StringBuffer buffer) → void
Prints the object into buffer.
inherited
toString() String
Standard toString implementation. Do not override, instead implement toStringPrinter to customize.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

dart() DurationPrinter
Returns the standard Dart duration format.
iso8601() DurationPrinter
Returns an ISO-8601 extended full-precision format representation.