Short Challenge Solution


#1

Here it is:

Code from the .m file

+(NSDate *)bnr_year: (int) y month: (int) m day: (int) d
{
    
    
    NSDateComponents * metoda = [[NSDateComponents alloc] init];
    [metoda setYear:y];
    [metoda setMonth:m];
    [metoda setDay:d];
//set for 1 hour as normally I would get 23 hour in gregorian calendar. However I live in London which is +0000 so needed to add 1h.
    [metoda setHour:1];
    [metoda setMinute:0];
    NSCalendar *cal = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    NSDate * data = [cal dateFromComponents:metoda];
    
   
    return data;
    
    
}

and code from the main.m
#import <Foundation/Foundation.h>
#import “NSDate+BNRDateConvenience.h”

int main(int argc, const char * argv[])
{

@autoreleasepool {

    
    NSDate *challengeDate = [NSDate bnr_year:2014 month:05 day:12];
    NSLog(@"%@", challengeDate);
      
}
return 0;

}