Changeset 4480

Show
Ignore:
Timestamp:
02/05/07 11:44:37 (2 years ago)
Author:
morris
Message:

Add WIDateFormatter

Remove date formatting methods from NSDate

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • WiredAdditions/trunk/NSDate-WIAdditions.h

    r4438 r4480  
    3535 
    3636 
    37 @interface NSDate(WIDateLocalization) 
    38  
    39 - (NSString *)commonDateStringWithSeconds:(BOOL)seconds; 
    40 - (NSString *)commonDateStringWithSeconds:(BOOL)seconds relative:(BOOL)relative; 
    41 - (NSString *)commonDateStringWithSeconds:(BOOL)seconds relative:(BOOL)relative capitalized:(BOOL)capitalized; 
    42 - (NSString *)fullDateStringWithSeconds:(BOOL)seconds; 
    43 - (NSString *)timeStringWithSeconds:(BOOL)seconds; 
    44  
    45 @end 
    46  
    47  
    4837@interface NSCalendarDate(WICalendarDateeAdditions) 
    4938 
  • WiredAdditions/trunk/NSDate-WIAdditions.m

    r4438 r4480  
    5959 
    6060 
    61 @implementation NSDate(WIDateLocalization) 
    62  
    63 - (NSString *)commonDateStringWithSeconds:(BOOL)seconds { 
    64         return [self commonDateStringWithSeconds:seconds relative:YES capitalized:YES]; 
    65 } 
    66  
    67  
    68  
    69 - (NSString *)commonDateStringWithSeconds:(BOOL)seconds relative:(BOOL)relative { 
    70         return [self commonDateStringWithSeconds:seconds relative:relative capitalized:YES]; 
    71 } 
    72  
    73  
    74  
    75 - (NSString *)commonDateStringWithSeconds:(BOOL)seconds relative:(BOOL)relative capitalized:(BOOL)capitalized { 
    76         NSCalendarDate          *calendarDate, *calendarDateToday; 
    77         NSUserDefaults          *defaults; 
    78         NSMutableString         *time; 
    79         NSString                        *string, *date, *format; 
    80         NSRange                         range; 
    81         BOOL                            today = NO, yesterday = NO; 
    82          
    83         defaults = [NSUserDefaults standardUserDefaults]; 
    84          
    85         if(relative) { 
    86                 calendarDate = [self dateWithCalendarFormat:NULL timeZone:NULL]; 
    87                 calendarDateToday = [NSCalendarDate calendarDate]; 
    88                  
    89                 if([calendarDate dayOfCommonEra] == [calendarDateToday dayOfCommonEra]) 
    90                         today = YES; 
    91                 else if([calendarDate dayOfCommonEra] == [calendarDateToday dayOfCommonEra] - 1) 
    92                         yesterday = YES; 
    93         } 
    94          
    95         date = [defaults objectForKey:NSDateFormatString]; 
    96          
    97         if(today || yesterday) { 
    98                 if(today) 
    99                         date = [[defaults objectForKey:NSThisDayDesignations] objectAtIndex:0]; 
    100                 else if(yesterday) 
    101                         date = [[defaults objectForKey:NSPriorDayDesignations] objectAtIndex:0]; 
    102                  
    103                 if(capitalized) 
    104                         date = [date capitalizedString]; 
    105         } 
    106          
    107         time = [[defaults objectForKey:NSTimeFormatString] mutableCopy]; 
    108          
    109         // --- fix a bug where the date formats would have 12-hour clocks 
    110         range = [time rangeOfString:@"%H"]; 
    111          
    112         if(range.location != NSNotFound) { 
    113                 // --- time has 24-hour clock, adjust our format accordingly 
    114                 [time replaceOccurrencesOfString:@"%I" 
    115                                                           withString:@"%H" 
    116                                                                  options:0 
    117                                                                    range:NSMakeRange(0, [time length])]; 
    118         } 
    119          
    120         // --- fix a bug where the date formats would have 24-hour clocks 
    121         range = [time rangeOfString:@"%I"]; 
    122          
    123         if(range.location != NSNotFound) { 
    124                 // --- time has 12-hour clock, adjust our format accordingly 
    125                 [time replaceOccurrencesOfString:@"%H" 
    126                                                           withString:@"%I" 
    127                                                                  options:0 
    128                                                                    range:NSMakeRange(0, [time length])]; 
    129         } 
    130          
    131         // --- kill seconds 
    132         if(!seconds) { 
    133                 range = [time rangeOfString:@":%S"]; 
    134                  
    135                 if(range.location != NSNotFound) 
    136                         [time deleteCharactersInRange:range]; 
    137                  
    138                 range = [time rangeOfString:@".%S"]; 
    139                  
    140                 if(range.location != NSNotFound) 
    141                         [time deleteCharactersInRange:range]; 
    142         } 
    143          
    144         // --- get final format 
    145         format = [NSSWF:@"%@, %@", date, time]; 
    146         string = [self descriptionWithCalendarFormat:format 
    147                                                                                 timeZone:NULL 
    148                                                                                   locale:[defaults dictionaryRepresentation]]; 
    149          
    150         [time release]; 
    151          
    152         return string; 
    153 } 
    154  
    155  
    156  
    157 - (NSString *)fullDateStringWithSeconds:(BOOL)seconds { 
    158         NSUserDefaults          *defaults; 
    159         NSMutableString         *time; 
    160         NSString                        *string, *format, *date; 
    161         NSRange                         range; 
    162          
    163         defaults = [NSUserDefaults standardUserDefaults]; 
    164         date = [defaults objectForKey:NSShortDateFormatString]; 
    165         time = [[defaults objectForKey:NSTimeFormatString] mutableCopy]; 
    166          
    167         // --- fix a bug where the date formats would have 12-hour clocks 
    168         range = [time rangeOfString:@"%H"]; 
    169          
    170         if(range.location != NSNotFound) { 
    171                 // --- time has 24-hour clock, adjust our format accordingly 
    172                 [time replaceOccurrencesOfString:@"%I" 
    173                                                           withString:@"%H" 
    174                                                                  options:0 
    175                                                                    range:NSMakeRange(0, [time length])]; 
    176         } 
    177          
    178         // --- fix a bug where the date formats would have 24-hour clocks 
    179         range = [time rangeOfString:@"%I"]; 
    180          
    181         if(range.location != NSNotFound) { 
    182                 // --- time has 12-hour clock, adjust our format accordingly 
    183                 [time replaceOccurrencesOfString:@"%H" 
    184                                                           withString:@"%I" 
    185                                                                  options:0 
    186                                                                    range:NSMakeRange(0, [time length])]; 
    187         } 
    188          
    189         // --- kill seconds 
    190         if(!seconds) { 
    191                 range = [time rangeOfString:@":%S"]; 
    192                  
    193                 if(range.location != NSNotFound) 
    194                         [time deleteCharactersInRange:range]; 
    195                  
    196                 range = [time rangeOfString:@".%S"]; 
    197                  
    198                 if(range.location != NSNotFound) 
    199                         [time deleteCharactersInRange:range]; 
    200         } 
    201          
    202         format = [NSSWF:@"%@, %@", date, time]; 
    203         string = [self descriptionWithCalendarFormat:format 
    204                                                                                 timeZone:NULL 
    205                                                                                   locale:[defaults dictionaryRepresentation]]; 
    206          
    207         // --- fix bug where extraneous space characters would be left at the end 
    208         while([string hasSuffix:@" "]) 
    209                 string = [string substringToIndex:[string length] - 1]; 
    210          
    211         [time release]; 
    212          
    213         return string; 
    214 } 
    215  
    216  
    217  
    218 - (NSString *)timeStringWithSeconds:(BOOL)seconds { 
    219         NSUserDefaults          *defaults; 
    220         NSMutableString         *time; 
    221         NSString                        *string; 
    222         NSRange                         range; 
    223          
    224         defaults = [NSUserDefaults standardUserDefaults]; 
    225         time = [[defaults objectForKey:NSTimeFormatString] mutableCopy]; 
    226          
    227         // --- fix a bug where the date formats would have 12-hour clocks 
    228         range = [time rangeOfString:@"%H"]; 
    229          
    230         if(range.location != NSNotFound) { 
    231                 // --- time has 24-hour clock, adjust our format accordingly 
    232                 [time replaceOccurrencesOfString:@"%I" 
    233                                                           withString:@"%H" 
    234                                                                  options:0 
    235                                                                    range:NSMakeRange(0, [time length])]; 
    236         } 
    237          
    238         // --- fix a bug where the date formats would have 24-hour clocks 
    239         range = [time rangeOfString:@"%I"]; 
    240          
    241         if(range.location != NSNotFound) { 
    242                 // --- time has 12-hour clock, adjust our format accordingly 
    243                 [time replaceOccurrencesOfString:@"%H" 
    244                                                           withString:@"%I" 
    245                                                                  options:0 
    246                                                                    range:NSMakeRange(0, [time length])]; 
    247         } 
    248          
    249         // --- kill seconds 
    250         if(!seconds) { 
    251                 range = [time rangeOfString:@":%S"]; 
    252                  
    253                 if(range.location != NSNotFound) 
    254                         [time deleteCharactersInRange:range]; 
    255                  
    256                 range = [time rangeOfString:@".%S"]; 
    257                  
    258                 if(range.location != NSNotFound) 
    259                         [time deleteCharactersInRange:range]; 
    260         } 
    261          
    262         string = [self descriptionWithCalendarFormat:time 
    263                                                                                 timeZone:NULL 
    264                                                                                   locale:[defaults dictionaryRepresentation]]; 
    265          
    266         // --- fix bug where extraneous space characters would be left at the end 
    267         while([string hasSuffix:@" "]) 
    268                 string = [string substringToIndex:[string length] - 1]; 
    269          
    270         [time release]; 
    271          
    272         return string; 
    273 } 
    274  
    275 @end 
    276  
    277  
    278  
    27961@implementation NSCalendarDate(WICalendarDateAdditions) 
    28062 
  • WiredAdditions/trunk/WiredAdditions.h

    r4438 r4480  
    7373#import <WiredAdditions/WIAddress.h> 
    7474#import <WiredAdditions/WIApplication.h> 
     75#import <WiredAdditions/WIDateFormatter.h> 
    7576#import <WiredAdditions/WIError.h> 
    7677#import <WiredAdditions/WIEventQueue.h> 
  • WiredAdditions/trunk/WiredAdditions.xcodeproj/project.pbxproj

    r4464 r4480  
    5959                77B7C4AC0973FF5E009367B0 /* NSApplication-WIAdditions.m in Sources */ = {isa = PBXBuildFile; fileRef = 77B7C4AA0973FF5E009367B0 /* NSApplication-WIAdditions.m */; }; 
    6060                77B7C4AD0973FF5E009367B0 /* NSApplication-WIAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 77B7C4AB0973FF5E009367B0 /* NSApplication-WIAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 
     61                77C84DEF0B773382000F8478 /* WIDateFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 77C84DED0B773382000F8478 /* WIDateFormatter.m */; }; 
     62                77C84DF00B773382000F8478 /* WIDateFormatter.h in Headers */ = {isa = PBXBuildFile; fileRef = 77C84DEE0B773382000F8478 /* WIDateFormatter.h */; settings = {ATTRIBUTES = (Public, ); }; }; 
    6163                77CDAED8083B3781003BE654 /* ReleaseNotes.nib in Resources */ = {isa = PBXBuildFile; fileRef = 77CDAED6083B3781003BE654 /* ReleaseNotes.nib */; }; 
    6264                77D5170C0984F4AD0057D51F /* NSMenu-WIAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 77D5170A0984F4AD0057D51F /* NSMenu-WIAdditions.h */; settings = {ATTRIBUTES = (Public, ); }; }; 
     
    272274                77B7C4AA0973FF5E009367B0 /* NSApplication-WIAdditions.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = "NSApplication-WIAdditions.m"; sourceTree = "<group>"; }; 
    273275                77B7C4AB0973FF5E009367B0 /* NSApplication-WIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = "NSApplication-WIAdditions.h"; sourceTree = "<group>"; }; 
     276                77C84DED0B773382000F8478 /* WIDateFormatter.m */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.objc; path = WIDateFormatter.m; sourceTree = "<group>"; }; 
     277                77C84DEE0B773382000F8478 /* WIDateFormatter.h */ = {isa = PBXFileReference; fileEncoding = 5; lastKnownFileType = sourcecode.c.h; path = WIDateFormatter.h; sourceTree = "<group>"; }; 
    274278                77CDAED7083B3781003BE654 /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/ReleaseNotes.nib; sourceTree = "<group>"; }; 
    275279                77D5170A0984F4AD0057D51F /* NSMenu-WIAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSMenu-WIAdditions.h"; sourceTree = "<group>"; }; 
     
    649653                                A56B9EFA075B865F00B3B6AA /* WIApplication.m */, 
    650654                                A56B9EF9075B865F00B3B6AA /* WIApplication.h */, 
     655                                77C84DED0B773382000F8478 /* WIDateFormatter.m */, 
     656                                77C84DEE0B773382000F8478 /* WIDateFormatter.h */, 
    651657                                7772565B097E70640003B608 /* WIError.m */, 
    652658                                7772565A097E70640003B608 /* WIError.h */, 
     
    918924                                A56B9EFB075B865F00B3B6AA /* WIApplication.h in Headers */, 
    919925                                A544C2360758E1EE008446CF /* WIColorCell.h in Headers */, 
     926                                77C84DF00B773382000F8478 /* WIDateFormatter.h in Headers */, 
    920927                                7772565C097E70640003B608 /* WIError.h in Headers */, 
    921928                                A5B452960880BD95003B1DA1 /* WIEventQueue.h in Headers */, 
     
    11461153                                77246ED709DD7D230010335B /* WIExceptionHandler.m in Sources */, 
    11471154                                A54D3E86076337FE00227EBE /* WIFunctions.m in Sources */, 
     1155                                77C84DEF0B773382000F8478 /* WIDateFormatter.m in Sources */, 
    11481156                                A5D96CD5078DDB8A00CD982E /* WIGraphView.m in Sources */, 
    11491157                                A544C1480758DFA9008446CF /* WIIconCell.m in Sources */,