[
https://issues.apache.org/jira/browse/CB-6132?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15523434#comment-15523434
]
Richard commented on CB-6132:
-----------------------------
Looks like this is broken again. For me sample code returns:
[Log] pattern: dd/MM/yy
[Log] pattern: dd/MM/yy
[Log] pattern: dd/MM/yy
[Log] pattern: dd/MM/yy
Testing on iOS 9.0.2
> Globalization plugin method getDatePattern always returns short date style on
> iOS.
> ----------------------------------------------------------------------------------
>
> Key: CB-6132
> URL: https://issues.apache.org/jira/browse/CB-6132
> Project: Apache Cordova
> Issue Type: Bug
> Components: Plugin Globalization
> Affects Versions: 3.4.0
> Environment: iOS 7
> Reporter: Alan Rahlf
> Labels: ios, triaged
>
> Here are a few examples to demonstrate the problem:
> {code}
> navigator.globalization.getDatePattern(function(properties) {
> console.log('pattern: ' + properties.pattern); // prints "M/d/yy"
> }, function() {}, { formatLength: 'short', selector: 'date' });
> navigator.globalization.getDatePattern(function(properties) {
> console.log('pattern: ' + properties.pattern); // prints "M/d/yy"
> }, function() {}, { formatLength: 'medium', selector: 'date' });
> navigator.globalization.getDatePattern(function(properties) {
> console.log('pattern: ' + properties.pattern); // prints "M/d/yy"
> }, function() {}, { formatLength: 'long', selector: 'date' });
> navigator.globalization.getDatePattern(function(properties) {
> console.log('pattern: ' + properties.pattern); // prints "M/d/yy"
> }, function() {}, { formatLength: 'full', selector: 'date' });
> {code}
> As you can see, the pattern is the same for all format lengths. This is
> happening because in the iOS plugin code it's iterating over the options
> dictionary keys, but because order matters, the logic inside the loop is
> flawed. Here's the block I'm referring to:
> {code}
> if (items && [items isKindOfClass:[NSMutableDictionary class]]) {
> NSEnumerator* enumerator = [items keyEnumerator];
> id key;
> // iterate through all the options
> while ((key = [enumerator nextObject])) {
> id item = [items valueForKey:key];
> // make sure that only string values are present
> if ([item isKindOfClass:[NSString class]]) {
> // get the desired format length
> if ([key isEqualToString:@"formatLength"]) {
> if ([item isEqualToString:@"short"]) {
> style = kCFDateFormatterShortStyle;
> } else if ([item isEqualToString:@"medium"]) {
> style = kCFDateFormatterMediumStyle;
> } else if ([item isEqualToString:@"long"]) {
> style = kCFDateFormatterLongStyle;
> } else if ([item isEqualToString:@"full"]) {
> style = kCFDateFormatterFullStyle;
> }
> }
> // get the type of date and time to generate
> else if ([key isEqualToString:@"selector"]) {
> if ([item isEqualToString:@"date"]) {
> dateStyle = style;
> timeStyle = kCFDateFormatterNoStyle;
> } else if ([item isEqualToString:@"time"]) {
> dateStyle = kCFDateFormatterNoStyle;
> timeStyle = style;
> } else if ([item isEqualToString:@"date and time"]) {
> dateStyle = style;
> timeStyle = style;
> }
> }
> }
> }
> }
> {code}
> The selector key runs first, which relies on the style variable being set
> correctly, but this doesn't get set until the 2nd iteration of the loop when
> the formatLength key is evaluated.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]