sap.ui.model.type.Date - 使用样式时值错误 short/medium/long/full

sap.ui.model.type.Date - Wrong value when using style short/medium/long/full

我遇到了一个错误,这似乎是 OpenUI5 中的一个错误。但由于我不是 100% 确定我想检查是否遗漏了什么。

我正在使用 javascript 对象作为 JSONModel 的数据源。此对象具有字符串格式 yyyymmdd 的 "birthday" 属性。我已经将 JSONModel 附加到核心对象,因此它可以在我的应用程序的所有控件中使用。

    obj = { birthday: "19890727" }; // July 27, 1989

    var model = new sap.ui.model.json.JSONModel();
    model.setData(obj);

    sap.ui.getCore().setModel(model);

然后我尝试使用数据绑定,以便可以在 TextView 上显示生日。由于我不想以与模型相同的格式显示此日期,因此我使用类型对象对其进行格式化。

var type_date = new sap.ui.model.type.Date({source: {}});
text_view_birthday.bindProperty("text",{
    path: "/birthday",
    type: type_date
});

以下 Date 对象也很好用:

var type_date = new sap.ui.model.type.Date({
                    source: {
                        pattern: "yyyymmdd"
                    },
                    pattern: "dd - mm - yy"
                });

我在玩 class sap.ui.model.type.Date 并且当我尝试通过 style 使用它时属性及其任何可能的值(short/medium/long/full),显示的日期实际上与模型不同。 UI5 显示的不是七月,而是一月!

var type_date =
        new sap.ui.model.type.Date({
            source: {
                pattern: "yyyymmdd"
            },
            style: "short"
        });
// Short: 1/27/89
// Medium: Jan 27, 1989
// Long: January 27, 1989
// Full: Friday, January 27, 1989

我尝试调试 sap-ui-core-dbg..它超出了我的范围...我没有成功

IMO 有两种可能的情况

  1. 我错误地使用了日期 class(我根据 UI5 Developer Guide 的文档创建了这个代码段,因为模型类型 classes 是 qui很穷)。
  2. 这是一个错误!

查看下面的完整来源。

<!DOCTYPE html>
<meta name="robots" content="noindex">
<html>

<head>
  <script src="https://openui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.ui.commons">
  </script>
  <meta charset="utf-8">
  <title>JS Bin</title>

  <script>
    obj = {
      birthday: "19890727"
    };

    var model = new sap.ui.model.json.JSONModel();
    model.setData(obj);

    sap.ui.getCore().setModel(model);

     // var type_date = new sap.ui.model.type.Date({source: {}}); // Correct: Result is Jul 27, 1989 (in my locale)
     // var type_date = new sap.ui.model.type.Date({
     //     source: {
     //      pattern: "yyyymmdd"
     //     },
     //     pattern: "dd - mm - yy"
     //     }); // Correct: Result is 27 - 07 - 89 (ignore my locale)

    var type_date =
      new sap.ui.model.type.Date({
        source: {
          pattern: "yyyymmdd"
        },
        style: "full"
      });
     // Incorrect!
     // Short: 1/27/89
     // Medium: Jan 27, 1989
     // Long: January 27, 1989
     // Full: Friday, January 27, 1989


    var text_view_birthday = new sap.ui.commons.TextView();

    text_view_birthday.bindProperty("text", {
      path: "/birthday",
      type: type_date
    });

    text_view_birthday.placeAt("content");
  </script>
</head>

<body class="sapUiBody" role="application">
  <div id="content"></div>
</body>

</html>

谢谢!

我不熟悉所有细节,但模式应该是 LDML 格式。月份的模式为 MMM,小写 m 表示分钟。要调试它,您只需在 sap.ui.model.type.Date.

formatValue 中设置一个断点