Ignore:
Timestamp:
11/24/07 03:03:52 (17 years ago)
Author:
Nicholas Riley
Message:

PSAlarm.m: Use 10.4-style (ICU-based) date formatters, which pick up format changes automatically. Still some un-localized bits for intervals and "on"/"at".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Cocoa/Pester/Source/PSAlarm.m

    r355 r358  
    1111#import "PSAlerts.h"
    1212#import "PSTimer.h"
    13 #import "NJRDateFormatter.h"
    1413#import "NSCalendarDate-NJRExtensions.h"
    1514#import "NSDictionary-NJRExtensions.h"
     
    2928static NSString * const PLAlarmRepeating = @"repeating"; // NSNumber
    3029
    31 static NSString *dateFormat, *shortDateFormat, *timeFormat;
    32 static NSDictionary *locale;
     30static NSDateFormatter *dateFormatter, *shortDateFormatter, *timeFormatter;
    3331
    3432@implementation PSAlarm
     
    3634#pragma mark initialize-release
    3735
    38 + (void)initialize; // XXX change on locale modification, subscribe to NSNotifications
    39 {
    40     dateFormat = [[NJRDateFormatter localizedDateFormatIncludingWeekday: YES] retain];
    41     shortDateFormat = [[NJRDateFormatter localizedShortDateFormatIncludingWeekday: NO] retain];
    42     timeFormat = [[NJRDateFormatter localizedTimeFormatIncludingSeconds: YES] retain];
    43     locale = [[[NSUserDefaults standardUserDefaults] dictionaryRepresentation] retain];
     36+ (void)initialize;
     37{
     38    [NSDateFormatter setDefaultFormatterBehavior: NSDateFormatterBehavior10_4];
     39    dateFormatter = [[NSDateFormatter alloc] init];
     40    [dateFormatter setTimeStyle: NSDateFormatterNoStyle];
     41    [dateFormatter setDateStyle: NSDateFormatterFullStyle];
     42    shortDateFormatter = [[NSDateFormatter alloc] init];
     43    [shortDateFormatter setTimeStyle: NSDateFormatterNoStyle];
     44    [shortDateFormatter setDateStyle: NSDateFormatterShortStyle];
     45    timeFormatter = [[NSDateFormatter alloc] init];
     46    [timeFormatter setTimeStyle: NSDateFormatterMediumStyle];
     47    [timeFormatter setDateStyle: NSDateFormatterNoStyle];
    4448}
    4549
     
    291295- (NSString *)dateString;
    292296{
    293     return [[self date] descriptionWithCalendarFormat: dateFormat locale: locale];
     297    return [dateFormatter stringFromDate: [self date]];
    294298}
    295299
    296300- (NSString *)shortDateString;
    297301{
    298     return [[self date] descriptionWithCalendarFormat: shortDateFormat locale: locale];
     302    return [shortDateFormatter stringFromDate: [self date]];
    299303}
    300304
    301305- (NSString *)timeString;
    302306{
    303     return [[self date] descriptionWithCalendarFormat: timeFormat locale: locale];
     307    return [timeFormatter stringFromDate: [self date]];
    304308}
    305309
     
    316320        NSCalendarDate *date = [[NSCalendarDate alloc] initWithTimeIntervalSinceNow: [self interval]];
    317321        NSString *nextDateTimeString = [NSString stringWithFormat: @"%@ at %@",
    318             [date descriptionWithCalendarFormat: dateFormat locale: locale],
    319             [date descriptionWithCalendarFormat: timeFormat locale: locale]];
     322                                        [dateFormatter stringFromDate: date],
     323                                        [timeFormatter stringFromDate: date]];
    320324        [date release];
    321325        return nextDateTimeString;
Note: See TracChangeset for help on using the changeset viewer.