let realDate = Date

function set(date) {
  const fixed = new realDate(date).getTime()

  class MockDate extends realDate {
    constructor(...args) {
      if (args.length === 0) {
        super(fixed)
      } else {
        super(...args)
      }
    }

    static now() {
      return fixed
    }
  }

  MockDate.UTC = realDate.UTC
  MockDate.parse = realDate.parse
  global.Date = MockDate
}

function reset() {
  global.Date = realDate
}

module.exports = { set, reset }
