mirror of
https://github.com/discourse/discourse.git
synced 2024-12-26 15:56:18 +08:00
22 lines
544 B
JavaScript
22 lines
544 B
JavaScript
|
import sinon from "sinon";
|
||
|
|
||
|
const PARIS = "Europe/Paris";
|
||
|
|
||
|
export default function freezeTime({ date, timezone }, cb) {
|
||
|
date = date || "2020-01-22 10:34";
|
||
|
const newTimezone = timezone || PARIS;
|
||
|
const previousZone = moment.tz.guess();
|
||
|
const now = moment.tz(date, newTimezone).valueOf();
|
||
|
|
||
|
sinon.useFakeTimers(now);
|
||
|
sinon.stub(moment.tz, "guess");
|
||
|
moment.tz.guess.returns(newTimezone);
|
||
|
moment.tz.setDefault(newTimezone);
|
||
|
|
||
|
cb();
|
||
|
|
||
|
moment.tz.guess.returns(previousZone);
|
||
|
moment.tz.setDefault(previousZone);
|
||
|
sinon.restore();
|
||
|
}
|