如果要将 TimeSpan/DayTime 字符串用于 SecurityValidatio 类的方法,请使用下面的代码在本地测试 Dotcom-Monitor 是否可以正确分析字符串格式。

private static string[] TimeSpanFormats = new string[] { "c", "g", "G", "d", "d\.hh" };
private static string[] DateTimeFormats = new string[] { "d", "D", "f", "F", "g", "G", "yy/MM/dd", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss" };
private TimeSpan parseTimeSpan(string value)
{
TimeSpan result = TimeSpan.Zero;
bool res = TimeSpan.TryParse(value, out result);
if (!res)
res = TimeSpan.TryParseExact(value, TimeSpanFormats, null, out result);

return result;
}
private DateTime parseDateTime(string value)
{
DateTime date = DateTime.MinValue;
bool res = DateTime.TryParse(value, out date);
if (!res)
{
DateTime.TryParseExact(value, DateTimeFormats, null, System.Globalization.DateTimeStyles.None, out date);
}
return date;
}