0 purchases
calendar time
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}
}
copied to clipboard
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");
}
copied to clipboard
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
}
copied to clipboard
isTomorrow #
Return if the supplied DateTime is tomorrow
import 'package:calendar_time/calendar_time.dart';
main(){
final calendarTime = CalendarTime(DateTime.now());
calendarTime.isTomorrow; //false
}
copied to clipboard
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
}
copied to clipboard
isYesterday #
Return if the supplied DateTime is yesterday
import 'package:calendar_time/calendar_time.dart';
main(){
final calendarTime = CalendarTime(DateTime.now());
calendarTime.isYesterday; //false
}
copied to clipboard
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
}
copied to clipboard
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
}
copied to clipboard
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
}
copied to clipboard
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
}
copied to clipboard
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
}
copied to clipboard
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
}
copied to clipboard
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
}
copied to clipboard
endOfTomorrow #
Return the end of tomorrow
import 'package:calendar_time/calendar_time.dart';
main(){
final calendarTime = CalendarTime(DateTime.now());
calendarTime.endOfTomorrow; // DateTime
}
copied to clipboard
endOfNextWeek #
Return the end of next week
import 'package:calendar_time/calendar_time.dart';
main(){
final calendarTime = CalendarTime(DateTime.now());
calendarTime.endOfNextWeek; // DateTime
}
copied to clipboard
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.