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

패키지 상세v2.1.6

time

타입 안전한 DateTime 및 Duration 계산, 확장 기능으로 구동됩니다.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
107만
좋아요
387
Pub 점수
160

패키지 설치

flutter pub add time

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

time 패키지는 Dart에서 타입 안전한 DateTime 및 Duration 계산을 제공하며, 직관적인 확장 기능을 통해 신뢰성과 가독성을 향상시킵니다. 수동적인 날짜 조작으로 인한 런타임 오류를 방지하기 위해 깔끔하고 매끄러운 API를 제공하여 일반적인 날짜 및 시간 작업을 간소화합니다. 안정성과 개발자 경험을 고려해 설계되었으며, 모바일, 웹, 데스크톱을 포함한 모든 주요 플랫폼을 지원합니다. 스케줄링, 타이머 또는 이벤트 추적과 같은 정밀한 시간 처리가 필요한 애플리케이션에 이상적입니다.

사용 사례

  • 일정 이벤트
  • 시간 차이 계산
  • 카운트다운 타이머 구축
  • 반복 작업 처리
  • 시간대 관리
  • 추적 기간

주요 기능

  • 타입 안전한 연산
  • 풍부한 확장 메서드
  • 크로스 플랫폼 지원
  • 컴파일 시 안전성
  • 직관적인 구문
  • 불변 기간 처리

적합한 대상

  • 신뢰할 수 있는 시간 논리를 필요로 하는 개발자
  • 복잡한 스케줄링을 가진 앱
  • 시간 기반 분석
  • 실시간 애플리케이션
  • 시간 조작을 위한 교육 도구

고려 사항

  • 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 개

소스 저장소

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

순위