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

パッケージ詳細v1.1.1

simple_moment

相対時間用の Moment.js 機能の簡単な実装。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
483
いいね数
51
Pub ポイント
120

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

flutter pub add simple_moment

パッケージ概要

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

相対的な時間を表示するための、Moment.jsに似た基本機能を備えた軽量なFlutterパッケージです。『2分前』や『5時間後』といった時間差のフォーマットを、複数のプラットフォームで簡単に実現します。使いやすさを重視し、重い依存関係なしにタイムスタンプを人間が読みやすい相対的な文字列に変換するための明確なAPIを提供しています。ユーザーインターフェースで直感的な時間表現が必要なアプリに最適です。

用途

  • 投稿のタイムスタンプを表示する
  • メッセージの送信時刻を表示
  • ライブアクティビティインジケーターの更新
  • ユーザー通知の強化
  • イベントの締切を追跡する

主な機能

  • 簡単な相対時間フォーマット
  • クロスプラットフォーム対応
  • 最小の依存関係フットプリント
  • DateTime オブジェクトとの簡単な統合
  • 外部ライブラリは不要です

適している対象

  • リアルタイム更新対応のアプリ
  • ソーシャルメディアインターフェース
  • チャットアプリケーション
  • タスク管理ツール
  • 読み取り可能な時間差を必要とするアプリ

注意事項

  • 相対時間のみに制限
  • 日付の解析や操作なし
  • ローカライズをサポートしていません
  • 複雑な日付操作には適していません
  • タイムゾーンオフセットの手動処理が必要です

元の README

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

simple_moment Pub Build Status

A simple implementation of the Moment.js features for relative time in Dart.

Usage

A simple usage example:

import 'package:simple_moment/simple_moment.dart';

main() {
    var secondsToAdd = Duration(seconds: 10);
    var dateForComparison = DateTime.now().add(secondsToAdd);
    var moment = Moment.now();

    // should print "in a few seconds"
    print(moment.from(dateForComparison));
    
    Moment rawDate = Moment.parse("2020-07-03");
      // should print "2020-08-03 00:00:00.000
      print(rawDate.add(months: 1));
    
      // should print "2019-07-03 00:00:00.000
      print(rawDate.subtract(years: 1));
    
      //should print "03-07-2020 00:00"
      print(rawDate.format("dd-MM-yyyy HH:mm"));
}

Locales

Set the locale for all usages of Moment:
Moment.setLocaleGlobally(new LocaleDe());
Set the locale only for the current instance of Moment:
var moment = new Moment.now().locale(new LocaleDe());
Adding your own locale:

Just create a class that implements ILocaleData and assign that to your Moment instance or set it globally.

Overwriting existing locales:
class ShortLocaleEn extends LocaleEn {
  String get seconds => '%is';

  String get aMinute => '%im';
  String get minutes => '%im';

  String get anHour => '%ih';
  String get hours => '%ih';

  String get aDay => '%id';
  String get days => '%id';
}
Using intl to format dates
// create new Moment instance with german locale
var moment = Moment.now().locale(LocaleDe(), useInFormat: true);

// initialize intl
await initializeDateFormatting(moment.usedLocale.localeString);

// format and print the current month in german
var formattedString = moment.format("LLLL");
print(formattedString);

Features and bugs

Please file feature requests and bugs at the issue tracker.

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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