Does twix work with moment-timezone
ozum opened this issue · 7 comments
Hello,
I'm currently using moment-timezone, and cannot get twix work with it. Did I miss something, or twix does not work with moment-timezone?
var moment = require('moment-timezone');
require('twix');
var a = moment("1982-05-25 05:00:00").twix("1982-05-25 06:00:00").count("days");
console.log(a);
When I run code above I get:
var a = moment("1982-05-25 05:00:00").twix("1982-05-25 06:00:00").count("days"
^
TypeError: undefined is not a function
I certainly expect it to work. What environment are you running this in (a browser, Node, etc?)
node.js v0.12.0 on OS X 10.10.3.
moment-timezone v0.4.0
moment v2.10.3
twix v0.6.4
I'm unable to reproduce this:
> var moment = require("moment-timezone");
undefined
> require("twix")
//stuff omitted
> moment("1982-05-25 05:00:00").twix("1982-05-25 06:00:00").count("days")
1
My versions are slightly different:
- moment 2.10.6
- moment-timezone 0.4.0
- Twix 0.6.5 (no changes relevant changes here)
- Node v0.12.4
I'm not sure how to proceed from here, but perhaps try upgrading Node and Moment? It's all I can think of.
Going to go ahead and close this. LMK if you're still having this issue.
function arrayOfDates(start,stop){
//converting a moment object to an ISO string
var startISOFormat = moment(start).toISOString();
var stopISOFormat = moment(stop).toISOString();
console.log(startISOFormat,stopISOFormat);
//converting a string in a moment object
startISOFormat = moment(startISOFormat);
stopISOFormat = moment(stopISOFormat);
console.log(moment(startISOFormat).toISOString(),stopISOFormat.toISOString());
var itr = moment.twix(startISOFormat,stopISOFormat).iterate("days");
var range = [];
while (itr.hasNext()){
console.log(moment(itr.next()).toISOString());
range.push(itr.next())
}
return range
}
the logs:
2016-07-13T00:00:00.000Z 2016-07-14T00:00:00.000Z
2016-07-13T00:00:00.000Z 2016-07-14T00:00:00.000Z
2016-07-12T06:00:00.000Z
When Iterating TWIX shouldn't set a new TMZ.
@smartcris It isn't. You're confusing formatting in UTC with a Moment in UTC mode. It's admittedly a subtle distinction, but just because you passed in a string formatted in UTC doesn't mean Moment now knows that the start of the day is supposed to be midnight UTC instead of midnight local. Fortunately it's an easy fix:
startISOFormat = moment(startISOFormat).utc();
stopISOFormat = moment(stopISOFormat).utc();
Then Twix will know what to do with the date:
2016-06-28T11:46:28.577Z 2016-06-28T11:46:28.579Z
2016-06-28T11:46:28.577Z 2016-06-28T11:46:28.579Z
2016-06-28T00:00:00.000Z
Got it, thank you for the clarification.