Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array.from(moment(from).twix(to)).iterate("days")) == [] #104

Open
tobybrad opened this issue Feb 27, 2018 · 1 comment
Open

Array.from(moment(from).twix(to)).iterate("days")) == [] #104

tobybrad opened this issue Feb 27, 2018 · 1 comment

Comments

@tobybrad
Copy link

Hey,

I now know about toArray() but I got caught out today when iterate() didn't return an iterable suitable for Array.from()

@home:~/src$ cat test.js
const moment = require("moment")
const twix = require("./lib/twix.min.js")

let start = new Date("2018-01-01");
let end = new Date("2018-06-01");

console.log(moment(start).twix(end).toArray("days").length);
console.log(Array.from(moment(start).twix(end).iterate("days")).length);
console.log(Array.from(moment(start).twix(end).iterate("days")));
@home:~/src$ node test.js
152
0
[]

Array.from() should expand the iterable:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/from

so I guess the object returned from iterate is not truly 'iterable' in the way required by the spec.

Nice library though.. saved me a bunch of time elsewhere so I'm still net positive on time-savings thanks to twix. :-)

@icambron
Copy link
Owner

Yeah, the iterable does not actually implement the Iterable protocol (and predates its implementation, IIRC). It could though! I'd take a PR making that true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants