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

NumMS on num
Provides ms's features directly on numbers. Specifically, allows you to format the number into Strings.
StringMS on String
Provides ms's features directly on Strings. Specifically, allows you to parse Strings into milliseconds.

Functions

format(num millisecs, {bool long = false}) String
Formats the provided millisecs into a String. Returns longer unit names if long is true. long is false by default. Throws an ArgumentError if the provided millisecs is not finite.
ms(dynamic value, {bool long = false}) → dynamic
Parses or formats value. If value is a String, parses and returns milliseconds. If value is num, formats and returns a String. long is used during formatting to use long unit names. Throws an ArgumentError if the provided value is not a String or num, or if parsing or formatting wasn't successful.
parse(String str) num
Parses the given str and return milliseconds. Throws ArgumentError if str 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.