I posted this question before and got an answer that worked, for one night only :(
I have this code:
NSLog(@"timeStringsArray2 %@", timeStringsArray2);
//3. Create NSDateFormatter
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm a"];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"MST"]];
//4. Get strings from Array
NSString *openDateString = (NSString*)[timeStringsArray2 objectAtIndex:0];
NSString *closeDateString = (NSString*)[timeStringsArray2 objectAtIndex:1];
NSLog(@"someDateString %@,%@", openDateString,closeDateString);
//5. Get month & day of current date
NSDate *currentDate = [NSDate date];
NSCalendar* calendario = [NSCalendar currentCalendar];
NSDateComponents* components = [calendario components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit fromDate:currentDate];
[components year]; // gives you year
//6. Make new strings with year 0001 + original time
NSString *adjustedOpenDateString = [NSString stringWithFormat:@"%@-%ld-%ld %@", @"2013", (long)[components month], (long)[components day], openDateString];
NSString *adjustedCloseDateString = [NSString stringWithFormat:@"%@-%ld-%ld %@", @"2013", (long)[components month], (long)[components day],closeDateString];
NSLog(@"adjustedString %@", adjustedCloseDateString);
//7. Use Date Formatter to convert adjusted strings to NSDates
NSDate *openDate = [dateFormatter dateFromString:adjustedOpenDateString];
NSDate *closeDate = [dateFormatter dateFromString:adjustedCloseDateString];
NSLog(@"DEALWITHTIMESTRINGS = open, now, close %@,%@,%@", openDate,[NSDate date], closeDate);
it logs this:
timeStringsArray2 (
"8:00AM",
"6:30PM" ) 2013-08-12
09:28:49 p.m.:316[7008:2311] +[TimeComparator dealWithTimeStrings2:] [Line 59] someDateString 8:00AM,6:30PM 2013-08-12
09:28:49 p.m.:320[7008:2311] +[TimeComparator dealWithTimeStrings2:] [Line 73] adjustedString 2013-8-12 6:30PM 2013-08-12
09:28:49 p.m.:325[7008:2311] +[TimeComparator dealWithTimeStrings2:] [Line 79] DEALWITHTIMESTRINGS = open, now, close (null),2013-08-13 04:28:49 a.m. +0000,(null)
I was suggested to change the format to hh:mma. I did and it worked briefly last night, for a couple of runs maybe. This morning it stopped working, returning null again. Any other ideas?
The only pattern I find is that it works on the simulator but not on any device. In the simulator, all dates come back just fine, open and close. But when i run it on the device, all dates come back null.