0
votes

I am stuck with a problem and hope to find somebody with a working solution.

The code (below) it working perfect in my JS-View. It retrieves the time from the sap netweaver gateway and displays it in the textview of a table. The source pattern needs to be exately like this in the js-view: pattern: "'PT'hh'H'mm'M'ss'S'" , e.g. PT11H25M16S

JS-View:

        template: new sap.ui.commons.TextView().bindProperty("text", "Uploadtime", new sap.ui.model.type.Time({
            source: {pattern: "'PT'hh'H'mm'M'ss'S'"},  
            pattern: "HH:mm:ss"}))

I am migrating this view to XML-view. Here now comes the problem. The same coding in XML view is not possible due to inverted comma, quotation mark issues.

XML-View:

text = "{path:'Uploadtime',type:'sap.ui.model.type.Time',formatOptions:{ source : { pattern : "'PT'hh'H'mm'M'ss'S'" }, pattern : 'HH:mm:ss'}}"

Unfortunately I have no idea left how to format it correctly to get it working.

A possible workaround would be using a formatter function in the controller. But this should also be possible with type and formatOptions in the xml view.

2

2 Answers

2
votes

The solution of Qualiture actually didn't work for me. In SAP UI5 Version 1.34.9 the following did the trick for me:

{path : 'Uploadtime/ms', type : 'sap.ui.model.type.Time' ,formatOptions:{ source: 
{pattern: 'timestamp'}, pattern : 'HH:mm:ss'}}

UI5 can parse the PT11H25M16S by recognizing it as a timestamp. Another important detail is that the data structure of edm.time has this timestamp in the "ms" sub-property of the actual datastructure, so make sure to include that with the "/ms" addition in the path.

0
votes

Just escape the quotation mark in the period formatter:

text = "{path:'Uploadtime',type:'sap.ui.model.type.Time',formatOptions:{ source : { pattern : '\'PT\'hh\'H\'mm\'M\'ss\'S\'' }, pattern : 'HH:mm:ss'}}"