Skip to content

Calculate a date range relative to a certain moment and format them nicely

Notifications You must be signed in to change notification settings

Swydo/moment-relative-range

Repository files navigation

previous-date-range

Calculate a date range in the past from a certain moment

Build status

Installation

npm

npm i -S previous-date-range

yarn

yarn add previous-date-range

Basic usage

You can use moment().previous(units, measure):

import moment from 'moment';
import 'previous-date-range';

var range = moment().previous(5, 'days');

// range.start = 6 days ago
// range.end = yesterday
// range.length = 5

var clone = range.previous(2, 'months');

// clone.start = start of 2 months ago
// clone.end = end of last month
// clone.length = the length of the last 2 months

It's also possible to construct a range yourself:

import { PreviousDateRange as Range } from 'previous-date-range';

var range = new Range({
    date: new Date(),
    units: 5,
    measure: 'days'
});

// The results are the same as above

About

Calculate a date range relative to a certain moment and format them nicely

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published