Sha256: 674f9fefd86828d01ce101aab077c6c077789a2fe8b3533fba434928a42b5f0a

Contents?: true

Size: 1.62 KB

Versions: 33

Compression:

Stored size: 1.62 KB

Contents

#import "MeetupExample.h"

@implementation Meetup {
    int _year;
    int _month;
}

- (instancetype)initWithYear:(int)year andMonth:(int)month {
    if (self = [super init]) {
        _year = year;
        _month = month;
    }
    
    return self;
}

- (NSDate *)dayForDayOfWeek:(MeetupDayOfWeek)dayOfWeek andOptions:(MeetupOptions)options {
    NSDateComponents *components = [[NSDateComponents alloc] init];
    components.year = _year;
    components.month = _month;
    
    switch (options) {
        case MeetupOptionsFirst:
            components.day = 1;
            break;
        case MeetupOptionsSecond:
            components.day = 8;
            break;
        case MeetupOptionsThird:
            components.day = 15;
            break;
        case MeetupOptionsFourth:
            components.day = 22;
            break;
        case MeetupOptionsLast:
            components.day = 0;
            components.month += 1;
            break;
        case MeetupOptionsTeenth:
            components.day = 13;
            break;
        default:
            break;
    }
    
    while ([self weekdayFromComponents:components] != dayOfWeek) {
        if (options == MeetupOptionsLast) {
            components.day -= 1;
        } else {
            components.day += 1;
        }
    }
    
    return [[NSCalendar currentCalendar] dateFromComponents:components];
}

- (long)weekdayFromComponents:(NSDateComponents *)components {
    NSDate *date = [[NSCalendar currentCalendar] dateFromComponents:components];
    long weekday = [[NSCalendar currentCalendar] component:NSCalendarUnitWeekday fromDate:date];
    
    return weekday - 1;
}

@end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
trackler-2.0.3.7 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.6 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.5 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.4 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.3 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.2 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.1 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.3.0 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.2.0 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.1.2 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.1.1 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.1.0 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.10 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.9 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.8 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.7 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.6 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.5 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.4 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.0.0.3 tracks/objective-c/exercises/meetup/MeetupExample.m