Skip to content

Commit

Permalink
[FABN-838] update BlockDecoder.timeStampToDate()
Browse files Browse the repository at this point in the history
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
zhaochy1990 committed Aug 8, 2018
1 parent 8e9c3d8 commit 3b187e4
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion fabric-client/lib/BlockDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ function timeStampToDate(time_stamp) {
const millis = time_stamp.seconds * 1000 + time_stamp.nanos / 1000000;
const date = new Date(millis);

return date.toString();
return date.toISOString();
}

function decodeChaincodeActionPayload(payload_bytes) {
Expand Down
31 changes: 31 additions & 0 deletions fabric-client/test/BlockDecoder.js
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());
});
});
});

0 comments on commit 3b187e4

Please sign in to comment.