Telerik - RecurrenceRule - TryParse无法正常工作

时间:2014-05-19 04:29:00

标签: kendo-ui telerik recurrence

我正在尝试将重复规则字符串解析为telerik对象,但它根本不适用于我。即使字符串模式似乎正确(从Kendo Recurrence控件传递),结果也始终为null。感谢您对此的任何想法。

enter image description here

更新:我尝试了另一个案例来证明解析是否有效,结果如下:

enter image description here

1 个答案:

答案 0 :(得分:1)

根据此帖http://www.telerik.com/forums/parsing-recurrencerule-server-side重复规则在指定INTERVAL时有效。

  

对于RecurrenceRule.TryParse抛出的异常,我注意到了   它是在缺少INTERVAL规则时引起的。如果你想使用   RecurrenceRule.TryParse方法,您需要手动添加它。

这是最初由jonno上传的修改后的代码

var today = DateTime.Now.Date;
var start = today.AddDays(-14).AddHours(19);
var end = start.AddHours(2.5);

// Create a few recurring events using Kendo Web Scheduler and use the recurrence rules
var patterns = new[]
{
    "FREQ=DAILY;UNTIL=20140227T130000Z", 
    "FREQ=DAILY;INTERVAL=3;UNTIL=20140227T130000Z", 
    "FREQ=DAILY;INTERVAL=3;COUNT=4", 
    "FREQ=DAILY;INTERVAL=5", 
    "FREQ=WEEKLY;BYDAY=WE;INTERVAL=1",
    "FREQ=WEEKLY;COUNT=5;BYDAY=TU,WE;INTERVAL=1",
    "FREQ=WEEKLY;INTERVAL=4;COUNT=5;BYDAY=WE,TH,SA", 
    "FREQ=WEEKLY;INTERVAL=3;UNTIL=20140331T090000Z;BYDAY=WE,TH,SA", 
    "FREQ=MONTHLY;BYMONTHDAY=13;INTERVAL=1", 
    "FREQ=MONTHLY;COUNT=7;BYDAY=1FR;INTERVAL=1", 
    "FREQ=MONTHLY;UNTIL=20150212T130000Z;BYDAY=SU,SA;BYSETPOS=-1;INTERVAL=1",
    "FREQ=YEARLY;BYMONTH=12;BYMONTHDAY=25", 
    "FREQ=YEARLY;COUNT=3;BYMONTH=2;BYMONTHDAY=28", 
    "FREQ=YEARLY;UNTIL=20200306T130000Z;BYMONTH=8;BYDAY=3WE",
    "FREQ=WEEKLY;COUNT=5;BYDAY=MO;INTERVAL=4",
    "FREQ=WEEKLY;COUNT=2;BYDAY=MO;INTERVAL=1",
};

// Now figure out which events will trigger in the next week - server side only - using Telerik.Web.UI.dll RecurrenceRule class.
foreach (var expr in patterns)
{
    var rrule = string.Format("DTSTART:{0:yyyyMMddTHHmmssZ}\r\nDTEND:{1:yyyyMMddTHHmmssZ}\r\nRRULE:{2}", start, end, expr);
    try
    {
        RecurrenceRule recRule = null;
        var b = RecurrenceRule.TryParse(rrule, out recRule);
        if (recRule == null)
        {
            Console.WriteLine("PARSE ERROR: " + expr);
            continue;
        }
    }
    catch (Exception)
    {
        Console.WriteLine("PARSE ERROR: " + expr);
    }
}