How to use timezone-mock - 10 common examples

To help you get started, we’ve selected a few timezone-mock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github decred / decrediton / test / unit / helpers / date.spec.js View on Github external
test("dateToLocal works as expected", () => {
  tzmock.register("UTC");

  expect(localTime(dateToLocal(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
  expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
  expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);

  tzmock.register("Brazil/East");

  expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 21, 0, 0, 0 ]);
  expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 17, 20, 38, 0 ]);
  expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 18, 20, 38, 0 ]); // DST on

  tzmock.register("US/Pacific");

  expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 16, 0, 0, 0 ]);
  expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 13, 20, 38, 0 ]); // DST on
  expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 12, 20, 38, 0 ]);

});
github decred / decrediton / test / unit / helpers / date.spec.js View on Github external
test("dateToLocal works as expected", () => {
  tzmock.register("UTC");

  expect(localTime(dateToLocal(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
  expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
  expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);

  tzmock.register("Brazil/East");

  expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 21, 0, 0, 0 ]);
  expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 17, 20, 38, 0 ]);
  expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 18, 20, 38, 0 ]); // DST on

  tzmock.register("US/Pacific");

  expect(localTime(dateToLocal(0))).toEqual([ 1969, 12, 31, 16, 0, 0, 0 ]);
  expect(localTime(dateToLocal(1539980438))).toEqual([ 2018, 10, 19, 13, 20, 38, 0 ]); // DST on
  expect(localTime(dateToLocal(1541708438))).toEqual([ 2018, 11, 8, 12, 20, 38, 0 ]);

});
github gitlabhq / gitlabhq / spec / frontend / vue_shared / components / time_ago_tooltip_spec.js View on Github external
beforeEach(() => {
        timezoneMock.register(timezone);
        // Date object with mocked TZ
        tzDate = new Date();
        buildVm({ time: date.getTime() });
      });
github kleros / doges-on-trial / src / setupTests.js View on Github external
// Configure
configure({ adapter: new Adapter() })

// Mock Modules
jest.mock('./components/identicon', () =&gt; () =&gt; <div>[Identicon]</div>)

// Mock Globals
Date.now = jest.fn(() =&gt; 1516916214006)
global.localStorage = {
  getItem() {},
  setItem() {}
}

// Mock Time
timezoneMock.register('UTC')
github decred / decrediton / test / unit / helpers / date.spec.js View on Github external
test("dateToUtc works as expected", () => {
  tzmock.register("UTC");

  expect(localTime(dateToUTC(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
  expect(localTime(dateToUTC(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
  expect(localTime(dateToUTC(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);

  tzmock.register("Brazil/East");

  expect(localTime(dateToUTC(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
  expect(localTime(dateToUTC(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
  expect(localTime(dateToUTC(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);

  tzmock.register("US/Pacific");

  expect(localTime(dateToUTC(0))).toEqual([ 1970, 1, 1, 0, 0, 0, 0 ]);
  expect(localTime(dateToUTC(1539980438))).toEqual([ 2018, 10, 19, 20, 20, 38, 0 ]);
  expect(localTime(dateToUTC(1541708438))).toEqual([ 2018, 11, 8, 20, 20, 38, 0 ]);
github mysqljs / mysql / test / integration / connection / test-timezones.js View on Github external
function registerMock() {
  timezone_mock.register('US/Pacific');
  var date = new Date(Date.now());
  var tzo = date.getTimezoneOffset();
  assert.ok(tzo === 420 || tzo === 480);
}

timezone-mock

A JavaScript library to mock the local timezone.

MIT
Latest version published 2 years ago

Package Health Score

56 / 100
Full package analysis

Popular timezone-mock functions