millisecs library
Exposes functions and extensions to convert between milliseconds and time formats and vice versa.
This is Dart & Flutter adaptation of Vercel's ms npm package.
Extensions
Functions
-
format(
num millisecs, {bool long = false}) → String -
Formats the provided
millisecs
into a String. Returns longer unit names iflong
istrue
.long
isfalse
by default. Throws an ArgumentError if the providedmillisecs
is not finite. -
ms(
dynamic value, {bool long = false}) → dynamic -
Parses or formats
value
. Ifvalue
is aString
, parses and returns milliseconds. Ifvalue
isnum
, formats and returns aString
.long
is used during formatting to use long unit names. Throws an ArgumentError if the providedvalue
is not aString
ornum
, or if parsing or formatting wasn't successful. -
parse(
String str) → num -
Parses the given
str
and return milliseconds. Throws ArgumentError ifstr
is empty or doesn't match the expected format. -
tryFormat(
num millisecs, {bool long = false}) → String? -
Same as format but returns
null
instead of throwing errors. -
tryMS(
dynamic value, {bool long = false}) → dynamic -
Same as ms but returns
null
instead of throwing errors. -
tryParse(
String str) → num? -
Same as parse but returns
null
instead of throwing errors.