fix cached timestamps, closes #63

This commit is contained in:
Sami Samhuri 2015-05-29 17:45:20 -07:00
parent a213d716a6
commit 93326a4d73
2 changed files with 22 additions and 0 deletions

View file

@ -169,6 +169,9 @@
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
}
}
else {
timestamp = _cachedDateTimestamp;
}
date = _cachedDate;
}
else {

19
test.js
View file

@ -195,6 +195,25 @@ assert.formatTZ('%F %r %z', '2011-06-07 11:21:45 AM -0730', '-0730');
assert.formatTZ('%F %r %:z', '2011-06-07 11:21:45 AM -07:30', '-0730');
ok('Time zone offset');
/// caching
(function() {
// this test fails when the 2 calls cross a millisecond boundary, so try a number of times
var CacheAttempts = 10;
var MaxFailures = 1;
var failures = 0;
for (var i = 0; i < CacheAttempts; ++i) {
var expectedMillis = strftime('%L');
var millis = strftime('%L');
if (expectedMillis != millis) {
++failures;
}
}
if (failures > MaxFailures) {
assert.fail('timestamp caching appears to be broken (' + failures + ' failed attempts out of ' + CacheAttempts + ')');
}
}());
ok('Cached timestamps');
/// helpers