분류, 패키지 및 저장소 검색

패키지 상세v2.3.0

calendar_time

MomentJS의 캘린더 시간 구현 및 기타 여러 도우미 메서드.

AndroidiOSWebmacOSWindowsLinux
30일 다운로드
124
좋아요
27
Pub 점수
130

패키지 설치

flutter pub add calendar_time

패키지 개요

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

MomentJS의 캘린더 시간 형식을 구현한 Flutter/Dart 패키지로, '2시간 후' 또는 '2일 전'과 같은 직관적인 상대 시간 표시를 제공합니다. 날짜 조작 및 포맷팅을 위한 추가 헬퍼 메서드를 포함하여 사용자 중심 애플리케이션에서 타임스탬프를 다루는 것을 더 쉽게 만듭니다. 크로스플랫폼 사용을 위해 설계되어 Android, iOS, Web, macOS, Windows, Linux를 지원합니다. 이 패키지는 인간이 읽기 쉬운 형식으로 시간 차이를 표현하는 것을 단순화하여, 동적 시간 표시가 필요한 앱의 UX를 향상시킵니다.

사용 사례

  • 채팅 앱에서 상대적 시간 표시하기
  • 소셜 피드에서 게시물 또는 활동 나이 표시
  • 알림에서 시간 차이 형식 지정
  • 읽기 쉬운 시간 레이블을 통한 사용자 경험 향상
  • 작업 관리 앱에서 날짜 로직을 단순화하기

주요 기능

  • MomentJS 스타일의 캘린더 시간 포맷팅
  • 크로스 플랫폼 호환성
  • 날짜 작업을 위한 보조 메서드
  • 읽기 쉬운 시간 표현
  • pub add 명령을 통한 간편한 통합

적합한 대상

  • 상대 시간 표시가 필요한 앱
  • MomentJS에 익숙한 개발자
  • 일관된 시간 형식이 필요한 프로젝트
  • 실시간 업데이트를 갖춘 UI 중심 애플리케이션
  • 개발자 생산성을 우선시하는 팀

고려 사항

  • 상대적 시간 개념을 이해해야 합니다
  • 영어 이외의 로케일에 대한 현지화 설정이 필요할 수 있습니다
  • 시간 형식 지정에만 제한됨—완전한 날짜 파싱 없음
  • Dart의 핵심 DateTime 클래스에 의존합니다
  • 복잡한 날짜 산술에 적합하지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

calendar_time

Implementation of MomentJS's calendarTime function and some other helpful utilities.

I expect this project will get replaced with another more ambitious project in the future, but this has come in very handy. Extensions and pull requests welcome.

Usage

toHuman

Converting a DateTime to a human readable string

import 'package:calendar_time/calendar_time.dart';

main(){
  CalendarTime(DateTime.now()).toHuman; //Today at {current time}
}

Example output:

  • Today at {current time}
  • Tomorrow at {time}
  • Yesterday at {time}
  • {day} at {time}
  • Last {day} at {time}
  • date time (outside of the last or upcoming few weeks)

Honestly just check the code, but it is in line with Moment's logic.

You can also call .toHumanMultiLine that splits the output around at to have date and time on different lines.

format

Formats to current timezone

import 'package:calendar_time/calendar_time.dart';

main(){
  CalendarTime(DateTime.now()).format("yyyy-MM-dd HH:mm");
}

See https://pub.dev/documentation/intl/latest/intl/DateFormat-class.html for options.

isToday

Return if the supplied DateTime is today

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isToday; //true
}
isTomorrow

Return if the supplied DateTime is tomorrow

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isTomorrow; //false
}
isNextWeek

Return if the supplied DateTime is next week

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isNextWeek; //false
}
isYesterday

Return if the supplied DateTime is yesterday

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isYesterday; //false
}
isLastweek

Return if the supplied DateTime is last week

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.isLastWeek; //false
}
startOfToday

Return the beginning of today - not to be confused with startOfDay

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.startOfToday; // DateTime
}
startOfDay

Return the beginning of the day of the CalendarTime obejct.

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime(2020,1,1));
  calendarTime.startOfDay; // 2020/01/01 0:0:0am
}
startOfYesterday

Return the beginning of yesterday

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.startOfYesterday; // DateTime start of yesterday
}
startOfLastWeek

Return the beginning of lastWeek

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.startOfLastWeek; // DateTime start of yesterday
}
endOfToday

Return the end of today (23:59:59:999:999) - not to be confused with endOfDay

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.endOfToday; // DateTime
}
endOfDay

Return the end of the day of the CalendarTime object (23:59:59:999:999)

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime(2020, 1,1));
  calendarTime.endOfToday; // 2020/01/01 23:59:59:999:999
}
endOfTomorrow

Return the end of tomorrow

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.endOfTomorrow; // DateTime
}
endOfNextWeek

Return the end of next week

import 'package:calendar_time/calendar_time.dart';

main(){
  final calendarTime = CalendarTime(DateTime.now());
  calendarTime.endOfNextWeek; // DateTime
}

카테고리

의존성

의존성 목록 1 개

소스 저장소

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

아직 데이터가 없습니다.