Closed IvanJov closed 7 years ago
I like the toArray()
idea but it shouldn't be responsible for the formatting; it should just return times. You can always do this:
t.toArray().map((m) -> m.format("YYYY-MM-DD"))
Or perhaps it can have a second optional mapper
argument like this:
t.toArray((m) -> m.format("YYYY-MM-DD"))
@icambron You are right, I will remove the formatting! And I don't like the idea with mapper
argument, maybe that's too much also :)
What do you think?
Let me know if this looks better!
I left a couple of specific comments. If you fix those and also edit https://github.com/icambron/twix.js/blob/master/docs/docs.md, I'll merge this. Thanks for the contribution!
@icambron I've fixed those issues, sorry! Not so experienced with CoffeeScript, this is basically my first code written in it 😄
And re docs, what do you think, what's the best place to put toArray
function?
You know, I'll do the docs, so don't worry about that. Thanks again!
@icambron Ok sure, thanks! I am glad I helped! If I come to something that can be useful I'll commit again!
@IvanJov Actually, now that I sit down to document it, is this really different from split
?
> moment.utc('1982-05-25').twix(moment.utc('1982-05-27'), true).split(1, 'day').map(function(t){return t.start().format('YYYY-MM-DD');});
[ '1982-05-25', '1982-05-26', '1982-05-27' ]
@icambron Hmm, don't know, didn't think about split
. I think that with toArray
it's kinda easier to put range into array.
I'm going to leave it in. Releasing as 1.1.2
Hi! I was using Twix on previous project and I think that's pretty useful to have
twix.toArray()
helper function.If you like it I am happy to write some text about it in documentation. Usage is very simple, it has 4 arguments, first one is format of the moment object that will be in array, other 3 are same as
iterate
function.Example:
moment.utc('1982-05-25').twix(moment.utc('1982-05-27'), allDay: true).toArray('YYYY-MM-DD', 'days')
Output:['1982-05-25', '1982-05-26', '1982-05-27']