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

패키지 상세v1.2.2

any_date

임의의 형식으로 문자열을 DateTime으로 파싱하기 위한 패키지입니다. 어떤 형식이나 언어로든 날짜를 쉽게 파싱할 수 있으며, 항상 ISO 및 RFC 형식을 존중합니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
6.8천
좋아요
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 개

소스 저장소

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