Giter Club home page Giter Club logo

moment-array-dates's Introduction

Moment Array Dates

A small utility function that returns an array of formatted date strings.

Build Status Coverage Status Code Climate npm

Installation

npm install --save moment-array-dates

Usage

Import package:

var dateArray = require('moment-array-dates');

Functions

.range(startDate, endDate, format, ascending)

Returns an array of formatted dates including the start and end dates. Format and the last boolean parameter is optional.

dateArray.range('09/01/2016', '09/05/2016', 'MMM DD', true)

Output: [ 'Sep 01', 'Sep 02', 'Sep 03', 'Sep 04', 'Sep 05' ]

.lastNDays(number of days, format, ascending)

Returns an array of formatted dates from the last n days excluding today. Format and the last boolean parameter is optional.

# today: October 25, 2016
dateArray.lastNDays(5, 'MMM DD', true)

Output: [ 'Oct 20', 'Oct 21', 'Oct 22', 'Oct 23', 'Oct 24' ]

.nextNDays(number of days, format, ascending)

Returns an array of formatted dates from the next n days excluding today. Format and the last boolean parameter is optional.

# today: October 25, 2016
dateArray.nextNDays(5, 'MMM DD', true)

Output: [ 'Oct 26', 'Oct 27', 'Oct 28', 'Oct 29', 'Oct 30' ]

Please refer to the Momentjs documentation for formatting options

Todos

  • Do method chaining / piping for advanced operations

License

MIT

moment-array-dates's People

Contributors

johncrisostomo avatar

Stargazers

Victor Anjos avatar Adel Bruno Grimm avatar Deejay Geroso avatar

Watchers

James Cloos avatar

Forkers

vidimitrov

moment-array-dates's Issues

.range() method excludes endDate in range if param is formatted as YYYY-MM-DD

The .range() method call does not produce the expected results per documentation when using `YYYY-MM-DD' format.

const dateRange = dateArray
    .range('2019-05-19', '2019-11-19', 'YYYY-MM-DD', true)

Expected Result: ["2019-05-19", ... , "2019-11-19"]

The expected result is an Array of date strings in ascending order, beginning with '2019-05-19' and ending with '2019-11-19'

Actual Result: ["2019-05-18", ... , "2019-11-18"]

The actual result, however, begins with 2019-05-18 and ends with 2019-11-18.
It begins a day before the provided startDate and ends a day before the provided endDate.

If the startDate and endDate are provided in MM/DD/YYYY format (as shown in readme examples), it works as documented. However, the readme documentation makes no mention that the above date formate is required, and the package appears able to understand the provided YYYY-MM-DD format, but doesn't return the expected range.

It seems either the readme documentation should make it clear if there is any constraint regarding the dateString format that can be provided to the range method. If there is no such constraint, then it appears there is a bug when passing in YYY-MM-DD formatted strings.

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.