Changeset 28 for trunk/Cocoa/Pester/Source/PSAlarm.m
- Timestamp:
- 10/20/02 06:40:54 (22 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/PSAlarm.m
r26 r28 21 21 [alarmMessage release]; alarmMessage = nil; 22 22 [invalidMessage release]; invalidMessage = nil; 23 [timer release]; timer = nil;23 [timer invalidate]; [timer release]; timer = nil; 24 24 [super dealloc]; 25 25 } … … 48 48 - (void)_validateForType:(PSAlarmType)type; 49 49 { 50 if (alarmType == PSAlarmSet) return; // already valid 50 51 [invalidMessage release]; 51 52 invalidMessage = nil; … … 72 73 - (void)_setIntervalFromDate; 73 74 { 74 alarmInterval = [alarmDate timeIntervalSinceNow] ;75 alarmInterval = [alarmDate timeIntervalSinceNow] + 1; 75 76 if (alarmInterval <= 0) { 76 77 [self _invalidate: @"Please specify an alarm time in the future."]; … … 142 143 } 143 144 144 - (NS Date *)date;145 - (NSCalendarDate *)date; 145 146 { 146 147 if (alarmType == PSAlarmInterval) [self _setDateFromInterval]; … … 148 149 } 149 150 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 150 174 - (NSTimeInterval)interval; 151 175 { 152 if (alarmType == PSAlarmSet) return [timer timeInterval]; // XXX counts down? 153 if (alarmType == PSAlarmDate) [self _setIntervalFromDate]; 176 if (alarmType == PSAlarmSet || alarmType == PSAlarmDate) [self _setIntervalFromDate]; 154 177 return alarmInterval; 155 178 } … … 166 189 repeats: NO]; 167 190 if (timer != nil) { 191 [timer retain]; 168 192 alarmType = PSAlarmSet; 169 193 [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerSetNotification object: self]; … … 177 201 - (void)cancel; 178 202 { 203 [timer invalidate]; [timer release]; timer = nil; 204 } 205 206 - (void)_timerExpired:(NSTimer *)aTimer; 207 { 208 [[NSNotificationCenter defaultCenter] postNotificationName: PSAlarmTimerExpiredNotification object: self]; 179 209 [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];187 210 } 188 211 … … 229 252 } 230 253 [coder encodeObject: alarmMessage]; 254 // NSLog(@"encoded: %@", self); // XXX happening twice, gdb refuses to show proper backtrace, grr 231 255 return; 232 256 }
Note:
See TracChangeset
for help on using the changeset viewer.