diff --git a/main/SS/UserModel/DateUtil.cs b/main/SS/UserModel/DateUtil.cs index a9b0a3580..928191cfa 100644 --- a/main/SS/UserModel/DateUtil.cs +++ b/main/SS/UserModel/DateUtil.cs @@ -50,11 +50,15 @@ public class DateUtil private static Regex date_ptrn1 = new Regex("^\\[\\$\\-.*?\\]", RegexOptions.Compiled); private static Regex date_ptrn2 = new Regex("^\\[[a-zA-Z]+\\]", RegexOptions.Compiled); private static Regex date_ptrn3a = new Regex("[yYmMdDhHsS]", RegexOptions.Compiled); - private static Regex date_ptrn3b = new Regex("^[\\[\\]yYmMdDhHsS\\-T/,. :\"\\\\]+0*[ampAMP/]*$", RegexOptions.Compiled); + // add "\u5e74 \u6708 \u65e5"(年月日) for Chinese/Japanese date format:2017年2月7日 + private static Regex date_ptrn3b = new Regex("^[\\[\\]yYmMdDhHsS\\-T/\u5e74\u6708\u65e5,. :\"\\\\]+0*[ampAMP/]*$", RegexOptions.Compiled); + // elapsed time patterns: [h],[m] and [s] //private static Regex date_ptrn4 = new Regex("^\\[([hH]+|[mM]+|[sS]+)\\]", RegexOptions.Compiled); private static Regex date_ptrn4 = new Regex("^\\[([hH]+|[mM]+|[sS]+)\\]$", RegexOptions.Compiled); + // for format which start with "[DBNum1]" or "[DBNum2]" or "[DBNum3]" could be a Chinese date + private static Regex date_ptrn5 = new Regex("^\\[DBNum(1|2|3)\\]", RegexOptions.Compiled); /// /// Given a Calendar, return the number of days since 1899/12/31. @@ -672,6 +676,10 @@ public static bool IsADateFormat(int formatIndex, String formatString) return true; } + // If it starts with [DBNum1] or [DBNum2] or [DBNum3] + // then it could be a Chinese date + fs = date_ptrn5.Replace(fs, ""); + // If it starts with [$-...], then could be a date, but // who knows what that starting bit Is all about //fs = Regex.Replace(fs, "^\\[\\$\\-.*?\\]", ""); diff --git a/testcases/main/SS/UserModel/TestDateUtil.cs b/testcases/main/SS/UserModel/TestDateUtil.cs index e3f31579b..daae4abee 100644 --- a/testcases/main/SS/UserModel/TestDateUtil.cs +++ b/testcases/main/SS/UserModel/TestDateUtil.cs @@ -159,5 +159,36 @@ public void GetJavaCalendar_ValidValue() Assert.AreEqual(expCal, actCal[2]); Assert.AreEqual(expCal, actCal[3]); } + + [Test] + public void IsADateFormat() + { + // Cell content 2016-12-8 as an example + // Cell show "12/8/2016" + Assert.IsTrue(DateUtil.IsADateFormat(14, "m/d/yy")); + // Cell show "Thursday, December 8, 2016" + Assert.IsTrue(DateUtil.IsADateFormat(182, "[$-F800]dddd\\,\\ mmmm\\ dd\\,\\ yyyy")); + // Cell show "12/8" + Assert.IsTrue(DateUtil.IsADateFormat(183, "m/d;@")); + // Cell show "12/08/16" + Assert.IsTrue(DateUtil.IsADateFormat(184, "mm/dd/yy;@")); + // Cell show "8-Dec-16" + Assert.IsTrue(DateUtil.IsADateFormat(185, "[$-409]d\\-mmm\\-yy;@")); + // Cell show "D-16" + Assert.IsTrue(DateUtil.IsADateFormat(186, "[$-409]mmmmm\\-yy;@")); + + // Cell show "2016骞12鏈8鏃" + Assert.IsTrue(DateUtil.IsADateFormat(165, "yyyy\"骞碶"m\"鏈圽"d\"鏃";@")); + // Cell show "2016骞12鏈" + Assert.IsTrue(DateUtil.IsADateFormat(164, "yyyy\"骞碶"m\"鏈圽";@")); + // Cell show "12鏈8鏃" + Assert.IsTrue(DateUtil.IsADateFormat(168, "m\"鏈圽"d\"鏃";@")); + // Cell show "鍗佷簩鏈堝叓鏃" + Assert.IsTrue(DateUtil.IsADateFormat(181, "[DBNum1][$-404]m\"鏈圽"d\"鏃";@")); + // Cell show "璐伴浂澹归檰骞村9鎷捐窗鏈堟崒鏃" + Assert.IsTrue(DateUtil.IsADateFormat(177, "[DBNum2][$-804]yyyy\"骞碶"m\"鏈圽"d\"鏃";@")); + // Cell show "锛掞紣锛戯紪骞达紤锛掓湀锛樻棩" + Assert.IsTrue(DateUtil.IsADateFormat(178, "[DBNum3][$-804]yyyy\"骞碶"m\"鏈圽"d\"鏃";@")); + } } }