protontime
protontime
is a dart library that converts a date into a humanized text. Instead of showing a date 2024-01-01 01:01
with protontime
you can display something like "now", "5 sec ago", "an hour ago", etc
A Flutter plugin for launching a URL.
Android | iOS | Linux | macOS | Web | Windows | |
---|---|---|---|---|---|---|
Support | SDK 16+ | 12.0+ | Any | 10.14+ | Any | Windows 10+ |
Installation
With Dart:
dart pub add protontime
With Flutter:
flutter pub add protontime
This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):
dependencies:
protontime: ^latest
Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.
Import it
Now in your Dart code, you can use:
import 'package:protontime/protontime.dart';
Usage
The easiest way to use this library via top-level function humanReadableTime(date)
:
import 'package:protontime/protontime.dart';
main() {
final fiveSecAgo = DateTime.now().subtract(Duration(seconds: 5)).toString();
print(fiveSecAgo); // 2024-01-01 00:00:00.000000
print(Protontime.format(fiveSecAgo); // 5 sec ago
}
Scope
While there are many request for adding more complex functionality I want keep this library as simple as possible to allow minimal maintenance.
The focus of this library should be
- Provide a single
format
function that transforms adate
to a humanized value - Give the abstractions for users to add their own languages or overriding them as they please
- Provide languages contributed by the community so users can add them as they need we should not add all languages by default.
- Library should not depend on any dependency
Libraries
- protontime
- Support for doing something awesome.