Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/will123195/set-now
Adds Date.setNow() to JavaScript's global Date object.
https://github.com/will123195/set-now
Last synced: 10 days ago
JSON representation
Adds Date.setNow() to JavaScript's global Date object.
- Host: GitHub
- URL: https://github.com/will123195/set-now
- Owner: will123195
- Created: 2016-03-18T19:16:30.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-03-22T22:01:09.000Z (almost 9 years ago)
- Last Synced: 2024-10-25T00:28:22.395Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 2
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# set-now
Adds `Date.setNow()` to JavaScript's global `Date` object.
[![Build Status](https://travis-ci.org/will123195/set-now.svg?branch=master)](https://travis-ci.org/will123195/set-now)
This is useful for making tests deterministic. Wind back the clock to a time in the past (or in the future).
## Install
```
npm install set-now
```## Usage
```js
require('set-now')Date.setNow('2016-03-17T12:00:00')
new Date() // Thu Mar 17 2016 08:00:00 GMT-0400 (EDT)
Date.now() // 1458216000000// wait 1 second
setTimeout(function () {
new Date() // Thu Mar 17 2016 08:00:01 GMT-0400 (EDT)
Date.setNow() // reset the time back to normal
new Date() // today's actual date
}, 1000)
```## Date.setNow( [time] )
Set the clock to the specified time.
* `time` {String} (optional) The time you want it to be. If `time` is not specified, the clock will be reset to the actual time.