Add method [iCalTrigger asDictionary]
This method is used to get a JSON representation of an alarm trigger.pull/91/head
parent
99af190e29
commit
a22195beec
|
@ -34,6 +34,8 @@
|
||||||
|
|
||||||
- (NSCalendarDate *) nextAlarmDate;
|
- (NSCalendarDate *) nextAlarmDate;
|
||||||
|
|
||||||
|
- (NSDictionary *) asDictionary;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif /* __NGCards_iCalTrigger_H__ */
|
#endif /* __NGCards_iCalTrigger_H__ */
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#import <Foundation/NSCalendarDate.h>
|
#import <Foundation/NSCalendarDate.h>
|
||||||
|
#import <Foundation/NSDictionary.h>
|
||||||
#import <Foundation/NSString.h>
|
#import <Foundation/NSString.h>
|
||||||
|
|
||||||
#import "iCalEvent.h"
|
#import "iCalEvent.h"
|
||||||
|
@ -52,6 +53,75 @@
|
||||||
return [self value: 0 ofAttribute: @"related"];
|
return [self value: 0 ofAttribute: @"related"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSDictionary *) asDictionary
|
||||||
|
{
|
||||||
|
NSDictionary *data;
|
||||||
|
NSString *duration, *relation, *reference, *quantity, *unit;
|
||||||
|
NSUInteger i;
|
||||||
|
unichar c;
|
||||||
|
|
||||||
|
data = nil;
|
||||||
|
if (![[self valueType] length] ||
|
||||||
|
[[self valueType] caseInsensitiveCompare: @"DURATION"] == NSOrderedSame)
|
||||||
|
{
|
||||||
|
relation = [[self relationType] uppercaseString];
|
||||||
|
duration = [self flattenedValuesForKey: @""];
|
||||||
|
i = 0;
|
||||||
|
c = [duration characterAtIndex: i];
|
||||||
|
if (c == '-')
|
||||||
|
{
|
||||||
|
reference = @"BEFORE";
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
reference = @"AFTER";
|
||||||
|
}
|
||||||
|
c = [duration characterAtIndex: i];
|
||||||
|
if (c == 'P')
|
||||||
|
{
|
||||||
|
quantity = @"";
|
||||||
|
unit = @"";
|
||||||
|
// Parse duration -- ignore first character (P)
|
||||||
|
for (i++; i < [duration length]; i++)
|
||||||
|
{
|
||||||
|
c = [duration characterAtIndex: i];
|
||||||
|
if (c == 't' || c == 'T')
|
||||||
|
// time -- ignore character
|
||||||
|
continue;
|
||||||
|
else if (isdigit (c))
|
||||||
|
quantity = [quantity stringByAppendingFormat: @"%c", c];
|
||||||
|
else
|
||||||
|
{
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case 'D': /* day */
|
||||||
|
unit = @"DAYS";
|
||||||
|
break;
|
||||||
|
case 'H': /* hour */
|
||||||
|
unit = @"HOURS";
|
||||||
|
break;
|
||||||
|
case 'M': /* min */
|
||||||
|
unit = @"MINUTES";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
NSLog(@"Cannot process duration unit: '%c'", c);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
data = [NSDictionary dictionaryWithObjectsAndKeys:
|
||||||
|
relation, @"relation",
|
||||||
|
reference, @"reference",
|
||||||
|
quantity, @"quantity",
|
||||||
|
unit, @"unit",
|
||||||
|
nil];
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
- (NSCalendarDate *) nextAlarmDate
|
- (NSCalendarDate *) nextAlarmDate
|
||||||
{
|
{
|
||||||
NSCalendarDate *relationDate, *nextAlarmDate;
|
NSCalendarDate *relationDate, *nextAlarmDate;
|
||||||
|
|
Loading…
Reference in New Issue