Search code examples
datetimehyperledger-fabrichyperledgerdatetime-formathyperledger-composer

Specify only Time in DateTime field (ISO-8601) in Hyperledger


I'm working on Hyperledger Composer Playground and want to specify only time in DateTime field skipping the Date completely. But whenever I try to create the asset, everytime I'm getting RangeError: Invalid time value error.

I tried giving default value to the variable in model file in some varieties of the following example but doesn't work either.

o DateTime dispatchTime default = "T06:18:42.716Z"

I must be missing some obvious thing in this as it is a ISO-8601 standard format but couldn't find exact solution to get it working specifically in Hyperledger Composer. Thanks in advance.


Solution

  • You are getting invalid time error because you can not store just time in your dispatchTime variable as it is an ISO-8601 Date-Time format. You can check it

    But then also, if you want to store only time, you can convert it in one of the transaction processor functions in your logic.js file as follows:

    tx.assetObject.dispatchTime = new Date().toISOString().split(/T/)[1];

    Hope it helps!