-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FABN-838] update BlockDecoder.timeStampToDate()
BlockDecoder.timeStampToDate() use Date.toString() which lose the date precision of nanoseconds. FABN-838 #done Change-Id: I4435bfd2bca8bcc5f5a160d654f9a26cd92c52ce Signed-off-by: zhaochy <[email protected]>
- Loading branch information
1 parent
8e9c3d8
commit 3b187e4
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Copyright 2018 IBM All Rights Reserved. | ||
SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
const rewire = require('rewire'); | ||
const BlockDecoderRewire = rewire('../lib/BlockDecoder'); | ||
require('chai').should(); | ||
|
||
describe('BlockDecoder', () => { | ||
describe('timeStampToDate()', () => { | ||
const timeStampToDate = BlockDecoderRewire.__get__('timeStampToDate'); | ||
|
||
it('should return null for empty timestamp', () => { | ||
const res = timeStampToDate(); | ||
res.should.eql('null'); | ||
}); | ||
|
||
it('should return ISO8601 string for a valid timestamp', () => { | ||
const now = new Date(); | ||
const timestamp = { | ||
seconds: Math.floor(now.getTime()/1000), | ||
nanos: now.getMilliseconds() * 1000000 | ||
}; | ||
const res = timeStampToDate(timestamp); | ||
res.should.have.string(now.getMilliseconds().toString()); | ||
}); | ||
}); | ||
}); |