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

パッケージ詳細v1.2.2

any_date

任意の形式で文字列をDateTimeにパースするためのパッケージ。任意の形式および任意の言語での日付のパースが簡単であり、常にISOおよびRFC形式を尊重します。

AndroidiOSWebmacOSWindowsLinux
30日間ダウンロード
6770
いいね数
17
Pub ポイント
160

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

flutter pub add any_date

パッケージ概要

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

AnyDate は、任意の日付形式および言語をサポートする DateTime オブジェクトへの文字列パースを簡素化することを目的とした Flutter/Dart パッケージです。さまざまな入力形式を自動的に検出し処理し、ISO および RFC 標準を優先します。日付形式が一貫していないまたは不明なアプリケーションに最適で、ボイラープレートコードを削減し信頼性を向上させます。このパッケージはすべての主要プラットフォームで動作するため、クロスプラットフォーム開発に非常に柔軟です。

用途

  • フォームからユーザー入力の日付を解析する
  • 国際的な日付形式の取り扱い
  • レガシーデート文字列を DateTime に変換する
  • ログ内の日付形式の自動検出
  • 多言語日付入力のサポート

主な機能

  • 日付形式を自動検出
  • 複数言語をサポート
  • ISO および RFC 標準を尊重します
  • クロスプラットフォーム互換性
  • 最小限の構成が必要
  • 堅牢なエラー処理

適している対象

  • 動的な日付入力を持つアプリ
  • 国際化アプリケーション
  • データ移行ツール
  • ログ解析ユーティリティ
  • 柔軟な日付パースを必要とする開発者ツール

注意事項

  • 大規模な解析ではパフォーマンスのオーバーヘッドが発生する可能性があります
  • 厳密なフォーマット検証には適していません
  • 曖昧な日付を誤解する可能性のあるヒューリスティクスに依存しています
  • 例外的なフォーマットに対するカスタマイズの制限
  • フォーマットの不確実性が予想されるときに最適に使用

元の README

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

PubStats Popularity

Package to improve DateTime manipulation, especially by allowing parsing any format. Heavily inspired by python's dateutil package.

Summary

In a glance, these are the features:

  1. Easy parsing of a String with many date formats into a DateTime object
  2. Same flexibility supported in almost any Locale. Not just English, but any language and culture
  3. Always compliant with ISO 8601 and major RFCs (822, 2822, 1123, 1036 and 3339), regardless of Locale
  4. Supports UNIX time in either seconds, milliseconds, microseconds, or nanoseconds since epoch

Basic usage

Usage is simple, use the AnyDate() constructor to create a parser with the desired settings, and use it to parse any String into DateTime, regardless of the format.

Note that, in order to resolve ambiguity, some settings are required either on the AnyDate() constructor or on the AnyDate.defaultSettings static attribute.

const parser = AnyDate();
final date = parser.parse('13 Aug 2023');
final sameDate = parser.parse('Aug 13 2023');
final stillTheSame = parser.parser('2023, August 13');
// in all cases date is parsed as DateTime(2023, 08, 13)

However, you may notice that the example above is in English. What if you want a different Locale? You can use the AnyDate.fromLocale() factory method to get the desired parser:

// American English
final parser1 = AnyDate.fromLocale('en-US');
final date1 = parser.parse('August 13, 2023');
// note that even if formatting is unusual for locale, it can still understand unambiguous dates
final sameDate = parser.parse('13 August 2023'); // this is not common for US locale, but it still parses normally


// Brazilian Portuguese
final parser2 = AnyDate.fromLocale('pt-BR');
final date2 = parser.parse('13 de Agosto de 2023');

// again, they all resolve to same DateTime value

Solving ambiguous cases

Moreover, the parser can be used to solve ambiguous cases. Look at the following example:

// what date is this? 1 Feb 2003, 2 Jan 2003, or worse 2 Mar 2001?
// this could be dd/mm/yy, mm/dd/yy or yy/mm/dd
const ambiguousDate = '01/02/03';

// the parser can be configured for all cases:
// mm/dd/yy (this is the default behaviour)
const parser1 = AnyDate();
final case1 = a.parse(ambiguousDate); // results in DateTime(2003, 1, 2);

// dd/mm/yy
const dayFirstInfo = DateParserInfo(dayFirst: true);
const parser2 = AnyDate(info: info);
final case2 = a.parse(ambiguousDate); // results in DateTime(2003, 2, 1);

// yy/mm/dd
const yearFirstInfo = DateParserInfo(yearFirst: true);
const parser3 = AnyDate(info: info);
final case3 = a.parse(ambiguousDate); // results in DateTime(2001, 2, 3);

Using a Locale based parser also allows you to solve ambiguity based on that culture:

// same example:
const ambiguousDate = '01/02/03';

// American English
final parser1 = AnyDate.fromLocale('en-US');
final date1 = parser.parse(ambiguousDate); // the ambiguous date results in Jan 2, 2003 (mm/dd/yy)


// Brazilian Portuguese
final parser2 = AnyDate.fromLocale('pt-BR');
final date2 = parser.parse(ambiguousDate); // the ambiguous date results in Feb 1, 2003 (dd/mm/yy)

Feedback appreciated 💙

Read the docs at https://el-darto.net/

カテゴリー

依存関係

依存関係一覧 2 件

ソースリポジトリ

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