Created
January 4, 2013 18:24
-
-
Save ronaldmannak/4454744 to your computer and use it in GitHub Desktop.
User friendly timestamps. https://coderwall.com/p/52edja
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*)dailyLanguage:(NSTimeInterval) overdueTimeInterval{ | |
if (overdueTimeInterval<0) | |
overdueTimeInterval*=-1; | |
NSInteger minutes = round(overdueTimeInterval)/60; | |
NSInteger hours = minutes/60; | |
NSInteger days = hours/24; | |
NSInteger months = days/30; | |
NSInteger years = months/12; | |
NSString* overdueMessage; | |
if (years>0){ | |
overdueMessage = [NSString stringWithFormat:@"%d %@", (years), (years==1?@"year":@"years")]; | |
}else if (months>0){ | |
overdueMessage = [NSString stringWithFormat:@"%d %@", (months), (months==1?@"month":@"months")]; | |
}else if (days>0){ | |
overdueMessage = [NSString stringWithFormat:@"%d %@", (days), (days==1?@"day":@"days")]; | |
}else if (hours>0){ | |
overdueMessage = [NSString stringWithFormat:@"%d %@", (hours), (hours==1?@"hour":@"hours")]; | |
}else if (minutes>0){ | |
overdueMessage = [NSString stringWithFormat:@"%d %@", (minutes), (minutes==1?@"minute":@"minutes")]; | |
}else if (overdueTimeInterval<60){ | |
overdueMessage = [NSString stringWithFormat:@"a few seconds"]; | |
} | |
return overdueMessage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment