2010-11-30 10 views

Respuesta

2
  • Here encontrará RSS-feeds con las vacaciones. No muestra el año, pero en los documentos encontrará información sobre cómo cambiar los intervalos de fechas.
  • Descárguelo. Sugeriría ASIHTTPRequest para esa tarea.
    analiza la fuente RSS. puede hacerlo mediante un análisis XML normal, o puede usar un analizador especializado. MWFeedParser sería una opción.
  • Guarde las fechas. ya sea mediante el uso de CoreData, o Event Kit Framework
+2

FYI, dijo que el enlace RSS es ahora obsoleto (a partir del 19 de febrero de 2015). –

5

Si solo desea feriados federales en EE. UU., escribí este método. Sin embargo, podría usar estas técnicas para calcular cualquier vacación.

-(NSArray *)getUSHolidyas{ 
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; 
    formatter.dateFormat = @"yyyy"; 

    NSString *year = [formatter stringFromDate:[NSDate date]]; 
    formatter.dateFormat = @"M/d/yyyy"; 

    //Constant Holidays 
    NSDate *newYearsDay = [formatter dateFromString:[NSString stringWithFormat:@"1/1/%@",year]]; //Use next year for the case where we are adding days near end of december. 
    NSDate *indDay = [formatter dateFromString:[NSString stringWithFormat:@"7/4/%@",year]]; 
    NSDate *vetDay = [formatter dateFromString:[NSString stringWithFormat:@"11/11/%@",year]]; 
    NSDate *xmasDay = [formatter dateFromString:[NSString stringWithFormat:@"12/25/%@",year]]; 


    //Variable Holidays 
    NSInteger currentYearInt = [[[NSCalendar currentCalendar] 
           components:NSYearCalendarUnit fromDate:[NSDate date]] year]; 

    NSDate *mlkDay = [self getTheNth:3 occurrenceOfDay:2 inMonth:1 forYear:currentYearInt]; 
    NSDate *presDay = [self getTheNth:3 occurrenceOfDay:2 inMonth:2 forYear:currentYearInt]; 
    NSDate *memDay = [self getTheNth:5 occurrenceOfDay:2 inMonth:5 forYear:currentYearInt]; // Let's see if there are 5 Mondays in May 
    NSInteger month = [[[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:memDay] month]; 
    if (month > 5) { //Check that we are still in May 
     memDay = [self getTheNth:4 occurrenceOfDay:2 inMonth:5 forYear:currentYearInt]; 
    } 
    NSDate *labDay = [self getTheNth:1 occurrenceOfDay:2 inMonth:9 forYear:currentYearInt]; 
    NSDate *colDay = [self getTheNth:2 occurrenceOfDay:2 inMonth:10 forYear:currentYearInt]; 
    NSDate *thanksDay = [self getTheNth:4 occurrenceOfDay:5 inMonth:11 forYear:currentYearInt]; 

    return @[newYearsDay,mlkDay,presDay,memDay,indDay,labDay,colDay,vetDay,thanksDay,xmasDay]; 
} 

-(NSDate *)getTheNth:(NSInteger)n occurrenceOfDay:(NSInteger)day inMonth:(NSInteger)month forYear:(NSInteger)year{ 

    NSDateComponents *dateComponents = [[NSDateComponents alloc] init]; 

    dateComponents.year = year; 
    dateComponents.month = month; 
    dateComponents.weekday = day; // sunday is 1, monday is 2, ... 
    dateComponents.weekdayOrdinal = n; // this means, the first of whatever weekday you specified 
    return [[NSCalendar currentCalendar] dateFromComponents:dateComponents]; 
} 
Cuestiones relacionadas