icambron / twix.js

:hourglass::left_right_arrow: A date range plugin for moment.js
https://isaaccambron.com/twix.js/
MIT License
379 stars 54 forks source link

Ability to split a date range by number #87

Closed RemiAWE closed 8 years ago

RemiAWE commented 8 years ago

Hello, thank you for this excellent library.

Is there a way to split a dateRange in n parts ? Actually the split() function split only by a time or duration but it cannot split by number like .split(5)

icambron commented 8 years ago

There isn't a way to do that now. I'd accept a PR for a function called divideEqually(numberOfParts)

icambron commented 8 years ago

I added this in 03b055d and will release it soon. In the meantime, it turns out that it's really simple, so you can do it yourself. This splits a range into 5 equal parts, leaving off the remainder (at most 4 milliseconds):

var n = 5
range.split(range.length() / n, 'ms').slice(0, n)