Sha256: dbd82bcf3b2ff338db188ddd2ab0c3a3b323a3056c1e7cf684623cf95022f566

Contents?: true

Size: 1.6 KB

Versions: 363

Compression:

Stored size: 1.6 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 { //!OCLINT
    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;
    }
    
    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

363 entries across 363 versions & 1 rubygems

Version Path
trackler-2.2.1.180 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.179 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.178 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.177 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.176 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.175 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.174 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.173 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.172 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.171 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.170 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.169 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.167 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.166 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.165 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.164 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.163 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.162 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.161 tracks/objective-c/exercises/meetup/MeetupExample.m
trackler-2.2.1.160 tracks/objective-c/exercises/meetup/MeetupExample.m