Skip to content

Commit b95ee4d

Browse files
adding parsing logic
1 parent e7d8376 commit b95ee4d

File tree

8 files changed

+572
-0
lines changed

8 files changed

+572
-0
lines changed

CalendarManager/CalendarEvent.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//
2+
// CalendarEvent.h
3+
// iOSCalendarEventParser
4+
//
5+
// Created by Rajeev Kumar Kallempudi on 2/3/16.
6+
// Copyright © 2016 rajeevprasanna. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface CalendarEvent : NSObject
12+
13+
@property (nonatomic, strong) NSString* uid;
14+
@property (nonatomic, strong) NSString* organiserMailId;
15+
@property (nonatomic, strong) NSString* location;
16+
@property (nonatomic, strong) NSString* subject;
17+
@property (nonatomic, strong) NSString* eventDescription;
18+
@property (nonatomic, strong) NSString* timezoneId;
19+
@property (nonatomic, assign) NSTimeInterval startTime;
20+
@property (nonatomic, assign) NSTimeInterval endTime;
21+
@property (nonatomic, assign) NSTimeInterval lastModifiedTime;
22+
@property (nonatomic, assign) NSTimeInterval creationTime;
23+
@property (nonatomic, strong) NSString* method;
24+
@property (nonatomic, strong) NSInteger userAction;
25+
@property (nonatomic, strong) NSString* icalString;
26+
27+
@end

CalendarManager/CalendarEvent.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//
2+
// CalendarEvent.m
3+
// iOSCalendarEventParser
4+
//
5+
// Created by Rajeev Kumar Kallempudi on 2/3/16.
6+
// Copyright © 2016 rajeevprasanna. All rights reserved.
7+
//
8+
9+
#import "CalendarEvent.h"
10+
11+
@implementation CalendarEvent
12+
13+
@end

CalendarManager/CalendarEventParser.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
//
88

99
#import <Foundation/Foundation.h>
10+
#import "CalendarEvent.h"
1011

1112
@interface CalendarEventParser : NSObject
1213

14+
+(void)parseCalendar:(NSString *)icalEventString :(void (^)(CalendarEvent *))successBlock withErrorBlock:(void (^)(NSDictionary*))errorBlock;
15+
1316
@end

CalendarManager/CalendarEventParser.m

Lines changed: 312 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// CalendarEventParserConstants.h
3+
// iOSCalendarEventParser
4+
//
5+
// Created by Rajeev Kumar Kallempudi on 2/3/16.
6+
// Copyright © 2016 rajeevprasanna. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
12+
#define CALENDAR_EVENT_STATUS_NONE 0
13+
#define CALENDAR_EVENT_STATUS_CONFIRMED 1
14+
#define CALENDAR_EVENT_STATUS_TENTATIVE 2
15+
#define CALENDAR_EVENT_STATUS_DECLINED 3
16+
#define CALENDAR_EVENT_STATUS_CANCELLED 4
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// CalendarEventTimeZones.h
3+
// iOSCalendarEventParser
4+
//
5+
// Created by Rajeev Kumar Kallempudi on 2/3/16.
6+
// Copyright © 2016 rajeevprasanna. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface CalendarEventTimeZones : NSObject
12+
13+
+(NSTimeZone *)getTimezoneById:(NSString *)timezoneId;
14+
15+
@end
Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
//
2+
// CalendarEventTimeZones.m
3+
// iOSCalendarEventParser
4+
//
5+
// Created by Rajeev Kumar Kallempudi on 2/3/16.
6+
// Copyright © 2016 rajeevprasanna. All rights reserved.
7+
//
8+
9+
#import "CalendarEventTimeZones.h"
10+
11+
@implementation CalendarEventTimeZones
12+
13+
+(NSTimeZone *)getTimezoneById:(NSString *)timezoneId
14+
{
15+
static NSDictionary *timeZoneMap = nil;
16+
static dispatch_once_t onceToken;
17+
dispatch_once(&onceToken, ^{
18+
timeZoneMap = @{
19+
@"Pacific Standard Time" : @"America/Los_Angeles",
20+
@"Chennai, Kolkata, Mumbai, New Delhi" : @"Asia/Kolkata",
21+
@"International Date Line West" : @"Pacific/Midway",
22+
@"Midway Island" : @"Pacific/Midway",
23+
@"American Samoa" : @"Pacific/Pago_Pago",
24+
@"Hawaii" : @"Pacific/Honolulu",
25+
@"Alaska" : @"America/Juneau",
26+
@"Pacific Time (US & Canada)" : @"America/Los_Angeles",
27+
@"Tijuana" : @"America/Tijuana",
28+
@"Mountain Time (US & Canada)" : @"America/Denver",
29+
@"Arizona" : @"America/Phoenix",
30+
@"Chihuahua" : @"America/Chihuahua",
31+
@"Mazatlan" : @"America/Mazatlan",
32+
@"Central Time (US & Canada)" : @"America/Chicago",
33+
@"Saskatchewan" : @"America/Regina",
34+
@"Guadalajara" : @"America/Mexico_City",
35+
@"Mexico City" : @"America/Mexico_City",
36+
@"Monterrey" : @"America/Monterrey",
37+
@"Central America" : @"America/Guatemala",
38+
@"Eastern Time (US & Canada)" : @"America/New_York",
39+
@"Indiana (East)" : @"America/Indiana/Indianapolis",
40+
@"Bogota" : @"America/Bogota",
41+
@"Lima" : @"America/Lima",
42+
@"Quito" : @"America/Lima",
43+
@"Atlantic Time (Canada)" : @"America/Halifax",
44+
@"Caracas" : @"America/Caracas",
45+
@"La Paz" : @"America/La_Paz",
46+
@"Santiago" : @"America/Santiago",
47+
@"Newfoundland" : @"America/St_Johns",
48+
@"Brasilia" : @"America/Sao_Paulo",
49+
@"Buenos Aires" : @"America/Argentina/Buenos_Aires",
50+
@"Georgetown" : @"America/Guyana",
51+
@"Greenland" : @"America/Godthab",
52+
@"Mid-Atlantic" : @"Atlantic/South_Georgia",
53+
@"Azores" : @"Atlantic/Azores",
54+
@"Cape Verde Is." : @"Atlantic/Cape_Verde",
55+
@"Dublin" : @"Europe/Dublin",
56+
@"Edinburgh" : @"Europe/London",
57+
@"Lisbon" : @"Europe/Lisbon",
58+
@"London" : @"Europe/London",
59+
@"Casablanca" : @"Africa/Casablanca",
60+
@"Monrovia" : @"Africa/Monrovia",
61+
@"UTC" : @"Etc/UTC",
62+
@"Belgrade" : @"Europe/Belgrade",
63+
@"Bratislava" : @"Europe/Bratislava",
64+
@"Budapest" : @"Europe/Budapest",
65+
@"Ljubljana" : @"Europe/Ljubljana",
66+
@"Prague" : @"Europe/Prague",
67+
@"Sarajevo" : @"Europe/Sarajevo",
68+
@"Skopje" : @"Europe/Skopje",
69+
@"Warsaw" : @"Europe/Warsaw",
70+
@"Zagreb" : @"Europe/Zagreb",
71+
@"Brussels" : @"Europe/Brussels",
72+
@"Copenhagen" : @"Europe/Copenhagen",
73+
@"Madrid" : @"Europe/Madrid",
74+
@"Paris" : @"Europe/Paris",
75+
@"Amsterdam" : @"Europe/Amsterdam",
76+
@"Berlin" : @"Europe/Berlin",
77+
@"Bern" : @"Europe/Berlin",
78+
@"Rome" : @"Europe/Rome",
79+
@"Stockholm" : @"Europe/Stockholm",
80+
@"Vienna" : @"Europe/Vienna",
81+
@"West Central Africa" : @"Africa/Algiers",
82+
@"Bucharest" : @"Europe/Bucharest",
83+
@"Cairo" : @"Africa/Cairo",
84+
@"Helsinki" : @"Europe/Helsinki",
85+
@"Kyiv" : @"Europe/Kiev",
86+
@"Riga" : @"Europe/Riga",
87+
@"Sofia" : @"Europe/Sofia",
88+
@"Tallinn" : @"Europe/Tallinn",
89+
@"Vilnius" : @"Europe/Vilnius",
90+
@"Athens" : @"Europe/Athens",
91+
@"Istanbul" : @"Europe/Istanbul",
92+
@"Minsk" : @"Europe/Minsk",
93+
@"Jerusalem" : @"Asia/Jerusalem",
94+
@"Harare" : @"Africa/Harare",
95+
@"Pretoria" : @"Africa/Johannesburg",
96+
@"Moscow" : @"Europe/Moscow",
97+
@"St. Petersburg" : @"Europe/Moscow",
98+
@"Volgograd" : @"Europe/Moscow",
99+
@"Kuwait" : @"Asia/Kuwait",
100+
@"Riyadh" : @"Asia/Riyadh",
101+
@"Nairobi" : @"Africa/Nairobi",
102+
@"Baghdad" : @"Asia/Baghdad",
103+
@"Tehran" : @"Asia/Tehran",
104+
@"Abu Dhabi" : @"Asia/Muscat",
105+
@"Muscat" : @"Asia/Muscat",
106+
@"Baku" : @"Asia/Baku",
107+
@"Tbilisi" : @"Asia/Tbilisi",
108+
@"Yerevan" : @"Asia/Yerevan",
109+
@"Kabul" : @"Asia/Kabul",
110+
@"Ekaterinburg" : @"Asia/Yekaterinburg",
111+
@"Islamabad" : @"Asia/Karachi",
112+
@"Karachi" : @"Asia/Karachi",
113+
@"Tashkent" : @"Asia/Tashkent",
114+
@"Chennai" : @"Asia/Kolkata",
115+
@"Kolkata" : @"Asia/Kolkata",
116+
@"Mumbai" : @"Asia/Kolkata",
117+
@"New Delhi" : @"Asia/Kolkata",
118+
@"Kathmandu" : @"Asia/Kathmandu",
119+
@"Astana" : @"Asia/Dhaka",
120+
@"Dhaka" : @"Asia/Dhaka",
121+
@"Sri Jayawardenepura" : @"Asia/Colombo",
122+
@"Almaty" : @"Asia/Almaty",
123+
@"Novosibirsk" : @"Asia/Novosibirsk",
124+
@"Rangoon" : @"Asia/Rangoon",
125+
@"Bangkok" : @"Asia/Bangkok",
126+
@"Hanoi" : @"Asia/Bangkok",
127+
@"Jakarta" : @"Asia/Jakarta",
128+
@"Krasnoyarsk" : @"Asia/Krasnoyarsk",
129+
@"Beijing" : @"Asia/Shanghai",
130+
@"Chongqing" : @"Asia/Chongqing",
131+
@"Hong Kong" : @"Asia/Hong_Kong",
132+
@"Urumqi" : @"Asia/Urumqi",
133+
@"Kuala Lumpur" : @"Asia/Kuala_Lumpur",
134+
@"Singapore" : @"Asia/Singapore",
135+
@"Taipei" : @"Asia/Taipei",
136+
@"Perth" : @"Australia/Perth",
137+
@"Irkutsk" : @"Asia/Irkutsk",
138+
@"Ulaan Bataar" : @"Asia/Ulaanbaatar",
139+
@"Seoul" : @"Asia/Seoul",
140+
@"Osaka" : @"Asia/Tokyo",
141+
@"Sapporo" : @"Asia/Tokyo",
142+
@"Tokyo" : @"Asia/Tokyo",
143+
@"Yakutsk" : @"Asia/Yakutsk",
144+
@"Darwin" : @"Australia/Darwin",
145+
@"Adelaide" : @"Australia/Adelaide",
146+
@"Canberra" : @"Australia/Melbourne",
147+
@"Melbourne" : @"Australia/Melbourne",
148+
@"Sydney" : @"Australia/Sydney",
149+
@"Brisbane" : @"Australia/Brisbane",
150+
@"Hobart" : @"Australia/Hobart",
151+
@"Vladivostok" : @"Asia/Vladivostok",
152+
@"Guam" : @"Pacific/Guam",
153+
@"Port Moresby" : @"Pacific/Port_Moresby",
154+
@"Magadan" : @"Asia/Magadan",
155+
@"Solomon Is." : @"Asia/Magadan",
156+
@"New Caledonia" : @"Pacific/Noumea",
157+
@"Fiji" : @"Pacific/Fiji",
158+
@"Kamchatka" : @"Asia/Kamchatka",
159+
@"Marshall Is." : @"Pacific/Majuro",
160+
@"Auckland" : @"Pacific/Auckland",
161+
@"Wellington" : @"Pacific/Auckland",
162+
@"Nuku'alofa" : @"Pacific/Tongatapu",
163+
@"Tokelau Is." : @"Pacific/Fakaofo",
164+
@"Samoa" : @"Pacific/Apia"
165+
};
166+
});
167+
168+
NSString *timezoneName = [timeZoneMap valueForKey:timezoneId];
169+
return timezoneName.length != 0 ? [NSTimeZone timeZoneWithName:timezoneName] : nil;
170+
}
171+
172+
@end

Example/iOSCalendarEventParser.xcodeproj/project.pbxproj

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
/* Begin PBXBuildFile section */
1010
02CE49A11C61FD3B00A2893C /* CalendarEventParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 02CE49A01C61FD3B00A2893C /* CalendarEventParser.m */; };
11+
02CE49A81C6204D400A2893C /* CalendarEventTimeZones.m in Sources */ = {isa = PBXBuildFile; fileRef = 02CE49A71C6204D400A2893C /* CalendarEventTimeZones.m */; };
12+
02CE49AB1C6209FD00A2893C /* CalendarEvent.m in Sources */ = {isa = PBXBuildFile; fileRef = 02CE49AA1C6209FD00A2893C /* CalendarEvent.m */; };
1113
6003F5B0195388D20070C39A /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F5AF195388D20070C39A /* XCTest.framework */; };
1214
6003F5B1195388D20070C39A /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F58D195388D20070C39A /* Foundation.framework */; };
1315
6003F5B2195388D20070C39A /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6003F591195388D20070C39A /* UIKit.framework */; };
@@ -18,6 +20,11 @@
1820
/* Begin PBXFileReference section */
1921
02CE499F1C61FD3B00A2893C /* CalendarEventParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalendarEventParser.h; sourceTree = "<group>"; };
2022
02CE49A01C61FD3B00A2893C /* CalendarEventParser.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CalendarEventParser.m; sourceTree = "<group>"; };
23+
02CE49A61C6204D400A2893C /* CalendarEventTimeZones.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalendarEventTimeZones.h; sourceTree = "<group>"; };
24+
02CE49A71C6204D400A2893C /* CalendarEventTimeZones.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CalendarEventTimeZones.m; sourceTree = "<group>"; };
25+
02CE49A91C6209FD00A2893C /* CalendarEvent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalendarEvent.h; sourceTree = "<group>"; };
26+
02CE49AA1C6209FD00A2893C /* CalendarEvent.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CalendarEvent.m; sourceTree = "<group>"; };
27+
02CE49AC1C620C1400A2893C /* CalendarEventParserConstants.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CalendarEventParserConstants.h; sourceTree = "<group>"; };
2128
2652851B1D2A3FE1DEC1BAC5 /* README.md */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = net.daringfireball.markdown; name = README.md; path = ../README.md; sourceTree = "<group>"; };
2229
30AAC1F3AAB018B6AE11CEF5 /* iOSCalendarEventParser.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = iOSCalendarEventParser.podspec; path = ../iOSCalendarEventParser.podspec; sourceTree = "<group>"; };
2330
4C0E30E2FD4823767EC65860 /* LICENSE */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = LICENSE; path = ../LICENSE; sourceTree = "<group>"; };
@@ -51,6 +58,11 @@
5158
children = (
5259
02CE499F1C61FD3B00A2893C /* CalendarEventParser.h */,
5360
02CE49A01C61FD3B00A2893C /* CalendarEventParser.m */,
61+
02CE49A61C6204D400A2893C /* CalendarEventTimeZones.h */,
62+
02CE49A71C6204D400A2893C /* CalendarEventTimeZones.m */,
63+
02CE49A91C6209FD00A2893C /* CalendarEvent.h */,
64+
02CE49AA1C6209FD00A2893C /* CalendarEvent.m */,
65+
02CE49AC1C620C1400A2893C /* CalendarEventParserConstants.h */,
5466
);
5567
name = CalendarManager;
5668
path = ../CalendarManager;
@@ -184,7 +196,9 @@
184196
isa = PBXSourcesBuildPhase;
185197
buildActionMask = 2147483647;
186198
files = (
199+
02CE49A81C6204D400A2893C /* CalendarEventTimeZones.m in Sources */,
187200
6003F5BC195388D20070C39A /* Tests.m in Sources */,
201+
02CE49AB1C6209FD00A2893C /* CalendarEvent.m in Sources */,
188202
02CE49A11C61FD3B00A2893C /* CalendarEventParser.m in Sources */,
189203
);
190204
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)