protontime 2.0.0 copy "protontime: ^2.0.0" to clipboard
protontime: ^2.0.0 copied to clipboard

A library useful for creating fuzzy timestamps. (e.g. "2 min ago")

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 managing timestamps.

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 format(date):

Quick Usage #

DateTime

import 'package:protontime/protontime.dart';

main() {
    Duration fiveMin = Duration(days: 5); // 120:00:00.000000
    DateTime fiveMinAdd = DateTime.now().add(fiveMin); // 2024-03-02 03:00:05.270034
    DateTime fiveMinSub = DateTime.now().subtract(fiveMin); // 2024-02-21 03:00:05.277179

    final resultPast = Protontime.format(fiveMinSub); // 5 days ago
    final resultFuture = Protontime.format(fiveMinAdd); // 5 days from now

    print("Past Time: $resultPast"); // 5 days ago
    print('Future Time: $resultFuture'); // 5 days from now
}

Timestamp

import 'package:protontime/protontime.dart';

main() {
    DateTime timestamp = DateTime.parse("2024-01-01T00:00:00.000000Z");
    final resultTimestamp = Protontime.format(timestamp); // 5 days ago

    print("Timestamp Time: $resultTimestamp"); // 5 days ago
}

Basic Usage (Short Messages) #

import 'package:protontime/protontime.dart';

main() {
    Duration fiveMin = Duration(days: 5); // 120:00:00.000000
    DateTime fiveMinAdd = DateTime.now().add(fiveMin); // 2024-03-02 03:00:05.270034
    DateTime fiveMinSub = DateTime.now().subtract(fiveMin); // 2024-02-21 03:00:05.277179

    final resultPastShort = Protontime.format(
      fiveMinSub,
      short: true,
    ); // 5d

    final resultFutureShort = Protontime.format(
      fiveMinAdd,
      short: true,
    ); // 5d

    print("Past Short Time: $resultPast"); // 5d
    print('Future Short Time: $resultFuture'); // 5d
}

Language #

The simplest method to format timestamps using local language is with protontime.

import 'package:protontime/protontime.dart';

main() {
    Duration fiveMin = Duration(days: 5); // 120:00:00.000000
    DateTime fiveMinAdd = DateTime.now().add(fiveMin); // 2024-03-02 03:00:05.270034
    DateTime fiveMinSub = DateTime.now().subtract(fiveMin); // 2024-02-21 03:00:05.277179

    final resultEsp = Protontime.format(
      fiveMinSub,
      language: 'es',
    ); //  hace 5 días

    final resultEspShort = Protontime.format(
      fiveMinAdd,
      language: 'es',
      short: true,
    ); //  5 días

    print("Local Lanugage: $resultEsp"); //  hace 5 días
    print('Local Lanugage Short: $resultEspShort'); //  5 días
}

Supported Language #

Supported languages include Amharic, Arabic, Azerbaijani, and many more.

Flag Language Language Code
Flag Amharic am
Flag Arabic ar
Flag Azerbaijani az
Flag Belarusian be
Flag Bosnian bs
Flag Catalan ca
Flag Czech cs
Flag Danish da
Flag German de
Flag Dhivehi dv
Flag English en
Flag Spanish es
Flag Estonian et
Flag Persian fa
Flag Finnish fi
Flag French fr
Flag Greek gr
Flag Hebrew he
Flag Hindi hi
Flag Hungarian hu
Flag Indonesian id
Flag Italian it
Flag Japanese ja
Flag Khmer km
Flag Korean ko
Flag Kurdish ku
Flag Latvian lv
Flag Mongolian mn
Flag Malay ms_my
Flag Norwegian Bokmål nb_no
Flag Dutch nl
Flag Norwegian Nynorsk nn_no
Flag Polish pl
Flag Portuguese (Brazil) pt_br
Flag Romanian ro
Flag Russian ru
Flag Kinyarwanda rw
Flag Serbian sr
Flag Swedish sv
Flag Tamil ta
Flag Thai th
Flag Turkmen tk
Flag Turkish tr
Flag Ukrainian uk
Flag Urdu ur
Flag Vietnamese vi
Flag Chinese (Simplified) zh_ch
Flag Chinese (Traditional) zh

Scope #

While there have been numerous requests for additional complex features, I aim to maintain this library's simplicity to minimize the need for ongoing maintenance.

The focus of this library should be

  1. Offering a singular format function that converts a date into a human-readable format.
  2. Allowing users to incorporate their own languages or override existing ones as desired through customizable abstractions.
  3. Offer languages contributed by the community for users to incorporate as needed, avoiding the inclusion of all languages by default.
  4. The library should be dependency-free.
2
likes
140
pub points
20%
popularity

Publisher

verified publishernben.com.np

A library useful for creating fuzzy timestamps. (e.g. "2 min ago")

Homepage

Topics

#date #time #timestamp

Documentation

API reference

License

MIT (LICENSE)

More

Packages that depend on protontime