Giter Site home page Giter Site logo

nexttime's Introduction

NextTime

Simple tool set to calculate next event occurring date.

Installation

Use NPM to install using;

npm install nexttime --save

Getting Started

NextTime module contains an API to predict next event occurring date or dates. Lets assume that current date is Tue Dec 01 2015 00:00:00 GMT+0530 (IST). Then following method calls will calculate required events as below;

// Create a NextTime instance
let nextTime = require('nexttime').NextTime;

nextTime.nextDate();
// Wed Dec 02 2015 00:00:00 GMT+0530 (IST)
nextTime.nextDate(new Date(2015, 11, 1));
// Wed Dec 02 2015 00:00:00 GMT+0530 (IST)

nextTime.nextDate(new Date(2015,11,1), new Date(2015,11,4));
// ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Wed Dec 02 2015 00:00:00 GMT+0530 (IST)', 'Thu Dec 03 2015 00:00:00 GMT+0530 (IST)']
nextTime.nextDate(new Date(2015,11,4));
// ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Wed Dec 02 2015 00:00:00 GMT+0530 (IST)', 'Thu Dec 03 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextWeek();
// Tue Dec 08 2015 00:00:00 GMT+0530 (IST)
nextTime.nextWeek(new Date(2015, 11, 1));
// Tue Dec 08 2015 00:00:00 GMT+0530 (IST)

nextTime.nextWeeks(new Date(2015,11,1), new Date(2015,11,10));
// ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Tue Dec 08 2015 00:00:00 GMT+0530 (IST)']
nextTime.nextWeeks(new Date(2015,11,11));
// ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Tue Dec 08 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextMonth();
// Fri Jan 01 2016 00:00:00 GMT+0530 (IST)
nextTime.nextMonth(new Date(2015, 11, 1));
// Fri Jan 01 2016 00:00:00 GMT+0530 (IST)
nextTime.nextMonth(new Date(2016,1,29), 31);
// 'Thu Mar 31 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextMonths(new Date(2015,11,31), new Date(2016,2,24));
// ['Thu Dec 31 2015 00:00:00 GMT+0530 (IST)', 'Sun Jan 31 2015 00:00:00 GMT+0530 (IST)', 'Mon Feb 29 2015 00:00:00 GMT+0530 (IST)']
nextTime.nextMonths(new Date(2016,2,24));
// ['Thu Dec 31 2015 00:00:00 GMT+0530 (IST)', 'Sun Jan 31 2015 00:00:00 GMT+0530 (IST)', 'Mon Feb 29 2015 00:00:00 GMT+0530 (IST)']

API

  1. nextDate([date])
  2. nextDates([startDate], endDate)
  3. nextWeek([date])
  4. nextWeeks([startDate], endDate)
  5. nextMonth([date] [,upto])
  6. nextMonths([startDate], endDate)

1. nextDate([date])

Get next date after a given date

Parameters
  • date : {Integer/Date/Date String} A valid date format

(optional) Default new Date()

Return
  • {Date} Next Date instance
USAGE:

If current date is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', then following method return 'Wed Dec 02 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextDate();

If feed with a date 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', then following method return 'Wed Dec 02 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextDate(new Date(2015,11,1));

2. nextDates([startDate], endDate)

Get next dates between given startDate and endDate period

Parameters
  • startDate : {Integer/Date/Date String} A valid date format

(optional) Default new Date()

  • endDate : {Integer/Date/Date String} A valid date format

(required) If endDate isn't provided, take startDate as endDate

Return
  • {Array of Date} Next Dates instance
USAGE:

If startDate is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)' and endDate is 'Fri Dec 04 2015 00:00:00 GMT+0530 (IST)', then following method return ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Wed Dec 02 2015 00:00:00 GMT+0530 (IST)', 'Thu Dec 03 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextDates(new Date(2015,11,1), new Date(2015,11,4));

If current time is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)' and call method with 'Fri Dec 04 2015 00:00:00 GMT+0530 (IST)' will return ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Wed Dec 02 2015 00:00:00 GMT+0530 (IST)', 'Thu Dec 03 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextDates(new Date(2015,11,4));

3. nextWeek([date])

Get date of next week for a given date

Parameters
  • date : {Integer/Date/Date String} A valid date format

(optional) Default new Date()

Return
  • {Date} Next week Date instance
USAGE:

If current date is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', then following method return 'Tue Dec 08 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextWeek();

If feed with a date 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', then following method return 'Tue Dec 08 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextWeek(new Date(2015,11,1));

4. nextWeeks([startDate], endDate)

Get dates of next weeks between given startDate and endDate period

Parameters
  • startDate : {Integer/Date/Date String} A valid date format

(optional) Default new Date()

  • endDate : {Integer/Date/Date String} A valid date format

(required) If endDate isn't provided, take startDate as endDate

Return
  • {Array of Date} Next weeks' Date objects
USAGE:

If startDate is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)' and endDate is 'Fri Dec 11 2015 00:00:00 GMT+0530 (IST)', then following method return ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Tue Dec 08 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextWeeks(new Date(2015,11,1), new Date(2015,11,10));

If current time is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)' and call method with 'Fri Dec 11 2015 00:00:00 GMT+0530 (IST)' will return ['Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', 'Tue Dec 08 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextWeeks(new Date(2015,11,11));

5. nextMonth([date] [,upto])

Get date of next month for a given date NOTE: When end of month provided, it'll return possible end of next month

Parameters
  • date : {Integer/Date/Date String} A valid date format

(optional) Default new Date()

  • upto : {Integer} Most value end of month can change

(optional) Default set to date of date parameter

Return
  • {Date} Next month Date instance
USAGE:

If current date is 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', then following method return 'Fri Jan 01 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextMonth();

If feed with a date 'Tue Dec 01 2015 00:00:00 GMT+0530 (IST)', then following method return 'Fri Jan 01 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextMonth(new Date(2015,11,1));

NOTE:

If upto provided 'Mon Feb 29 2016 00:00:00 GMT+0530 (IST)', then return 'Thu Mar 31 2015 00:00:00 GMT+0530 (IST)'

nextTime.nextMonth(new Date(2016,1,29), 31);

6. nextMonths([startDate], endDate)

Get dates of next months between given startDate and endDate period

Parameters
  • startDate : {Integer/Date/Date String} A valid date format

(optional) Default new Date()

  • endDate : {Integer/Date/Date String} A valid date format

(required) If endDate isn't provided, take startDate as endDate

Return
  • {Array of Date} Next months' Date objects
USAGE:

If startDate is 'Thu Dec 31 2015 00:00:00 GMT+0530 (IST)' and endDate is 'Thu Mar 24 2016 00:00:00 GMT+0530 (IST)', then following method return ['Thu Dec 31 2015 00:00:00 GMT+0530 (IST)', 'Sun Jan 31 2015 00:00:00 GMT+0530 (IST)', 'Mon Feb 29 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextMonths(new Date(2015,11,31), new Date(2016,2,24));

If current time is 'Thu Dec 31 2015 00:00:00 GMT+0530 (IST)' and call method with 'Thu Mar 24 2016 00:00:00 GMT+0530 (IST)' will return ['Thu Dec 31 2015 00:00:00 GMT+0530 (IST)', 'Sun Jan 31 2015 00:00:00 GMT+0530 (IST)', 'Mon Feb 29 2015 00:00:00 GMT+0530 (IST)']

nextTime.nextMonths(new Date(2016,2,24));

Testing

  1. Install dependencies with npm install
  2. Run test cases
  • npm run test (just tests)
  • npm run test-debug (test with more debug logs)

License

This Software is licensed under MIT License

Copyright (c) 2015 Gihan Karunarathne [email protected]

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.