패키지, 저장소 및 앱 카테고리 검색

패키지 상세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

카테고리

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.