Skip to content
/ MockDate Public
forked from boblauer/MockDate

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

License

Notifications You must be signed in to change notification settings

spmjs/MockDate

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MockDate

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

Build Status

Installation

npm install mockdate

Environment Support

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

Usage

// CommonJS
var MockDate = require('mockdate');
// AMD
require(['MockDate'], function(MockDate) { ... });
// Script Tag
var MockDate = window.MockDate;

API

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 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().

MockDate.reset();

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

Example

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

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

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

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

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

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

MockDate.reset();

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

Test

npm test

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%