npm.io
1.0.0 • Published 10 years ago

moment-rental

Licence
MIT
Version
1.0.0
Deps
1
Vulns
0
Weekly
0
Stars
1

moment-rental

Summary

Extends Moment.js to properly calculate the number of rental days between two given dates

Syntax: Add rental days to current date

moment().rentalAdd(days[, saturdays]);
Parameters
  • days (integer) Number of rental days to add to current date
  • saturdays (BOOL) Weather or not to include Saturdays
Syntax: Get rental day breakdown
moment(endDate).rentalDays(startDate[, saturdays]);
Parameters
  • endDate (moment object) End date of rental
  • startDate (moment object) Start date of rental
  • saturdays (BOOL) Weather or not to include Saturdays

Installation

Install package
npm i moment-rental -S
Require in project
// ES5
var moment = require('moment');
require('moment-rental');

// ES6
import moment from 'moment';
import moment-rental;

Examples

Get new end date
moment('2015-02-04').rentalAdd(3).format('MM-DD-YYYY');
// 02-09-2015
Get new end date including Saturdays
moment('2015-02-04').rentalAdd(3, true).format('MM-DD-YYYY');
// 02-07-2015
Get rental day breakdown
moment('2015-02-12 08:00').rentalDays('2015-02-04 08:00');
// { Day: 0, FourWeek: 0, RentalDays: 6, Week: 1 }
Get rental day breakdown including Saturdays
moment('2015-02-12 08:00').rentalDays('2015-02-04 08:00', true);
// { Day: 0, FourWeek: 0, RentalDays: 7, Week: 1 }