搜尋分類、套件與程式碼儲存庫

GitHub 儲存庫rknell/calendar_time

日曆時間

MomentJS 的 calendarTime 的 Dart 實現

日曆時間 專案封面
星標
15
分支
12
最近推送(UTC)
2024年5月31日
專案狀態
未封存

原始 README

以下為英文專案原文快照,最新內容請造訪 GitHub。

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
}
Ryan Knell GitHub avatar
GitHub 作者

Ryan Knell ↗

Snappy AppsBrisbane, Australia官方網站 ↗
語言Dart

此儲存庫發佈的套件

使用的依賴

依賴清單 3 項

如何選擇適合專案的儲存庫?

先依使用情境篩選,再比較專案活躍情況,最後到原始儲存庫確認使用要求。

  1. 透過儲存庫名稱、作者或描述搜尋,再依技術分類縮小範圍。
  2. 綜合星標、分支與最近推送比較專案;星標反映社群關注,不保證品質。
  3. 使用前在 GitHub 確認 README、授權條款與 Issues。

來源與維護

“A repository is the most basic element of GitHub.”

GitHub Docs — About repositories ↗