// // StringExtensions.m // SixToEight // // Created by Adam Wright on 20/04/2010. // Copyright 2010 Adam Wright. All rights reserved. // #import "DateExtensions.h" @implementation NSDate (NSDate_Extensions) - (NSString*)niceDateString { int secondsElapsed = [self timeIntervalSinceNow] * -1; if (secondsElapsed <= 119) return @"a minute ago"; else if (secondsElapsed <= 59 * 60) return [NSString stringWithFormat:@"%i minutes ago", secondsElapsed / 60]; else if (secondsElapsed <= 60 * 60 * 90) return [NSString stringWithFormat:@"an hour ago", secondsElapsed / 60]; else if (secondsElapsed <= 23 * 60 * 60) return [NSString stringWithFormat:@"%i hours ago", secondsElapsed / (60 * 60)]; else if (secondsElapsed < 25 * 60 * 60) return @"yesterday"; else if (secondsElapsed < 24 * 60 * 60 * 7) { NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; formatter.dateFormat = @"cccc"; return [NSString stringWithFormat:@"last %@", [formatter stringFromDate:self]]; } NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease]; formatter.dateFormat = @"H:mm, d MMM yy"; return [formatter stringFromDate:self]; } @end