GithubHelp home page GithubHelp logo

ronderksen / mockdate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from boblauer/mockdate

0.0 1.0 0.0 65 KB

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

License: MIT License

JavaScript 99.86% HTML 0.14%

mockdate's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.