Conversion
Purpose¶
A general purpose conversion utilities.
Methods¶
Binding name: p6.conversion
getBytesFromUUID¶
Convert an UUID to a byte array.
Syntax
byte[] p6.conversion.getBytesFromUUID(UUID uuid)
Example
// Convert a transaction UUID to bytes for binary storage
def transactionId = UUID.randomUUID()
def bytes = p6.conversion.getBytesFromUUID(transactionId)
p6.log.debug 'UUID as bytes: ' + bytes.length + ' bytes'
getUUIDFromBytes¶
Convert a byte array to an UUID.
Syntax
UUID p6.conversion.getUUIDFromBytes(byte[] bytes)
Example
// Restore a UUID from its binary representation
def transactionId = p6.conversion.getUUIDFromBytes(storedBytes)
p6.log.debug 'Restored UUID: ' + transactionId.toString()
bigIntegerToZDT¶
Convert an epoch (in millisec) to a date time.
Syntax
ZonedDateTime p6.conversion.bigIntegerToZDT(BigInteger epoch)
Example
// Convert an epoch timestamp from an EDI message to a date
def epoch = 1550160528000
def invoiceDate = p6.conversion.bigIntegerToZDT(epoch)
p6.log.debug 'Invoice date: ' + invoiceDate.toString()
zdtToBigInteger¶
Convert a date time to epoch (in millisec).
Syntax
BigInteger p6.conversion.zdtToBigInteger(ZonedDateTime zdt)
Example
// Convert the current date to epoch for use in an EDI envelope
def now = java.time.ZonedDateTime.now()
def epoch = p6.conversion.zdtToBigInteger(now)
p6.log.debug 'Current epoch: ' + epoch