[Core] Add 'now' service

Add a service to wrap Date.now(), such that this can be injected
(simplifying testing of scripts which need to respond to system
time.) Specifically supports staleness indication, WTD-660.
This commit is contained in:
Victor Woeltjen
2015-01-23 14:19:53 -08:00
parent 5c34382933
commit 310006f832
4 changed files with 63 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Defines the `now` service, which is a simple wrapper upon
* `Date.now()` which can be injected to support testability.
*
* @returns {Function} a function which returns current system time
*/
function Now() {
/**
* Get the current time.
* @returns {number} current time, in milliseconds since
* 1970-01-01 00:00:00Z
*/
return function () {
return Date.now();
};
}
return Now;
}
);