簡體   English   中英

使用EKRecurrenceRule計算上一個或下一個日期

[英]Compute previous or next date with EKRecurrenceRule

我想從偏移量NSDateEKRecurrenceRule計算上一個日期或下一個日期。 像這樣:

NSDate* prevDate = [Something computePreviousDateForOffsetDate: aDate 
                                            withRecurrenceRule: aRule];

NSDate* nextDate = [Something computeNextDateForOffsetDate: aDate
                                        withRecurrenceRule: aRule];

我可以用簡單的重復規則創建Something ,但是復雜的規則對我來說有點困難。 我認為這是非常常見的事情,所以我問了一下。

我是否需要花費時間來實施自己的解決方案?

在使用EKRecurrenceRule浪費了一些時間之后,我找到了ios-rrule_parser的替代解決方案。 它最容易使用,可以滿足我的所有需求。

對於nextDate,請使用以下命令:

NSDate *startDate = [NSDate date];
NSDate *endDate = [startDate dateByAddingTimeInterval:100 *24 *60 *60];

Scheduler * scheduler = [[Scheduler alloc] initWithDate:startDate andRule:@"RRULE:FREQ=DAILY;COUNT=1;INTERVAL=2"];
NSArray *occurences = [scheduler occurencesBetween:startDate andDate:endDate];

NSDate *nextDate = [occurences objectAtIndex:0];

對於previousDate,只需更改startDate。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM