0.1.1 • Published 8 years ago

nexttime v0.1.1

Weekly downloads
3
License
MIT
Repository
github
Last release
8 years ago

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)

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 gckarunarathne@gmail.com