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

パッケージ詳細v0.1.4

date_util

DateTime API にない完全な日付ヘルパーメソッドを備えたシンプルなDart APIであり、日付処理の生産性を向上させます。

30日間ダウンロード
103
いいね数
28
Pub ポイント
25

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

flutter pub add date_util

パッケージ概要

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

date_util は、組み込みの DateTime API を超える包括的な日付ヘルパー メソッドを提供する Dart パッケージです。フォーマット、パース、比較、計算などの一般的な日付操作を簡素化し、Flutter および Dart アプリケーションでの日付処理をより直感的かつ効率的にします。使いやすさを重視して設計されており、ボイラープレートコードを削減し、本番環境で日付を管理する際の生産性を高めます。

用途

  • 日付の解析とフォーマット
  • 日付の演算を実行する
  • 日付範囲の比較
  • 日付シーケンスの生成
  • タイムゾーンの取り扱い
  • 日付検証の簡素化

主な機能

  • 広範な日付操作メソッド
  • 洗練された直感的な API
  • 外部の依存関係なし
  • 複数の日付形式をサポートします
  • 組み込みのタイムゾーンユーティリティ
  • 堅牢なエラー処理

適している対象

  • 日付論理が必要なFlutterアプリ
  • 日付処理を伴うバックエンドサービス
  • 国際的な日付形式を必要とするアプリ
  • 開発者は手動での日付パースを避ける
  • コードの可読性を最優先とするチーム

注意事項

  • Dart/Flutter プラットフォームに限定
  • 組み込みのローカライゼーションサポートなし
  • 手動での依存関係の管理が必要です
  • 複雑なカレンダーシステムには適していません
  • 実行時構成オプションなし
  • 基本的な例を超える最小限のドキュメント

元の README

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

Date utility

A simple dart API with a complete set of date helper methods not available in the DateTime API hence,production is made easier when working with dates.

features

The class dateUtil contains the following method:

  • yearLength
  • day
  • month
  • daysInMonth
  • daysPastInYear
  • totalLengthOfDays
  • printMonthCalendar
  • getWeek
  • leapYear

The yearLength method: The yearLength method has a single parameter of type integer and it calculates the number of days from the beginning of calendar to the entered year

yearLength(int year);

The day method: The day method has a single parameter of type integer and it returns the string equivalent of given date day

day(int length);

The month method: The month method has a single parameter of type integer and it returns the string equivalent of given month number

month(int monthNum);

The daysInMonth method: The daysInMonth method has two parameters of type # # # #integer and it returns the total number of days in a month

daysInMonth(int monthNum, int year);

The daysPastInYear method: This method has three parameters of type integer and it returns the total number of days past in a given year

daysPastInYear(int monthNum, int dayNum, int year);

The totalLengthOfDays method: This method has three parameters of type integer and it returns the total number of days past since the beginning of the calendar year 0001

totalLengthOfDays(int monthNum, int dayNum, int year);

The printMonthCalendar method; This method has two parameter of type integer and it prints the calendar of the given month in the given year.

printMonthCalendar(int monthNum, int year);

The getWeek method: This method has three parameters of type integer and returns the weeks past in the year.

getWeek(int monthNum, int dayNum, int year);

The leapYear method: This method has a single parameter of type integer also and returns a boolean value if the given year is a leap year

leapYear(int year);

Usage

Simply create an instance of the class dateUtil.dart in your main() block

final dateUtility = DateUtil();

Import the 'dart: io' api and request for user input on month number, day number and year.

//Prompting for user input of the month number
stdout.writeln('Enter month number');
final monthNumber = int.parse(stdin.readLineSync());

Output:

Enter Month Number 11

//Prompting for user input of the  day  number
stdout.writeln('Enter day number');
final dayNumber = int.parse(stdin.readLineSync());

Output:

Enter day number 12

//Prompting for user input of the year
stdout.writeln('Enter year ');
final year = int.parse(stdin.readLineSync());

Output:

Enter year 1975

Note: When using the standard input stream, the returned data type is a String hence the parsing of the returned data to the required data type.

Create a variable name of type integer to store the total number of days past since the beginning of the calendar year 0001

//store the total number of days past since the beginning of the calendar year 0001
final length = dateUtility.totalLengthOfDays(monthNumber, dayNumber, year);
The above line of code returns the total number of days past in a year plus the number of days from the beginning of calendar to the entered year

Create a variable name of type String to store the result of the entered date day which calls the day() method for getting the string equivalent of the entered date day and thereby passing the variable name of step 3

//store the string equivalent of entered date day
String resultDay = dateUtility.day(length);

Create a variable name to store the string equivalent of the given Month number

//store the string equivalent of entered month number
String monthName = dateUtility.month(monthNumber);

Printing the result.

//Printing the details
stdout.writeln('The Day $resultDay, the Month is $monthName and the year is $year');

Output:

The Day Wednesday, the Month is November and the year is 1975

Using the days past in a year method:

Create a variable name to store the returned value of the day(s) past in a year method.

//calculating total number of days past in a given year
int daysPast = dateUtility.daysPastInYear(monthNumber, dayNumber, year);

Printing the details

//Printing out the result for days past in a given year
stdout.writeln('Days past in the year is: $daysPast day(s)');

Output:

Days past in the year is: 316 day(s)

Using the weeks past in a year Create a variable name to store the returned value of the week(s) past in a year method.

//calculating the week past in  the entered date in the year
int weeks = dateUtility.getWeek(monthNumber, dayNumber, year);

Printing the details

//Printing the number of weeks past in a given year
stdout.writeln('Week(s): $weeks week(s)');

Output:

Week(s): 46 week(s)

Using the print month calendar:

//Printing the calendar for the month in a given year
dateUtility.printMonthCalendar(monthNumber, year);

Output:

Sun Mon Tue Wed Thur Fri Sat 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

using the leap year method to check if a year is a leap year

//Checking if a year is a leap year
stdout.writeln('Is $year a leap year? \n Answer: ${dateUtility.leapYear(year)}');

Output:

Is 1975 a leap year? Answer: false

カテゴリー

ソースリポジトリ

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

データはまだありません。