在我正在开发的应用程序中有一个Google集成。RRULE字符串用于描述它们的递归行为的重复事件。
(例如RRULE:FREQ=DAILY;WKST=SU;UNTIL=20211215T215959Z;INTERVAL=3) )
我需要在应用程序中验证一些DateTime,这样它们就不会与这些事件相交。就复杂性而言,最有效的方法是什么?
发布于 2021-11-12 16:48:16
如果该RRULE的格式是常量的,只需:
创建Dictionary<string, string>的
循环中的
实际的代码应该非常简单。
// NOTE: This rules parsing code could/should make it into a separate function, this is just some quick coding
string[] rulesParts = myVariable.Substring(myVariable.Indexof(':') + 1).Split(';');
Dictionary<string, string> rrules = new Dictionary<string, string>();
foreach(string rulePart in rulesParts)
{
string[] nameAndValue = rulePart.Split(';');
string ruleName = nameAndValue[0];
string ruleValue = nameAndValue[1];
if (!rulesParts.ContainsKey(ruleName))
{
rrules.Add(ruleName, ruleValue);
}
}
if (rrules.ContainsKey("UNTIL"))
{
// Do a DateTime.TryParseExact of rrules["UNTIL"] and work with your DateTime variable as you like
}https://stackoverflow.com/questions/69945906
复制相似问题