パッケージ、リポジトリ、アプリカテゴリを検索

パッケージ詳細v3.7.1

timeago

曖昧なタイムスタンプを作成するのに便利なライブラリです(例:「15分前」)。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
75.8万
いいね数
2020
Pub ポイント
160

パッケージをインストール

flutter pub add timeago

パッケージ概要

公開情報に基づく選定ガイドです。参考としてご利用ください。

timeago パッケージは、「15分前」や「2日前」など、人間が読みやすい曖昧なタイムスタンプを簡単に生成する方法を提供します。アプリケーションで相対的な時間を表示するのに最適であり、時間の理解をより直感的にすることでユーザー体験を向上させます。このライブラリは複数の言語をサポートしており、Android、iOS、Web、macOS、Windows、Linux を含むすべての主要プラットフォームと互換性があります。Flutterプロジェクトへの統合も、簡単なAPIを通じてスムーズに行えます。

用途

  • ソーシャルメディアアプリで投稿のタイムスタンプを表示する
  • チャットインターフェースで活動時間を表示する
  • 読み取り可能な時間ラベルによるユーザーエクスペリエンスの向上
  • ダッシュボードでイベントの期間を追跡する
  • 相対時間とのリアルタイム更新の同期
  • 現在の時刻差を使用してUIを動的に更新する

主な機能

  • 複数言語をサポート
  • Flutter との簡単な統合
  • クロスプラットフォーム互換性
  • カスタマイズ可能なフォーマットオプション
  • 自動時間の更新
  • 軽量で効率的

適している対象

  • ソーシャルメディアアプリケーション
  • リアルタイムメッセージングアプリ
  • ダッシュボードウィジェット
  • ユーザー活動トラッキングシステム
  • 人間が読み取れるタイムスタンプが必要なアプリ

注意事項

  • タイムゾーンの違いを手動で処理する必要があります
  • 英語以外の言語用にローカライゼーションの設定が必要になる場合があります
  • 絶対日付フォーマットをサポートしていません
  • 相対時間表示に限定
  • 正確なタイムスタンプの保存には適していません

元の README

関連するソースリポジトリの README 原文のスナップショットです。最新の内容はリポジトリをご覧ください。

timeago

timeago is a dart library that converts a date into a humanized text. Instead of showing a date 2020-12-12 18:30 with timeago you can display something like "now", "an hour ago", "~1y", etc

timeago pub package core library
timeago_flutter pub package flutter widgets

The easiest way to use this library via top-level function format(date):

import 'package:timeago/timeago.dart' as timeago;

main() {
    final fifteenAgo = DateTime.now().subtract(Duration(minutes: 15));

    print(timeago.format(fifteenAgo)); // 15 minutes ago
    print(timeago.format(fifteenAgo, locale: 'en_short')); // 15m
    print(timeago.format(fifteenAgo, locale: 'es')); // hace 15 minutos
}
IMPORTANT

timeago library ONLY includes en and es messages loaded by default.

To add more of the supported languages use timeago.setLocaleMessages(..). See locale messages.

Standard for language code

This library uses ISO 639-1 language code to identify the language. For more information see ISO 639-1.

Adding locales
timeago.setLocaleMessages('fr', timeago.FrMessages()); // Add french messages

print(timeago.format(fifteenAgo, locale: 'es')); // environ 15 minutes
Overriding locales or adding custom messages
// Override "en" locale messages with custom messages that are more precise and short
timeago.setLocaleMessages('en', MyCustomMessages());


// my_custom_messages.dart
class MyCustomMessages implements LookupMessages {
  @override String prefixAgo() => '';
  @override String prefixFromNow() => '';
  @override String suffixAgo() => '';
  @override String suffixFromNow() => '';
  @override String lessThanOneMinute(int seconds) => 'now';
  @override String aboutAMinute(int minutes) => '${minutes}m';
  @override String minutes(int minutes) => '${minutes}m';
  @override String aboutAnHour(int minutes) => '${minutes}m';
  @override String hours(int hours) => '${hours}h';
  @override String aDay(int hours) => '${hours}h';
  @override String days(int days) => '${days}d';
  @override String aboutAMonth(int days) => '${days}d';
  @override String months(int months) => '${months}mo';
  @override String aboutAYear(int year) => '${year}y';
  @override String years(int years) => '${years}y';
  @override String wordSeparator() => ' ';
}

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

  1. Provide a single format function that transforms a date to a humanized value
  2. Give the abstractions for users to add their own languages or overriding them as they please
  3. Provide languages contributed by the community so users can add them as they need we should not add all languages by default.
  4. Library should not depend on any dependency

timeago_flutter widgets

  • Timeago
  • TimerRefresh
  • TimerRefreshWidget

Local development

  1. Install Melos (https://pub.dev/packages/melos):

dart pub global activate melos

  1. Bootstrap dependencies:

melos bootstrap

  1. Open desired package in VSCode or Webstorm

Live Demo

Here

カテゴリー

依存関係

依存関係一覧 1 件

  • intl>=0.18.0 <0.21.0

ソースリポジトリ

このパッケージを使用しているプロジェクト

ランキング