当前位置:网站首页>SAP ui5 date type sap ui. model. type. Analysis of date parsing format

SAP ui5 date type sap ui. model. type. Analysis of date parsing format

2022-06-25 05:45:00 JerryWang_ WangZiXi

I developed a SAP UI5 application , Data type used sap.ui.model.type.Date, And specify the display format pattern by :yyyy-MM-ddTHH:mm:ss

<ObjectAttribute title="{i18n>dateTitle}" text="{
                    path: 'invoice>ShippedDate',
                    type: 'sap.ui.model.type.Date',
                    formatOptions: {
                      style: 'long',
                      source: {
                        pattern: 'yyyy-MM-ddTHH:mm:ss'
                      }
                    }
                  }"/>

The value of the data source bound to this field is :2015-04-01T01:20:59

I look forward to SAP UI5 The format displayed on the is One year - a certain month - One day -T- Hours - branch - second , But the final display effect is shown in the figure below :April 1,2015

This article introduces how to analyze the problem of this display format .

We are Chrome Found in the developer tool sap.ui.model.type.Date Implementation file address of :

sap/ui/model/type/Date.js

First, in the function Date1.prototype.formatValue To set breakpoints , Observe the original value of string type , The function has been successfully passed in :

sInternalType Value :string

string Type of PrimitiveType The value is itself .

The logic is defined in the following functions :

SimpleType.prototype.getPrimitiveType = function (sInternalType) {
        // Avoid dealing with type objects, unless really necessary
        switch (sInternalType) {
            case "any":
            case "boolean":
            case "int":
            case "float":
            case "string":
            case "object":
                return sInternalType;
            default:
                var oInternalType = DataType.getType(sInternalType);
                return oInternalType && oInternalType.getPrimitiveType().getName();
        }
    };

Get the template of format data from the model :

For example, the abbreviation of seven days a week , Stored in aDaysAbbrev in :

A year 12 Months of words , Stored in aMonthsWide in :

Get into parse Internal function ,Calendar type by :Gregorian, intend The solar calendar .

Calendar type For enumeration value , All those who support calendar The type is shown in the figure below :

Format the value of the array :aFormatArray

Has successfully resolved 2015 year 4 month 2 The day :

Start parsing :T01:20:30

All possible Date separator

\u002d\u007E\u2010\u2011\u2012\u2013\u2014\ufe58\ufe63\uff0d\uFF5E

stay Dateformat.js Functional _parse The return value of the function , It has been observed for hours , Minutes and seconds have been successfully resolved . So the problem is not parsing , But in the display of values .

Last returned value :Thu Apr 02 2015 01:20:30 GMT+0800 (China Standard Time

more Jerry The original article of , All in :" Wang Zixi ":

原网站

版权声明
本文为[JerryWang_ WangZiXi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202201825108251.html