Skip to content

Instantly share code, notes, and snippets.

@lambdabaa
Created May 10, 2013 17:46
Show Gist options
  • Save lambdabaa/5556096 to your computer and use it in GitHub Desktop.
Save lambdabaa/5556096 to your computer and use it in GitHub Desktop.
*** BEFORE ***
/**
* @return {number} Amount of time in ms until the end of the hour.
*/
_millisUntilHour: function() {
var date = new Date();
var millis = 1000 * (
60 * (60 - date.getMinutes()) +
(60 - date.getSeconds())
);
return millis;
}
*** AFTER ***
/**
* @return {number} Amount of time in ms until the end of the hour.
*/
_millisUntilHour: function() {
var date = new Date();
var millis = 1000 * (
60 * (59 - date.getMinutes()) +
(60 - date.getSeconds())
);
return millis;
}
};
*** TEST ***
suite('#_millisUntilHour', function() {
var MockDate, millisUntilHour;
var RealDate;
setup(function() {
/** @constructor */
MockDate = function() {};
MockDate.prototype = {
getMinutes: function() {
return 58;
},
getSeconds: function() {
return 30;
}
};
RealDate = window.Date;
window.Date = MockDate;
// By inspection, there are 90000 ms between
// xx:58:30 and the top of the hour
millisUntilHour = 90000;
});
teardown(function() {
window.Date = RealDate;
});
test('should calculate the correct number of ms', function() {
assert.equal(decorator._millisUntilHour(), millisUntilHour);
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment