Skip to content

Instantly share code, notes, and snippets.

@alaeddineG
Created July 27, 2016 15:28
Show Gist options
  • Save alaeddineG/cd2efeb1cea3249bd7041c5329f700b6 to your computer and use it in GitHub Desktop.
Save alaeddineG/cd2efeb1cea3249bd7041c5329f700b6 to your computer and use it in GitHub Desktop.
- (NSString*) postedSince {
NSInteger days = self.age.integerValue / (60 * 60 * 24);
NSInteger second = self.age.integerValue % (60 * 60 * 24);
NSInteger hours = second / (60 * 60);
NSInteger minute = (second % (60 * 60)) / 60;
NSMutableString* postedSince = [NSMutableString new];
if(self.age.integerValue < 60){
return [NSString stringWithFormat:@"%ld s", (long)self.age.integerValue];
}
if(hours > 0) {
[postedSince appendString:[NSString stringWithFormat:@"%ld hr", (long)hours]];
}
if(minute > 0){
[postedSince appendString:[NSString stringWithFormat:@" %ld m", (long)minute]];
}
if(hours >= 8 || days > 1){
return @"+8 h";
}
return postedSince;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment