Created by Wang, Jerry, last modified on Oct 27, 2015
test("parse with fallback patterns", function(){
var oLocaleEN = new sap.ui.core.Locale("en_US"),
oLocaleDE = new sap.ui.core.Locale("de_DE"),
oFormat,
iCompare = new Date(1975, 3, 16).getTime();
oFormat = sap.ui.core.format.DateFormat.getDateInstance({style: "long"}, oLocaleEN);
equal(oFormat.parse("April 16, 1975").getTime(), iCompare, "Parse long style");
equal(oFormat.parse("Apr 16, 1975").getTime(), iCompare, "Parse fallback medium style");
equal(oFormat.parse("4/16/75").getTime(), iCompare, "Parse fallback short style");
equal(oFormat.parse("04161975").getTime(), iCompare, "Parse fallback without separators");
equal(oFormat.parse("041675").getTime(), iCompare, "Parse fallback without separators, short year");
equal(oFormat.parse("1975-04-16").getTime(), iCompare, "Parse fallback ISO");
equal(oFormat.parse("19750416").getTime(), iCompare, "Parse fallback ABAP");
oFormat = sap.ui.core.format.DateFormat.getDateInstance({style: "long", calendarType: sap.ui.core.CalendarType.Islamic}, oLocaleEN);
equal(oFormat.parse("Rabiʻ II 4, 1395 AH").getTime(), iCompare, "Parse long style");
equal(oFormat.parse("Rab. II 4, 1395 AH").getTime(), iCompare, "Parse fallback medium style");
equal(oFormat.parse("4/4/1395 AH").getTime(), iCompare, "Parse fallback short style");
equal(oFormat.parse("04041395").getTime(), iCompare, "Parse fallback without separators");
equal(oFormat.parse("040495").getTime(), iCompare, "Parse fallback without separators, short year");
equal(oFormat.parse("1395-04-04").getTime(), iCompare, "Parse fallback ISO");
equal(oFormat.parse("13950404").getTime(), iCompare, "Parse fallback ABAP");
oFormat = sap.ui.core.format.DateFormat.getDateInstance({style: "long"}, oLocaleDE);
equal(oFormat.parse("16. April 1975").getTime(), iCompare, "Parse long style");
equal(oFormat.parse("16.4.1975").getTime(), iCompare, "Parse fallback medium style");
equal(oFormat.parse("16.4.75").getTime(), iCompare, "Parse fallback short style");
equal(oFormat.parse("16041975").getTime(), iCompare, "Parse fallback without separators");
equal(oFormat.parse("160475").getTime(), iCompare, "Parse fallback without separators, short year");
equal(oFormat.parse("1975-04-16").getTime(), iCompare, "Parse fallback ISO");
equal(oFormat.parse("19750416").getTime(), iCompare, "Parse fallback ABAP");
});
```要获取更多Jerry的原创文章,请关注公众号"汪子熙":
<img src="https://user-images.githubusercontent.com/5669954/61616089-2a87e180-ac9a-11e9-861d-c29c2cf897af.png">