Frameworks/AIUtilities Framework/Source/AIDateFormatterAdditions.m
author Evan Schoenberg
Thu, 14 Nov 2019 16:22:42 -0500
branchadium-1.5.10.5
changeset 5997 d88e6711d0e0
parent 4724 d7c0b9fe1002
permissions -rw-r--r--
Fixed a triple handful of warnings
3679
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     1
/* 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     2
 * Adium is the legal property of its developers, whose names are listed in the copyright file included
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     3
 * with this source distribution.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     4
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     6
 * General Public License as published by the Free Software Foundation; either version 2 of the License,
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     7
 * or (at your option) any later version.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     8
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
     9
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
    10
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
    11
 * Public License for more details.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
    12
 * 
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
    13
 * You should have received a copy of the GNU General Public License along with this program; if not,
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
    14
 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
f4294bb53b0f Bring consistency to file headings, this is not exhaustive. Evan and the rest.
Frank Dowsett <wixardy@adium.im>
parents: 2803
diff changeset
    15
 */
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    16
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    17
#import "AIDateFormatterAdditions.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    18
#import "AIApplicationAdditions.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    19
#import "AIDateAdditions.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    20
#import "AIStringUtilities.h"
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    21
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    22
#define ONE_WEEK AILocalizedStringFromTableInBundle(@"1 week", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    23
#define MULTIPLE_WEEKS AILocalizedStringFromTableInBundle(@"%i weeks", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    24
#define ONE_DAY AILocalizedStringFromTableInBundle(@"1 day", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    25
#define MULTIPLE_DAYS AILocalizedStringFromTableInBundle(@"%i days", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    26
#define ONE_HOUR AILocalizedStringFromTableInBundle(@"1 hour", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    27
#define MULTIPLE_HOURS AILocalizedStringFromTableInBundle(@"%i hours", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    28
#define ONE_MINUTE AILocalizedStringFromTableInBundle(@"1 minute", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    29
#define MULTIPLE_MINUTES AILocalizedStringFromTableInBundle(@"%i minutes", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    30
#define ONE_SECOND AILocalizedStringFromTableInBundle(@"1 second", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    31
#define MULTIPLE_SECONDS AILocalizedStringFromTableInBundle(@"%1.0lf seconds", nil, [NSBundle bundleWithIdentifier:AIUTILITIES_BUNDLE_ID], nil)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    32
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    33
@interface NSDateFormatter (PRIVATE)
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    34
+ (NSDateFormatter *)localizedDateFormatter;
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    35
+ (NSDateFormatter *)localizedShortDateFormatter;
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    36
+ (NSDateFormatter *)localizedDateFormatterShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm;
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    37
+ (dispatch_queue_t)localizedFormatterQueue;
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    38
@end
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    39
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    40
typedef enum {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    41
    NONE,
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    42
    SECONDS,
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    43
    AMPM,
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    44
    BOTH
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    45
} StringType;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
    46
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    47
@interface AIDateFormatterCache : NSObject
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    48
{
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    49
	NSDateFormatter *localizedDateFormatter;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    50
	NSDateFormatter *localizedShortDateFormatter;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    51
	NSDateFormatter *localizedDateFormatterShowingSecondsAndAMPM;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    52
	NSDateFormatter *localizedDateFormatterShowingAMPM;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    53
	NSDateFormatter *localizedDateFormatterShowingSeconds;
2799
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
    54
	NSDateFormatter *localizedDateFormatterShowingNoSecondsOrAMPM;
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    55
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    56
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    57
+ (AIDateFormatterCache *)sharedInstance;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    58
- (void) flushFormatterCache:(NSNotification *)dnc;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    59
- (NSDateFormatter **)formatterShowingSeconds:(BOOL)sec showingAMorPM:(BOOL)ampm;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    60
- (NSDateFormatter **)formatter;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    61
- (NSDateFormatter **)shortFormatter;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    62
@end
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    63
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    64
static AIDateFormatterCache *sharedFormatterCache = nil;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    65
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    66
@implementation AIDateFormatterCache
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    67
- (id) init {
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    68
	if ((self = [super init])) {
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    69
		[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(flushFormatterCache:) name:@"AppleDatePreferencesChangedNotification" object:nil];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    70
		[[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(flushFormatterCache:) name:@"AppleTimePreferencesChangedNotification" object:nil];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    71
	}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    72
	return self;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    73
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    74
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    75
- (void) flushFormatterCache:(NSNotification *)dnc
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    76
{
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    77
	[sharedFormatterCache release]; sharedFormatterCache = nil;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    78
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    79
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    80
+ (AIDateFormatterCache *)sharedInstance
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    81
{
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    82
	NSAssert(dispatch_get_current_queue() == [NSDateFormatter localizedFormatterQueue], @"Wrong queue");
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
    83
	
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    84
	if (!sharedFormatterCache)
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    85
		sharedFormatterCache = [[AIDateFormatterCache alloc] init];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    86
	return sharedFormatterCache;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    87
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    88
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    89
- (NSDateFormatter **)formatterShowingSeconds:(BOOL)sec showingAMorPM:(BOOL)ampm
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    90
{
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    91
	if (sec && ampm)
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    92
		return &localizedDateFormatterShowingSecondsAndAMPM;
2799
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
    93
	else if (sec && !ampm)
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    94
		return &localizedDateFormatterShowingSeconds;
2799
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
    95
	else if (!sec && ampm)
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
    96
		return &localizedDateFormatterShowingAMPM;
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
    97
	else // if (!sec && !ampm)
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
    98
		return &localizedDateFormatterShowingNoSecondsOrAMPM;
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
    99
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   100
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   101
- (NSDateFormatter **)formatter
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   102
{
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   103
	return &localizedDateFormatter;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   104
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   105
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   106
- (NSDateFormatter **)shortFormatter
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   107
{
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   108
	return &localizedShortDateFormatter;
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   109
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   110
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   111
- (void) dealloc
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   112
{
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   113
	[[NSDistributedNotificationCenter defaultCenter] removeObserver: self];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   114
	[localizedDateFormatter release];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   115
	[localizedShortDateFormatter release];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   116
	[localizedDateFormatterShowingSecondsAndAMPM release];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   117
	[localizedDateFormatterShowingAMPM release];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   118
	[localizedDateFormatterShowingSeconds release];
2799
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
   119
	[localizedDateFormatterShowingNoSecondsOrAMPM release];
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   120
	[super dealloc];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   121
}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   122
@end
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   123
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   124
@implementation NSDateFormatter (AIDateFormatterAdditions)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   125
4356
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   126
+ (dispatch_queue_t)localizedFormatterQueue
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   127
{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   128
	static dispatch_once_t onceToken;
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   129
	static dispatch_queue_t localizedFormatterQueue;
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   130
	dispatch_once(&onceToken, ^{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   131
		localizedFormatterQueue = dispatch_queue_create("im.adium.LocalizedDateFormatterQueue", NULL);
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   132
	});
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   133
	
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   134
	return localizedFormatterQueue;
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   135
}
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   136
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   137
+ (void)withLocalizedDateFormatterPerform:(void (^)(NSDateFormatter *))block
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   138
{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   139
	dispatch_queue_t localizedFormatterQueue = [self localizedFormatterQueue];
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   140
	
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   141
	dispatch_sync(localizedFormatterQueue, ^{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   142
		block([self localizedDateFormatter]);
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   143
	});
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   144
}
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   145
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   146
+ (void)withLocalizedShortDateFormatterPerform:(void (^)(NSDateFormatter *))block
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   147
{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   148
	dispatch_queue_t localizedFormatterQueue = [self localizedFormatterQueue];
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   149
	
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   150
	dispatch_sync(localizedFormatterQueue, ^{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   151
		block([self localizedShortDateFormatter]);
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   152
	});
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   153
}
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   154
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   155
+ (void)withLocalizedDateFormatterShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm perform:(void (^)(NSDateFormatter *))block
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   156
{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   157
	dispatch_queue_t localizedFormatterQueue = [self localizedFormatterQueue];
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   158
	
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   159
	dispatch_sync(localizedFormatterQueue, ^{
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   160
		block([self localizedDateFormatterShowingSeconds:seconds showingAMorPM:showAmPm]);
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   161
	});
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   162
}
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   163
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   164
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   165
+ (NSDateFormatter *)localizedDateFormatter
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   166
{
4356
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   167
	NSAssert(dispatch_get_current_queue() == [self localizedFormatterQueue], @"Wrong queue");
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   168
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   169
	// Thursday, July 31, 2008
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   170
	NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] formatter];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   171
	
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   172
	if (!(*cachePointer)) {
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   173
		*cachePointer = [[NSDateFormatter alloc] init];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   174
		[*cachePointer setDateStyle:NSDateFormatterFullStyle];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   175
		[*cachePointer setTimeStyle:NSDateFormatterNoStyle];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   176
	}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   177
	
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   178
	return *cachePointer;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   179
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   180
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   181
+ (NSDateFormatter *)localizedShortDateFormatter
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   182
{
4356
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   183
	NSAssert(dispatch_get_current_queue() == [self localizedFormatterQueue], @"Wrong queue");
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   184
	
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   185
	// 7/31/08
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   186
	NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] shortFormatter];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   187
	
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   188
	if (!(*cachePointer)) {
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   189
		*cachePointer = [[NSDateFormatter alloc] init];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   190
		[*cachePointer setDateStyle:NSDateFormatterShortStyle];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   191
		[*cachePointer setTimeStyle:NSDateFormatterNoStyle];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   192
	}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   193
	
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   194
	return *cachePointer;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   195
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   196
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   197
+ (NSDateFormatter *)localizedDateFormatterShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   198
{
4356
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   199
	NSAssert(dispatch_get_current_queue() == [self localizedFormatterQueue], @"Wrong queue");
a0d4ead5c91e Use a serial dispatch queue for all shared localized NSDateFormatter uses.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 3679
diff changeset
   200
	
1927
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   201
	NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] formatterShowingSeconds:seconds showingAMorPM:showAmPm];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   202
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   203
	if (!(*cachePointer)) {
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   204
		[self localizedDateFormatStringShowingSeconds:seconds showingAMorPM:showAmPm];
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   205
	}
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   206
	
6c4431042cd5 Implement a caching system for our date formatters. They showed up at 25% or so on a profile due to %shortTime% replacement in the wkmv
David Smith <catfish.man@gmail.com>
parents: 1658
diff changeset
   207
	return *cachePointer; //this is initialized in localizedDateFormatStringShowingSeconds:showingAMorPM:
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   208
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   209
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   210
+ (NSString *)localizedDateFormatStringShowingSeconds:(BOOL)seconds showingAMorPM:(BOOL)showAmPm
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   211
{
4358
020d20c23e1e Run +localizedDateFormatStringShowingSeconds:showingAMorPM: on the queue too, don't just assert it.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4356
diff changeset
   212
	dispatch_queue_t localizedFormatterQueue = [self localizedFormatterQueue];
020d20c23e1e Run +localizedDateFormatStringShowingSeconds:showingAMorPM: on the queue too, don't just assert it.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4356
diff changeset
   213
	__block NSString *formatString;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   214
	
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   215
	if (dispatch_get_current_queue() != localizedFormatterQueue) {
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   216
		dispatch_sync(localizedFormatterQueue, ^{
4385
29e120eb250a Two small AIDateFormatterAdditions fixes:
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4359
diff changeset
   217
			formatString = [[self localizedDateFormatStringShowingSeconds:seconds showingAMorPM:showAmPm] retain];
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   218
		});
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   219
		return [formatString autorelease];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   220
	}
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   221
	
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   222
	NSDateFormatter **cachePointer = [[AIDateFormatterCache sharedInstance] formatterShowingSeconds:seconds showingAMorPM:showAmPm];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   223
	
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   224
	BOOL setFormat = NO;
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   225
	
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   226
	if (!(*cachePointer)) {
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   227
		// Get the current time format string
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   228
		*cachePointer = [[NSDateFormatter alloc] init];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   229
		[*cachePointer setDateStyle:NSDateFormatterNoStyle];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   230
		[*cachePointer setTimeStyle:(seconds) ? NSDateFormatterMediumStyle : NSDateFormatterShortStyle];
4358
020d20c23e1e Run +localizedDateFormatStringShowingSeconds:showingAMorPM: on the queue too, don't just assert it.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4356
diff changeset
   231
		
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   232
		setFormat = YES;
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   233
	}
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   234
	
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   235
	if(!showAmPm) {
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   236
		NSMutableString *newFormat = [[NSMutableString alloc] initWithString:[*cachePointer dateFormat]];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   237
		[newFormat replaceOccurrencesOfString:@"a"
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   238
								   withString:@""
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   239
									  options:NSBackwardsSearch | NSLiteralSearch
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   240
										range:NSMakeRange(0,[newFormat length])];
4358
020d20c23e1e Run +localizedDateFormatStringShowingSeconds:showingAMorPM: on the queue too, don't just assert it.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4356
diff changeset
   241
		
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   242
		formatString = [newFormat autorelease];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   243
	} else {
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   244
		formatString = [*cachePointer dateFormat];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   245
	}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   246
	
4359
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   247
	formatString = [formatString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   248
	
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   249
	if (setFormat)
e857285aa973 Doh. This can of course be called from one of the other functions already on the queue. Make sure that's handled.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4358
diff changeset
   250
		[*cachePointer setDateFormat:formatString];
4358
020d20c23e1e Run +localizedDateFormatStringShowingSeconds:showingAMorPM: on the queue too, don't just assert it.
Thijs Alkemade <thijsalkemade@gmail.com>
parents: 4356
diff changeset
   251
		
2799
3ee009cf02f0 Fix a few date formatter issues. Fixes #11981. Fixes #12545.
Zachary West <zacw@adium.im>
parents: 2677
diff changeset
   252
	return formatString;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   253
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   254
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   255
+ (NSString *)stringForTimeIntervalSinceDate:(NSDate *)inDate
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   256
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   257
    return ([self stringForTimeIntervalSinceDate:inDate showingSeconds:YES abbreviated:NO]);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   258
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   259
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   260
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   261
 *@brief format time for the interval since the given date
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   262
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   263
 *@param inDate Date which starts the interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   264
 *@param showSeconds switch to determine if seconds should be shown
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   265
 *@param abbreviate switch to chose if w/d/h/ or weeks/days/hours/minutes is used to indicate the unit
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   266
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   267
 *@result a localized NSString containing the Interval in weeks, days, hours or minutes (the largest usable)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   268
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   269
 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   270
+ (NSString *)stringForTimeIntervalSinceDate:(NSDate *)inDate showingSeconds:(BOOL)showSeconds abbreviated:(BOOL)abbreviate;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   271
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   272
    return [self stringForTimeInterval:[[NSDate date] timeIntervalSinceDate:inDate]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   273
						showingSeconds:showSeconds
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   274
						   abbreviated:abbreviate
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   275
						  approximated:NO];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   276
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   277
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   278
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   279
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   280
 *@brief format time for the interval between two dates
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   281
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   282
 *@param firstDate first date of the interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   283
 *@param secondDate second date of the interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   284
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   285
 *@result a localized NSString containing the Interval in weeks, days, hours or minutes (the largest usable)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   286
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   287
 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   288
+ (NSString *)stringForApproximateTimeIntervalBetweenDate:(NSDate *)firstDate andDate:(NSDate *)secondDate
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   289
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   290
	return  [self stringForTimeInterval:[firstDate timeIntervalSinceDate:secondDate]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   291
						 showingSeconds:NO
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   292
							abbreviated:NO
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   293
						   approximated:YES];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   294
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   295
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   296
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   297
 *@brief format time for an interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   298
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   299
 *@param interval NSTimeInterval to format
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   300
 *@param abbreviate switch to chose if w/d/h/ or weeks/days/hours/minutes is used to indicate the unit
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   301
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   302
 *@result a localized NSString containing the Interval in weeks, days, hours or minutes (the largest usable)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   303
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   304
 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   305
+ (NSString *)stringForApproximateTimeInterval:(NSTimeInterval)interval abbreviated:(BOOL)abbreviate
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   306
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   307
	return  [self stringForTimeInterval:interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   308
						 showingSeconds:NO
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   309
							abbreviated:abbreviate
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   310
						   approximated:YES];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   311
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   312
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   313
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   314
 *@brief format time for an interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   315
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   316
 *@param interval NSTimeInterval to format
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   317
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   318
 *@result a localized NSString containing the interval in weeks, days, hours and minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   319
 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   320
 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   321
+ (NSString *)stringForTimeInterval:(NSTimeInterval)interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   322
{
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   323
	return  [self stringForTimeInterval:interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   324
						 showingSeconds:NO
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   325
							abbreviated:NO
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   326
						   approximated:NO];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   327
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   328
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   329
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   330
 *@brief format time for an interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   331
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   332
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   333
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   334
 *@param interval NSTimeInterval to format
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   335
 *@param showSeconds switch to determine if seconds should be shown
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   336
 *@param abbreviate switch to chose if w/d/h/ or weeks/days/hours/minutes is used to indicate the unit
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   337
 *@param approximate switch to chose if all parts should be shown or only the largest available part. If Hours is the largest available part, Minutes are also shown if applicable.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   338
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   339
 *@result a localized NSString containing the Interval formated according to the switches
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   340
 */ 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   341
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   342
+ (NSString *)stringForTimeInterval:(NSTimeInterval)interval showingSeconds:(BOOL)showSeconds abbreviated:(BOOL)abbreviate approximated:(BOOL)approximate
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   343
{
2677
43d104027d33 Correct for 64-bit type mismatches for our unit tests.
Stephen Holt <sholt@adium.im>
parents: 1927
diff changeset
   344
    NSInteger		weeks = 0, days = 0, hours = 0, minutes = 0;
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   345
	NSTimeInterval	seconds = 0; 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   346
	NSString		*weeksString = nil, *daysString = nil, *hoursString = nil, *minutesString = nil, *secondsString = nil;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   347
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   348
	[NSDate convertTimeInterval:interval
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   349
	                    toWeeks:&weeks
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   350
	                       days:&days
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   351
	                      hours:&hours
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   352
	                    minutes:&minutes
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   353
	                    seconds:&seconds];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   354
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   355
	//build the strings for the parts
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   356
	if (abbreviate) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   357
		//Note: after checking with a linguistics student, it appears that we're fine leaving it as w, h, etc... rather than localizing.
5997
d88e6711d0e0 Fixed a triple handful of warnings
Evan Schoenberg
parents: 4724
diff changeset
   358
        weeksString		= [NSString stringWithFormat: @"%liw",(long)weeks];
d88e6711d0e0 Fixed a triple handful of warnings
Evan Schoenberg
parents: 4724
diff changeset
   359
		daysString		= [NSString stringWithFormat: @"%id",(int)days];
d88e6711d0e0 Fixed a triple handful of warnings
Evan Schoenberg
parents: 4724
diff changeset
   360
		hoursString		= [NSString stringWithFormat: @"%ih",(int)hours];
d88e6711d0e0 Fixed a triple handful of warnings
Evan Schoenberg
parents: 4724
diff changeset
   361
		minutesString	= [NSString stringWithFormat: @"%im",(int)minutes];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   362
		secondsString	= [NSString stringWithFormat: @"%.0fs",seconds];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   363
	} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   364
		weeksString		= (weeks == 1)		? ONE_WEEK		: [NSString stringWithFormat:MULTIPLE_WEEKS, weeks];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   365
		daysString		= (days == 1)		? ONE_DAY		: [NSString stringWithFormat:MULTIPLE_DAYS, days];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   366
		hoursString		= (hours == 1)		? ONE_HOUR		: [NSString stringWithFormat:MULTIPLE_HOURS, hours];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   367
		minutesString	= (minutes == 1)	? ONE_MINUTE	: [NSString stringWithFormat:MULTIPLE_MINUTES, minutes];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   368
		secondsString	= (seconds == 1)	? ONE_SECOND	: [NSString stringWithFormat:MULTIPLE_SECONDS, seconds];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   369
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   370
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   371
	//assemble the parts
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   372
	NSMutableArray *parts = [NSMutableArray arrayWithCapacity:5];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   373
	if (approximate) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   374
		/* We want only one of these. For example, 5 weeks, 5 days, 5 hours, 5 minutes, and 5 seconds should just be "5 weeks".
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   375
		 * Exception: Hours should display hours and minutes. 5 hours, 5 minutes, and 5 seconds is "5 hours and 5 minutes".
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   376
		 */
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   377
		if (weeks)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   378
			[parts addObject:weeksString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   379
		else if (days)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   380
			[parts addObject:daysString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   381
		else if (hours) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   382
			[parts addObject:hoursString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   383
			if (minutes)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   384
				[parts addObject:minutesString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   385
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   386
		else if (minutes)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   387
			[parts addObject:minutesString];
1130
467a6582f4e1 Fix the test failure that I made no longer intermittent in r26332. We want to compare against the smallest number of seconds that will round up to at least 1; 0.01 is too small and results in ??, 0 seconds?. All tests now pass.
Peter Hosey
parents: 55
diff changeset
   388
		else if (showSeconds && (seconds >= 0.5))
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   389
			[parts addObject:secondsString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   390
	} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   391
		//We want all of these that aren't zero.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   392
		if (weeks)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   393
			[parts addObject:weeksString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   394
		if (days)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   395
			[parts addObject:daysString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   396
		if (hours)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   397
			[parts addObject:hoursString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   398
		if (minutes)
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   399
			[parts addObject:minutesString];
1130
467a6582f4e1 Fix the test failure that I made no longer intermittent in r26332. We want to compare against the smallest number of seconds that will round up to at least 1; 0.01 is too small and results in ??, 0 seconds?. All tests now pass.
Peter Hosey
parents: 55
diff changeset
   400
		if (showSeconds && (seconds >= 0.5))
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   401
			[parts addObject:secondsString];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   402
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   403
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   404
	return [parts componentsJoinedByString:@" "];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   405
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   406
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   407
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   408
/*!
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   409
 *@brief get the strftime-style format string for an NSDateFormatter
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   410
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   411
 * Translations are approximate! Not all fields supported by TR35-4 are
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   412
 * supported by the strftime format style.
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   413
 *
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   414
 *@result an NSString containing the strftime-style format string
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   415
 */ 
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   416
- (NSString *)dateCalendarFormat {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   417
	NSString *format = [self dateFormat];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   418
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   419
	// If we're using 10.0-10.3 behavior, it's easy
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   420
	if ([self formatterBehavior] == NSDateFormatterBehavior10_0) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   421
		return format;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   422
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   423
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   424
	// Scan across the format string, building the strftime-style format
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   425
	NSMutableString *newFormat = [[NSMutableString alloc] initWithCapacity:[format length]];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   426
	
1652
a6753f4b2901 Two more static analyzer leaks
David Smith
parents: 1561
diff changeset
   427
	NSScanner *scanner = [[[NSScanner alloc] initWithString:format] autorelease];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   428
	[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithRange:NSMakeRange(0, 0)]];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   429
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   430
	NSCharacterSet *t354symbols = [NSCharacterSet characterSetWithCharactersInString:@"GyYuMwWdDFgEeahHKkmsSAzZ'%"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   431
	
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   432
	while(![scanner isAtEnd]) {		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   433
		// Copy over anything that we don't handle specially
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   434
		NSString *skipped;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   435
		if ([scanner scanUpToCharactersFromSet:t354symbols intoString:&skipped]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   436
			[newFormat appendString:skipped];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   437
			continue;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   438
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   439
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   440
		// Get the current character and grab all contiguous repetitions of it
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   441
		unichar it = [format characterAtIndex:[scanner scanLocation]];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   442
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   443
		NSString *span;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   444
		if (![scanner scanCharactersFromSet:[NSCharacterSet characterSetWithRange:NSMakeRange(it, 1)]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   445
								 intoString:&span]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   446
			break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   447
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   448
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   449
		// Perform the translation		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   450
		// XXX Not supported or not fully supported: GuwWFgEeKkSAzZ
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   451
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   452
		if (it == 'G') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   453
			// strftime has no equivalent of era, so we assume it's AD
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   454
			[newFormat appendString:@"AD"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   455
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   456
		} else if (it == 'y' || it == 'y') {			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   457
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   458
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   459
					[newFormat appendString:@"%1y"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   460
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   461
				case 2:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   462
					[newFormat appendString:@"%y"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   463
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   464
				case 3:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   465
					[newFormat appendString:@"%3Y"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   466
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   467
				case 4:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   468
					[newFormat appendString:@"%Y"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   469
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   470
				default:
5997
d88e6711d0e0 Fixed a triple handful of warnings
Evan Schoenberg
parents: 4724
diff changeset
   471
                    [newFormat appendFormat:@"%%%luY", (unsigned long)[span length]];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   472
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   473
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   474
		} else if (it == 'M') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   475
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   476
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   477
					[newFormat appendString:@"%1m"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   478
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   479
				case 2:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   480
					[newFormat appendString:@"%m"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   481
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   482
				case 3:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   483
					[newFormat appendString:@"%b"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   484
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   485
				case 4:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   486
					[newFormat appendString:@"%B"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   487
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   488
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   489
					[newFormat appendString:@"%1b"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   490
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   491
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   492
		} else if (it == 'd') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   493
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   494
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   495
					[newFormat appendString:@"%e"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   496
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   497
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   498
					[newFormat appendString:@"%d"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   499
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   500
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   501
		} else if (it == 'D') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   502
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   503
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   504
					[newFormat appendString:@"%1j"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   505
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   506
				case 2:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   507
					[newFormat appendString:@"%2j"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   508
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   509
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   510
					[newFormat appendString:@"%j"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   511
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   512
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   513
		} else if (it == 'E' || it == 'e') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   514
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   515
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   516
				case 2:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   517
					// XXX In TR35-4, Sunday = 1, whereas in strftime Sunday = 0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   518
					[newFormat appendString:@"%w"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   519
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   520
				case 3:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   521
					[newFormat appendString:@"%a"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   522
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   523
				case 4:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   524
					[newFormat appendString:@"%A"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   525
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   526
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   527
					[newFormat appendString:@"%1a"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   528
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   529
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   530
		} else if (it == 'a') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   531
			[newFormat appendString:@"%p"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   532
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   533
		} else if (it == 'h') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   534
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   535
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   536
					[newFormat appendString:@"%1I"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   537
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   538
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   539
					[newFormat appendString:@"%I"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   540
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   541
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   542
		} else if (it == 'H') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   543
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   544
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   545
					[newFormat appendString:@"%1H"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   546
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   547
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   548
					[newFormat appendString:@"%H"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   549
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   550
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   551
		} else if (it == 'm') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   552
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   553
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   554
					[newFormat appendString:@"%1M"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   555
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   556
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   557
					[newFormat appendString:@"%M"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   558
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   559
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   560
		} else if (it == 's') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   561
			switch ([span length]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   562
				case 1:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   563
					[newFormat appendString:@"%1S"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   564
					break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   565
				default:
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   566
					[newFormat appendString:@"%S"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   567
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   568
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   569
		} else if (it == 'z') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   570
			[newFormat appendString:@"%Z"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   571
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   572
		} else if (it == 'Z') {
5
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   573
			switch ([span length]) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   574
				case 1:
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   575
					[newFormat appendString:@"GMT%z"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   576
					break;
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   577
				default:
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   578
					[newFormat appendString:@"%z"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   579
			}
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   580
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   581
		} else if (it == '\'') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   582
			if ([span length] >= 2) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   583
				[newFormat appendString:@"'"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   584
				[scanner setScanLocation:[scanner scanLocation] - [span length] + 2];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   585
			
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   586
			} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   587
				while(1) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   588
					NSString *text;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   589
					if ([scanner scanUpToCharactersFromSet:[NSCharacterSet characterSetWithCharactersInString:@"'%"]
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   590
												intoString:&text]) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   591
						[newFormat appendString:text];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   592
					}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   593
					
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   594
					if ([format characterAtIndex:([scanner scanLocation] + 1)] == '\'') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   595
						if (([scanner scanLocation] + 1 < [format length]) && ([format characterAtIndex:([scanner scanLocation] + 1)] == '\'')) {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   596
							[newFormat appendString:@"'"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   597
							[scanner setScanLocation:([scanner scanLocation] + 2)];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   598
						} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   599
							[scanner setScanLocation:([scanner scanLocation] + 1)];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   600
							break;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   601
						}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   602
					} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   603
						[newFormat appendString:@"%%"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   604
					}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   605
				}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   606
			}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   607
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   608
		} else if (it == '%') {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   609
			[newFormat appendString:@"%%"];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   610
			[scanner setScanLocation:[scanner scanLocation] - [span length] + 1];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   611
		
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   612
		} else {
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   613
			//NSLog(@"Unhandled format %@", span);
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   614
		}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   615
	}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   616
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   617
	// Make it immutable
1658
414648997e43 Date formatter additions were super leaky...
David Smith
parents: 1652
diff changeset
   618
	NSString *result = [[newFormat copy] autorelease];
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   619
	[newFormat release];
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   620
	return result;
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   621
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   622
	// http://developer.apple.com/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatterSyntax.html
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   623
	// http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   624
}
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   625
5
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   626
/*!
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   627
 *@brief get the Unicode TR35-4-style format string for an NSDateFormatter
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   628
 *
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   629
 *@result an NSString containing the Unicode-style format string
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   630
 */ 
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   631
- (NSString *)dateUnicodeFormat {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   632
	NSString *format = [self dateFormat];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   633
	
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   634
	// If we're using 10.4+ behavior, it's easy
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   635
	if ([self formatterBehavior] == NSDateFormatterBehavior10_4) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   636
		return format;
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   637
	}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   638
	
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   639
	// Scan across the format string, building the strftime-style format
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   640
	NSMutableString *newFormat = [[NSMutableString alloc] initWithCapacity:[format length]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   641
	
1652
a6753f4b2901 Two more static analyzer leaks
David Smith
parents: 1561
diff changeset
   642
	NSScanner *scanner = [[[NSScanner alloc] initWithString:format] autorelease];
5
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   643
	[scanner setCharactersToBeSkipped:[NSCharacterSet characterSetWithRange:NSMakeRange(0, 0)]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   644
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   645
	while(![scanner isAtEnd]) {		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   646
		// Skip to the first percentage sign
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   647
		NSString *skipped;
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   648
		if ([scanner scanUpToString:@"%" intoString:&skipped]) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   649
			[newFormat appendString:skipped];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   650
			continue;
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   651
		}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   652
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   653
		// Scan the percentage sign, we don't care about it
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   654
		[scanner scanString:@"%" intoString:nil];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   655
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   656
		// Get the character following the format string
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   657
		NSUInteger n = 2;
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   658
		unichar it = [format characterAtIndex:[scanner scanLocation]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   659
		
6
d5597fbe1658 Xcode is annoying about TODO comments.
Ryan Govostes
parents: 5
diff changeset
   660
		// Did we get a numeric flag? These aren't actually documented, so
d5597fbe1658 Xcode is annoying about TODO comments.
Ryan Govostes
parents: 5
diff changeset
   661
		// it's unclear as to how to treat them. Can you have multiple digits?
d5597fbe1658 Xcode is annoying about TODO comments.
Ryan Govostes
parents: 5
diff changeset
   662
		// Currently we don't support padding, so %5Y will incorrectly yield
d5597fbe1658 Xcode is annoying about TODO comments.
Ryan Govostes
parents: 5
diff changeset
   663
		// 2008 (yyyy) instead of 02008 (yyyyy).
5
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   664
		if (it >= '0' && it <= '9') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   665
			n = it - '0';
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   666
			[scanner setScanLocation:[scanner scanLocation] + 2];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   667
			it = [format characterAtIndex:[scanner scanLocation]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   668
		} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   669
			[scanner setScanLocation:[scanner scanLocation] + 1];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   670
		}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   671
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   672
		// Perform the translation		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   673
		// XXX Not supported or not fully supported: 
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   674
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   675
		if (it == '%') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   676
			[newFormat appendString:@"%"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   677
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   678
		} else if (it == 'a') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   679
			[newFormat appendString:@"EEE"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   680
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   681
		} else if (it == 'A') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   682
			[newFormat appendString:@"EEEE"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   683
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   684
		} else if (it == 'b') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   685
			[newFormat appendString:@"MMM"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   686
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   687
		} else if (it == 'B') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   688
			[newFormat appendString:@"MMMM"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   689
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   690
		} else if (it == 'c') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   691
			// Same as "%X %x"
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   692
			// Not an exact conversion, I should see what matches most closely.
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   693
			NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   694
			[tempFormatter setDateStyle:NSDateFormatterFullStyle];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   695
			[tempFormatter setTimeStyle:NSDateFormatterFullStyle];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   696
			[newFormat appendString:[tempFormatter dateFormat]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   697
			[tempFormatter release];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   698
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   699
		} else if (it == 'd') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   700
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   701
				[newFormat appendString:@"d"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   702
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   703
				[newFormat appendString:@"dd"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   704
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   705
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   706
		} else if (it == 'e') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   707
			[newFormat appendString:@"d"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   708
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   709
		} else if (it == 'F') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   710
			[newFormat appendString:@"SSSS"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   711
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   712
		} else if (it == 'H') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   713
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   714
				[newFormat appendString:@"H"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   715
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   716
				[newFormat appendString:@"HH"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   717
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   718
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   719
		} else if (it == 'I') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   720
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   721
				[newFormat appendString:@"h"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   722
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   723
				[newFormat appendString:@"hh"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   724
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   725
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   726
		} else if (it == 'j') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   727
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   728
				[newFormat appendString:@"D"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   729
			} else if (n == 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   730
				[newFormat appendString:@"DD"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   731
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   732
				[newFormat appendString:@"DDD"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   733
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   734
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   735
		} else if (it == 'm') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   736
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   737
				[newFormat appendString:@"M"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   738
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   739
				[newFormat appendString:@"MM"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   740
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   741
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   742
		} else if (it == 'M') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   743
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   744
				[newFormat appendString:@"m"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   745
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   746
				[newFormat appendString:@"mm"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   747
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   748
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   749
		} else if (it == 'p') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   750
			[newFormat appendString:@"a"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   751
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   752
		} else if (it == 's') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   753
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   754
				[newFormat appendString:@"s"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   755
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   756
				[newFormat appendString:@"ss"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   757
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   758
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   759
		} else if (it == 'w') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   760
			// Not a perfect translation, assumes start of week is Sunday. If it
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   761
			// is Monday, should use 'E' instead of 'e'.
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   762
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   763
				[newFormat appendString:@"e"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   764
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   765
				[newFormat appendString:@"ee"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   766
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   767
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   768
		} else if (it == 'x') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   769
			// Date representation for the locale, including time zone.
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   770
			// Not an exact conversion, I should see what matches most closely.
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   771
			NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   772
			[tempFormatter setDateStyle:NSDateFormatterFullStyle];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   773
			[tempFormatter setTimeStyle:NSDateFormatterNoStyle];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   774
			[newFormat appendString:[tempFormatter dateFormat]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   775
			[tempFormatter release];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   776
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   777
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   778
		} else if (it == 'X') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   779
			// Time representation for the locale.
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   780
			// Not an exact conversion, I should see what matches most closely.
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   781
			NSDateFormatter *tempFormatter = [[NSDateFormatter alloc] init];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   782
			[tempFormatter setDateStyle:NSDateFormatterNoStyle];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   783
			[tempFormatter setTimeStyle:NSDateFormatterFullStyle];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   784
			[newFormat appendString:[tempFormatter dateFormat]];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   785
			[tempFormatter release];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   786
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   787
		} else if (it == 'y' || (it == 'Y' && n <= 2)) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   788
			if (n < 2) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   789
				[newFormat appendString:@"y"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   790
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   791
				[newFormat appendString:@"yy"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   792
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   793
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   794
		} else if (it == 'Y') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   795
			if (n == 3) {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   796
				[newFormat appendString:@"yyy"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   797
			} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   798
				[newFormat appendString:@"yyyy"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   799
			}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   800
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   801
		} else if (it == 'Z') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   802
			[newFormat appendString:@"zzzz"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   803
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   804
		} else if (it == 'z') {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   805
			[newFormat appendString:@"ZZ"];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   806
		
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   807
		} else {
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   808
			// Not a supported identifier
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   809
		}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   810
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   811
			
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   812
	}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   813
	
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   814
	// Make it immutable
1658
414648997e43 Date formatter additions were super leaky...
David Smith
parents: 1652
diff changeset
   815
	NSString *result = [[newFormat copy] autorelease];
5
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   816
	[newFormat release];
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   817
	return result;
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   818
	
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   819
	// http://developer.apple.com/documentation/Cocoa/Conceptual/DataFormatting/Articles/dfDateFormatterSyntax.html
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   820
	// http://unicode.org/reports/tr35/tr35-4.html#Date_Format_Patterns
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   821
}
ff66700b611f Add -[NSDateFormatter dateUnicodeFormat] to get a Unicode TR35-4-style format string. The translations need to be verified.
Ryan Govostes
parents: 0
diff changeset
   822
0
e22ad6bc8b46 svn 1.5 merge tracking is terrible. This is a manual merge of the Sparkle 1.5 branch into trunk
David Smith
parents:
diff changeset
   823
@end