# mockdate

> A JavaScript mock Date object that can be used to change when "now" is.

Latest version **3.0.5** (published 2021-03-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install mockdate
pnpm add mockdate
yarn add mockdate
bun add mockdate
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 3.0.5 |
| Published | 2021-03-25 |
| First published | 2014-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 679 |
| Author | Bob Lauer |
| Maintainers | boblauer |
| Keywords | date, mock, test |

## Links

- npm: https://www.npmjs.com/package/mockdate
- Repository: https://github.com/boblauer/MockDate
- Issues: https://github.com/boblauer/MockDate/issues
- npm.io page: https://npm.io/package/mockdate

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [vest](https://npm.io/package/vest.md) — 50.1K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads

## Recent versions

- 3.0.5 (latest) — 2021-03-25
- 3.0.4 — 2021-03-18
- 3.0.3 — 2021-03-15
- 3.0.2 — 2020-05-21
- 3.0.1 — 2020-05-21
- 3.0.0 — 2020-05-20
- 2.0.5 — 2019-08-09
- 2.0.4 — 2019-07-31
- 2.0.3 — 2019-06-14
- 2.0.2 — 2017-08-17
- 2.0.1 — 2016-11-22
- 2.0.0 — 2016-10-31
- 1.0.4 — 2016-02-02
- 1.0.3 — 2015-04-20
- 1.0.2 — 2015-04-06
- … 4 more at https://npm.io/package/mockdate/versions

## README

MockDate
========

A JavaScript Mock Date object that can be used to change when "now" is.

[![Build Status](https://travis-ci.org/boblauer/MockDate.png)](https://travis-ci.org/boblauer/MockDate)

## Installation ##
`npm install mockdate --save-dev`

## Environment Support ##
MockDate has been tested in Node, IE9+, Chrome, Firefox, and Opera.

## Usage ##
```javascript
import MockDate from 'mockdate'
```

## API ##
```javascript;
MockDate.set(date)
```

#### __date__

__date__: __`Object`__

The `Date` to be returned when no parameters are passed to `new Date()`.  Supports any object that has a `.valueOf` method that returns a value that can be passed to `new Date()`.

__date__: __`String`__

The string representation of the date which is passed to the `new Date()` constructor. This creates the `Date` to be returned when no parameters are passed to `new Date()`.

__date__: __`Number`__

The millisecond representation of the `Date` to be returned when no parameters are passed to `new Date()`.

```javascript
MockDate.reset();
```

Will restore the original `Date` object back to the native implementation.

## Example ##
```javascript
MockDate.set('2000-11-22');

new Date().toString() // "Tue Nov 21 2000 18:00:00 GMT-0600 (CST)"

MockDate.set('1/30/2000');

new Date().toString() // "Sun Jan 30 2000 00:00:00 GMT-0600 (CST)"

MockDate.set(new Date('2/20/2000'));

new Date().toString() // "Sun Feb 20 2000 00:00:00 GMT-0600 (CST)"

MockDate.set(moment('3/30/2000').toDate()); // using momentjs

new Date().toString() // "Thu Mar 30 2000 00:00:00 GMT-0600 (CST)"

MockDate.reset();

new Date().toString() // "Mon Mar 17 2014 18:08:44 GMT-0500 (CDT)"
```

## Test ##
```javascript
npm test
```

---
_Source: https://npm.io/package/mockdate · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
