plaa / TimeShift-js

Library for mocking JavaScript's Date object
MIT License
65 stars 28 forks source link

Fix an error preventing this lib from working in node.js #9

Closed greim closed 7 years ago

greim commented 7 years ago

In browsers, it's window but in node.js it's global. TimeShift-js fails to assign the latter into the root variable where it looks for root.Date. Thus, if you require('timeshift-js') in Node.js, it errors out when it does:

var OriginalDate = root.Date;
var timezoneOffset = new OriginalDate().getTimezoneOffset();
// OriginalDate is undefined

This PR fixes that, and meanwhile tests continue to pass in Chrome, Firefox and Safari. I've been playing around with it and once that specific issue is fixed, this lib works great in Node.

AndersDJohnson commented 7 years ago

@plaa Any chance of merging and releasing this?

plaa commented 7 years ago

Sorry for the delay, now merged and published.