Permalink
Browse files

-> Updated timetable with module events

  • Loading branch information...
1 parent 9172053 commit 618391489826436325f03d940b58e8875f542120 @shyamsundar2007 shyamsundar2007 committed Jul 14, 2011
Showing with 242 additions and 61 deletions.
  1. +4 −2 Classes/ModuleEvent2.h
  2. +77 −3 Classes/ModuleEvent2.m
  3. +161 −56 Classes/TimetableNew.m
View
@@ -7,12 +7,13 @@
//
#import <Foundation/Foundation.h>
-
+#import "IVLE.h"
@interface ModuleEvent2 : NSObject {
NSString *courseID, *academicYear, *dayText, *startTime, *endTime, *venue, *lessonType, *weekText, *weekCode;
NSNumber *semester, *classNumber, *dayCode;
+ NSMutableArray *classDates;
}
@property (nonatomic, retain) NSString *courseID;
@@ -27,7 +28,8 @@
@property (nonatomic, retain) NSNumber *semester;
@property (nonatomic, retain) NSNumber *classNumber;
@property (nonatomic, retain) NSNumber *dayCode;
+@property (nonatomic, retain) NSMutableArray *classDates;
-- (void)createModuleEvent:(NSDictionary *)moduleTimetableDetails;
+- (void)createModuleEvent:(NSDictionary *)moduleTimetableDetails StartDate:(NSDate *)startDate EndDate:(NSDate *)endDate;
@end
View
@@ -8,17 +8,25 @@
#import "ModuleEvent2.h"
+@interface ModuleEvent2 (PrivateMethods)
+
+- (NSDate *)setStartDate:(NSDate *)aDate;
+- (void)setWeekOffset;
+
+@end
+
@implementation ModuleEvent2
@synthesize courseID, academicYear, dayText, startTime, endTime, venue, lessonType, weekText, weekCode;
@synthesize semester, classNumber, dayCode;
+@synthesize classDates;
-- (void)createModuleEvent:(NSDictionary *)moduleTimetableDetails {
+- (void)createModuleEvent:(NSDictionary *)moduleTimetableDetails StartDate:(NSDate *)startDate EndDate:(NSDate *)endDate {
- NSLog(@"%@", moduleTimetableDetails);
+ //NSLog(@"%@", moduleTimetableDetails);
- courseID = [[NSString alloc] initWithString:[moduleTimetableDetails objectForKey:@"CourseID"]];
+ courseID = [[NSString alloc] initWithString:[moduleTimetableDetails objectForKey:@"ModuleCode"]];
academicYear = [[NSString alloc] initWithString:[moduleTimetableDetails objectForKey:@"AcadYear"]];
dayText = [[NSString alloc] initWithString:[moduleTimetableDetails objectForKey:@"DayText"]];
startTime = [[NSString alloc] initWithString:[moduleTimetableDetails objectForKey:@"StartTime"]];
@@ -30,6 +38,72 @@ - (void)createModuleEvent:(NSDictionary *)moduleTimetableDetails {
semester = [[NSNumber alloc] initWithInt:[[moduleTimetableDetails objectForKey:@"Semester"] intValue]];
classNumber = [[NSNumber alloc] initWithInt:[[moduleTimetableDetails objectForKey:@"ClassNo"] intValue]];
dayCode = [[NSNumber alloc] initWithInt:[[moduleTimetableDetails objectForKey:@"DayCode"] intValue]];
+
+ //NSLog(@"%@", [[IVLE instance] CodeTableWeekTypes]);
+
+ // Initialise calendar to current type and set the timezone to never have daylight saving
+ NSCalendar *cal = [NSCalendar currentCalendar];
+ [cal setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
+
+ // Construct DateComponents based on startDate so the iterating date can be created.
+ // Its massively important to do this assigning via the NSCalendar and NSDateComponents because of daylight saving has been removed
+ // with the timezone that was set above. If you just used "startDate" directly (ie, NSDate *date = startDate;) as the first
+ // iterating date then times would go up and down based on daylight savings.
+ NSDateComponents *comp = [cal components:(NSMonthCalendarUnit | NSMinuteCalendarUnit | NSYearCalendarUnit |
+ NSDayCalendarUnit | NSWeekdayCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit)
+ fromDate:startDate];
+
+ startDate = [self setStartDate:startDate];
+
+ NSDateComponents *dateOffset = [[NSDateComponents alloc] init];
+ if ([weekCode isEqualToString:@"0"]) {
+ [dateOffset setDay:7];
+ }
+ else if ([weekCode isEqualToString:@"1"]) {
+ [dateOffset setDay:14];
+ }
+ else if ([weekCode isEqualToString:@"2"]) {
+ [dateOffset setDay:14];
+ startDate = [NSDate dateWithTimeInterval:604800 sinceDate:startDate];
+ }
+
+ classDates = [[NSMutableArray alloc] init];
+
+ for (NSDate *currentDate = startDate; [currentDate compare:endDate] != NSOrderedDescending; currentDate = [cal dateByAddingComponents:dateOffset toDate:currentDate options:0]) {
+
+ [classDates addObject:currentDate];
+ }
+
+ NSLog(@"%@", classDates);
+}
+
+- (NSDate *)setStartDate:(NSDate *)aDate {
+
+ if ([dayText isEqualToString:@"Monday"]) {
+ return aDate;
+ }
+ else if ([dayText isEqualToString:@"Tuesday"]) {
+ return [NSDate dateWithTimeInterval:86400 sinceDate:aDate];
+ }
+ else if ([dayText isEqualToString:@"Wednesday"]) {
+ return [NSDate dateWithTimeInterval:86400*2 sinceDate:aDate];
+ }
+ else if ([dayText isEqualToString:@"Thursday"]) {
+ return [NSDate dateWithTimeInterval:86400*3 sinceDate:aDate];
+ }
+ else if ([dayText isEqualToString:@"Friday"]) {
+ return [NSDate dateWithTimeInterval:86400*4 sinceDate:aDate];
+ }
+ else if ([dayText isEqualToString:@"Saturday"]) {
+ return [NSDate dateWithTimeInterval:86400*5 sinceDate:aDate];
+ }
+ else if ([dayText isEqualToString:@"Sunday"]) {
+ return [NSDate dateWithTimeInterval:86400*6 sinceDate:aDate];
+ }
+}
+
+- (void)setWeekOffset {
+
}
- (void)dealloc {
Oops, something went wrong.

0 comments on commit 6183914

Please sign in to comment.