Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 13th, 2012  |  syntax: Objective C  |  size: 1.48 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. -(NSDateComponents*) parseGroup2:(NSString*) code
  2. {
  3.         NSDateComponents* ret = [[NSDateComponents alloc] init];
  4.         int code_length = [code length];
  5.         if (code_length != 3)
  6.         {
  7.                 error = 1;
  8.                 return nil;
  9.         }
  10.         if ([self isLetter:[code characterAtIndex:2]])
  11.         {
  12.                 error = 1;
  13.                 return nil;
  14.         }
  15.         if (([code characterAtIndex:1] - '0' < 10 && [code characterAtIndex:1] - '0' >= 1) || ([code characterAtIndex:1] - 'A' <= 2 && [code characterAtIndex:1] - 'A' >= 0))
  16.         {              
  17.                 NSArray *arr = [[NSArray alloc] initWithObjects: @"2010", @"2011", @"2012", @"2003", @"2004", @"2005", @"2006", @"2007", @"2008", @"2009", nil];
  18.                 NSDictionary *dicMounth = [[NSDictionary alloc] initWithObjectsAndKeys:
  19.                                                            @"1", [NSNumber numberWithInt:'1'], @"2", [NSNumber numberWithInt:'2'],       
  20.                                                            @"3", [NSNumber numberWithInt:'3'], @"4", [NSNumber numberWithInt:'4'],
  21.                                                            @"5", [NSNumber numberWithInt:'5'], @"6", [NSNumber numberWithInt:'6'],
  22.                                                            @"7", [NSNumber numberWithInt:'7'], @"8", [NSNumber numberWithInt:'8'],
  23.                                                            @"9", [NSNumber numberWithInt:'9'], @"10", [NSNumber numberWithInt:'A'],
  24.                                                            @"11", [NSNumber numberWithInt:'B'], @"12", [NSNumber numberWithInt:'C'],
  25.                                                            nil];
  26.        
  27.                 int yearInd = [code characterAtIndex:2] - '0';
  28.                 [ret setYear: [[arr objectAtIndex:yearInd] intValue]];
  29.                 ret.month = [[dicMounth objectForKey: [NSNumber numberWithInt:[code characterAtIndex:1]]] intValue];
  30.                 type = YEAR_MOUNTH;
  31.         }
  32.         else
  33.         {
  34.                 error = 1;
  35.                 return nil;
  36.         }
  37.         return ret;
  38. }