Skip to content

Instantly share code, notes, and snippets.

@TyrfingMjolnir
Last active August 29, 2015 13:58
Show Gist options
  • Save TyrfingMjolnir/10001148 to your computer and use it in GitHub Desktop.
Save TyrfingMjolnir/10001148 to your computer and use it in GitHub Desktop.
//FixturesObject.m
//...
NSString *dateString = [NSString stringWithFormat: @"%@",object.date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ"];
NSDate *myDate = [dateFormatter dateFromString:dateString];
NSString *dateInEpoch = [NSString stringWithFormat:@"%.0f", [myDate timeIntervalSince1970]];
object.epoch = dateInEpoch;
//MainViewController.m
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"fixturesCellID";
FixturesCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
FixturesObject *item = [tableDataFixtures objectAtIndex:(int)([indexPath row]/2)];
if( [ item isKindOfClass: [ FixturesObject class ] ] ) {
NSDate *dateStringCurrent = [ NSDate date ];
NSDateFormatter *dateFormatterCurrent = [ [ NSDateFormatter alloc ] init ];
[ dateFormatterCurrent setDateFormat:@"yyyy-MM-dd'T'HH:mm:ssZ" ];
NSString *dateInEpochCurrent = [ NSString stringWithFormat:@"%.0f", [ dateStringCurrent timeIntervalSince1970 ] ];
int bestDifference;
int initDifference = 999999999;
for( *epoch in tableDataFixtures ) {
bestDifference = ( int )dateInEpochCurrent - (int)epoch;
if( initDifference < bestDifference ) {
bestDifference = initDifference;
}
}
NSLog( @"show me the best difference %i", bestDifference );
// item.h
@interface item : NSObject
@property int epoch;
@property int dateInEpochCurrent;
@property int bestDifference;
@property int initDifference;
@end
-( int )calculateBestDifference;
// item.m
-( int )calculateBestDifference {
bestDifference = abs( dateInEpochCurrent - epoch );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment