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

パッケージ詳細v2.1.6

time

型安全な DateTime および Duration の計算、拡張機能によって駆動されます。

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

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

flutter pub add time

パッケージ概要

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

time パッケージは、Dart で型安全な DateTime および Duration の計算を提供し、直感的な拡張機能を通じて信頼性と読みやすさを向上させます。手動での日付操作に関連するランタイムエラーを防ぐために、明確でスムーズな API を提供することで、一般的な日付および時刻操作を簡素化します。安全性と開発者体験を重視して設計されており、モバイル、Web、デスクトップを含むすべての主要プラットフォームをサポートしています。スケジューリング、タイマー、イベント追跡など、正確な時間処理が必要なアプリケーションに最適です。

用途

  • スケジューリングイベント
  • 時間差の計算
  • カウントダウンタイマーの構築
  • 繰り返しタスクの処理
  • タイムゾーンの管理
  • トラッキング期間

主な機能

  • 型安全な操作
  • 広範な拡張メソッド
  • クロスプラットフォーム対応
  • コンパイル時安全性
  • 直感的な構文
  • 不変の期間処理

適している対象

  • 信頼性のある時間論理を必要とする開発者
  • 複雑なスケジューリングを持つアプリ
  • 時間ベースの分析
  • リアルタイムアプリケーション
  • 時間操作のための教育ツール

注意事項

  • Dart の拡張について理解が必要
  • ビルドサイズをわずかに増加させる可能性があります
  • 低レベルのシステム時刻アクセスには適していません
  • 高レベルな時刻計算に限定
  • 組み込みのタイムゾーン変換なし

元の README

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

⏰ Time

Build codecov pub package

With shiny extensions, if you have ever written something like this, then look no further:

final DateTime fourHoursFromNow = DateTime.now() + Duration(hours: 4);

🎖 Installation

dependencies:
  time: "^2.1.6"
⚡ Import
import 'package:time/time.dart';

🎮 Usage

final Duration tenMinutes = 10.minutes;
final Duration oneHourThirtyMinutes = 1.5.hours;
final DateTime afterTenMinutes = DateTime.now() + 10.minutes;
final Duration tenMinutesAndSome = 10.minutes + 15.seconds;
final int tenMinutesInSeconds = 10.minutes.inSeconds;
final DateTime tenMinutesFromNow = 10.minutes.fromNow;

You can perform all basic arithmetic operations on Duration as you always have been:

final Duration interval = 10.minutes + 15.seconds - 3.minutes + 2.hours;
final Duration doubled = interval * 2;

You can also use these operations on DateTime:

final DateTime oneHourAfter = DateTime() + 1.hours;

Duration is easily convertible as it always has been:

final int twoMinutesInSeconds = 2.minutes.inSeconds;

You can also convert Duration to DateTime, if needed:

final DateTime timeInFuture = 5.minutes.fromNow;
final DateTime timeInPast = 5.minutes.ago;

Iterate through a DateTime range:

final DateTime start = DateTime(2019, 12, 2);
final DateTime end = start + 1.weeks;
final DateTime tuesday = start.to(end).firstWhere((date) => date.weekday == DateTime.tuesday);

Granular comparison between DateTime fields:

final DateTime specificDate = DateTime(2021, 01, 01);
final DateTime otherDate = DateTime(2021, 02, 01);

print(specificDate.isAtSameYearAs(otherDate)); // true
print(specificDate.isAtSameMonthAs(otherDate)); // false
print(specificDate.isAtSameDayAs(otherDate)); // false

You can also delay code execution:

void doSomething() async {
  await 5.seconds.delay;
  // Do the other things
}

You can also use the popular copyWith:

final initial = DateTime(2019, 2, 4, 24, 50, 45, 1, 1);
final expected = initial.copyWith(
  year: 2021,
  month: 10,
  day: 28,
  hour: 12,
  minute: 45,
  second: 10,
  millisecond: 0,
  microsecond: 12,
);

Visit the API Reference to find out all that is available.

🐛 Bugs/Requests

If you encounter any problems feel free to open an issue. If you feel the library is missing a feature, please raise a ticket on Github and I'll look into it. Pull request are also welcome.

👏 Inspiration

  • Swift library of the same name - Time.
  • Kotlin library of the same name - Time.

⭐ License

MIT License

カテゴリー

依存関係

依存関係一覧 1 件

ソースリポジトリ

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

ランキング