SOAP4R SOAPDateTime format based on GMT

109 Views Asked by At

App uses SOAP4r for consuming API/SOAP

But SOAP::SOAPTimeFormat is returning 2015-11-15T16:59:521468.7999999999999545-04:00

chkout.add('purchasedDt ', SOAP::SOAPDateTime.new(basket.purchase_Date))

Using strftime('%Y-%m-%dT%H:%M:%S') is giving the following

chkout.add('purchasedDt ', SOAP::SOAPDateTime.new(basket.purchase_Date.strftime('%Y-%m-%dT%H:%M:%S')))

2015-11-15T16:59:52Z

What App needs is
2015-11-15 16:59:52 -0400 Please advise ...need the format in yyyy-mm-ddThh:mm:ss-/+gmt

-Fransis

2

There are 2 best solutions below

0
Thomas R. Koll On

A simple change in your strftime and you can find out more in the doc for Time#strftime

basket.purchase_Date.now.strftime('%Y-%m-%d %H:%M %z')
=> "2016-04-26 22:48 -0400"
2
spickermann On

Seems like your applicaton accepts the iso8601 format. You can use Time#xmlschema as a shortcut to generate iso8601 compatible strings:

basket.purchase_Date.xmlschema
#=> "2015-11-15T16:59:52-04:00"

Just change this line in your example:

chkout.add('purchasedDt ', SOAP::SOAPDateTime.new(basket.purchase_Date.xmlschema))