Created
July 27, 2016 15:28
-
-
Save alaeddineG/cd2efeb1cea3249bd7041c5329f700b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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