Giter VIP home page Giter VIP logo

calendar_time's Introduction

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

import 'package:calendar_time/calendar_time.dart';

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

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)

import 'package:calendar_time/calendar_time.dart';

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

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
}

calendar_time's People

Contributors

k00na avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.