Ignore:
Timestamp:
10/20/02 06:40:54 (20 years ago)
Author:
Nicholas Riley
Message:

Pester 1.0

File:
1 edited

Legend:

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

    r26 r28  
    2121    [alarmMessage release]; alarmMessage = nil;
    2222    [invalidMessage release]; invalidMessage = nil;
    23     [timer release]; timer = nil;
     23    [timer invalidate]; [timer release]; timer = nil;
    2424    [super dealloc];
    2525}
     
    4848- (void)_validateForType:(PSAlarmType)type;
    4949{
     50    if (alarmType == PSAlarmSet) return; // already valid
    5051    [invalidMessage release];
    5152    invalidMessage = nil;
     
    7273- (void)_setIntervalFromDate;
    7374{
    74     alarmInterval = [alarmDate timeIntervalSinceNow];
     75    alarmInterval = [alarmDate timeIntervalSinceNow] + 1;
    7576    if (alarmInterval <= 0) {
    7677        [self _invalidate: @"Please specify an alarm time in the future."];
     
    142143}
    143144
    144 - (NSDate *)date;
     145- (NSCalendarDate *)date;
    145146{
    146147    if (alarmType == PSAlarmInterval) [self _setDateFromInterval];
     
    148149}
    149150
     151- (NSString *)shortDateString;
     152{
     153    return [[self date] descriptionWithCalendarFormat: [[NSUserDefaults standardUserDefaults] stringForKey: NSShortDateFormatString]];
     154}
     155
     156- (NSString *)timeString;
     157{
     158    return [[self date] descriptionWithCalendarFormat: @"%1I:%M:%S %p"]; // XXX regular format doesn't work
     159}
     160
     161- (NSString *)timeRemainingString;
     162{
     163    static const unsigned long long minute = 60, hour = minute * 60, day = hour * 24, year = day * 365.26;
     164    unsigned long long interval = [self interval];
     165    // +[NSString stringWithFormat:] in 10.1 does not support long longs: work around it by converting to unsigned ints or longs for display
     166    if (interval == 0) return @"ÇexpiredÈ";
     167    if (interval < minute) return [NSString stringWithFormat: @"%us", (unsigned)interval];
     168    if (interval < day) return [NSString stringWithFormat: @"%uh %um", (unsigned)(interval / hour), (unsigned)((interval % hour) / minute)];
     169    if (interval < year) return [NSString stringWithFormat: @"%u days", (unsigned)(interval / day)];
     170    if (interval < 2 * year) return @"One year";
     171    return [NSString stringWithFormat: @"%lu years", (unsigned long)(interval / year)];
     172}
     173
    150174- (NSTimeInterval)interval;
    151175{
    152     if (alarmType == PSAlarmSet) return [timer timeInterval]; // XXX counts down?
    153     if (alarmType == PSAlarmDate) [self _setIntervalFromDate];
     176    if (alarmType == PSAlarmSet || alarmType == PSAlarmDate) [self _setIntervalFromDate];
    154177    return alarmInterval;
    155178}
     
    166189                                                    repeats: NO];
    167190            if (timer != nil) {
     191                [timer retain];
    168192                alarmType = PSAlarmSet;
    169193                [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerSetNotification object: self];
     
    177201- (void)cancel;
    178202{
     203    [timer invalidate]; [timer release]; timer = nil;
     204}
     205
     206- (void)_timerExpired:(NSTimer *)aTimer;
     207{
     208    [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self];
    179209    [timer release]; timer = nil;
    180 }
    181 
    182 - (void)_timerExpired:(NSTimer *)aTimer;
    183 {
    184     [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self];
    185     timer = nil;
    186     [timer release];
    187210}
    188211
     
    229252    }
    230253    [coder encodeObject: alarmMessage];
     254    // NSLog(@"encoded: %@", self); // XXX happening twice, gdb refuses to show proper backtrace, grr
    231255    return;
    232256}
Note: See TracChangeset for help on using the changeset viewer.