Skip to content

Instantly share code, notes, and snippets.

@Den-Rimus
Created February 24, 2015 12:48
Show Gist options
  • Save Den-Rimus/32f2e5854fce00b45670 to your computer and use it in GitHub Desktop.
Save Den-Rimus/32f2e5854fce00b45670 to your computer and use it in GitHub Desktop.
iOS
if (elapse < 60) {
if(elapse<1)
elapse=1;
return [NSString stringWithFormat:@"%ds", (int)elapse];
}
else if (elapse < 60 * 60) {
int minute = round(elapse / 60);
return [NSString stringWithFormat:@"%dm", minute];
// } else if (elapse < 1.5 * 60 * 60) {
// return @"An hour";
} else if (elapse < 24 * 60 * 60) {
int hour = round(elapse / 60 / 60);
return [NSString stringWithFormat:@"%dh", hour];
// } else if (elapse < 48 * 60 * 60) {
// return @"Yesterday";
} else if (elapse < 7 * 24 * 60 * 60) {
int day = floor(elapse / 24 / 60 / 60);
return [NSString stringWithFormat:@"%dd", day];
} else//(elapse < 365 * 24 * 60 * 60)
{
int day = floor(elapse / 24 / 60 / 60/7);
return [NSString stringWithFormat:@"%dw", day];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment