-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
format
doesn't support ordinal indicator formatter
#26
Comments
Hi, Unfortunately yes. |
It depends how tidy a solution you'd be looking to implement. A suggestion from SO using a pretty dirty switch statement: - (NSString *)daySuffixForDate:(NSDate *)date {
NSCalendar *calendar = [NSCalendar currentCalendar];
NSInteger dayOfMonth = [calendar component:NSCalendarUnitDay fromDate:date];
switch (dayOfMonth) {
case 1:
case 21:
case 31: return @"st";
case 2:
case 22: return @"nd";
case 3:
case 23: return @"rd";
default: return @"th";
}
} You'd then have to use a Regex to search for the special character in the formatter argument. |
Yes the dirty solution is simple. But the formatter one requires some work. If I implement this feature I would conforms to the moment.js one (Do input). It's do-able, but I don't have the time for the moment to think about the best solution. I would use as much as possible the NSDateFormatter and "just" add the missing features. |
Sure I understand. In iOS 9 Apple introduced NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterOrdinalStyle;
NSArray<NSNumber *> *numbers = @[@1, @2, @3, @4, @5];
for (NSNumber *number in numbers) {
NSLog(@"%@", [formatter stringFromNumber:number]);
}
// "1st", "2nd", "3rd", "4th", "5th" Might be useful one day when you come to implement. |
It could be useful if I only support iOS 9+. May be it make sense for a new major version of |
https://en.wikipedia.org/wiki/Ordinal_indicator
Example "3rd Oct"
The text was updated successfully, but these errors were encountered: