mirror of
https://github.com/samsonjs/strftime.git
synced 2026-03-25 09:05:48 +00:00
fix cached timestamps, closes #63
This commit is contained in:
parent
a213d716a6
commit
93326a4d73
2 changed files with 22 additions and 0 deletions
|
|
@ -169,6 +169,9 @@
|
|||
_cachedDate = new Date(_cachedDateTimestamp + getTimestampToUtcOffsetFor(_cachedDate) + _customTimezoneOffset);
|
||||
}
|
||||
}
|
||||
else {
|
||||
timestamp = _cachedDateTimestamp;
|
||||
}
|
||||
date = _cachedDate;
|
||||
}
|
||||
else {
|
||||
|
|
|
|||
19
test.js
19
test.js
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue