Changeset 608
- Timestamp:
- 12/21/09 22:13:21 (15 years ago)
- Location:
- trunk/Cocoa/Pester/Source
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Cocoa/Pester/Source/PSAlarm.h
r366 r608 48 48 49 49 - (NSCalendarDate *)date; 50 - (NSDate *)midnightOnDate; 50 51 - (NSDate *)time; 52 - (int)daysFromToday; 51 53 - (NSTimeInterval)interval; 52 54 - (NSTimeInterval)timeRemaining; -
trunk/Cocoa/Pester/Source/PSAlarm.m
r602 r608 29 29 30 30 static NSDateFormatter *dateFormatter, *shortDateFormatter, *timeFormatter; 31 32 static NSCalendar *gregorianCalendar; 33 34 static NSDate *midnightOnDate(NSDate *date) { 35 return [gregorianCalendar dateFromComponents: 36 [gregorianCalendar components: NSMonthCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit fromDate: date]]; 37 } 31 38 32 39 @implementation PSAlarm … … 46 53 [timeFormatter setTimeStyle: NSDateFormatterMediumStyle]; 47 54 [timeFormatter setDateStyle: NSDateFormatterNoStyle]; 55 gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; 48 56 } 49 57 … … 246 254 } 247 255 256 - (NSDate *)midnightOnDate; 257 { 258 if (alarmType == PSAlarmInterval) [self _setDateFromInterval]; 259 260 return midnightOnDate(alarmDate); 261 } 262 248 263 - (NSDate *)time; 249 264 { … … 251 266 if (alarmType == PSAlarmInterval) [self _setDateFromInterval]; 252 267 253 NSCalendar *calendar = [NSCalendar currentCalendar]; 254 255 return [calendar dateFromComponents: 256 [calendar components: NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate: alarmDate]]; 268 return [gregorianCalendar dateFromComponents: 269 [gregorianCalendar components: NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate: alarmDate]]; 270 } 271 272 - (int)daysFromToday; 273 { 274 if (alarmType == PSAlarmInterval) [self _setDateFromInterval]; 275 276 return [[gregorianCalendar components: NSDayCalendarUnit fromDate: midnightOnDate([NSDate date]) toDate: alarmDate options: 0] day]; 257 277 } 258 278 -
trunk/Cocoa/Pester/Source/PSAlarmSetController.m
r606 r608 165 165 { 166 166 // NSLog(@"updateDateDisplay: %@", sender); 167 if ([alarm isValid]) { 168 [self setStatus: [NSString stringWithFormat: @"Alarm will be set for %@\non %@.", [alarm timeString], [alarm dateString]]]; 169 [setButton setEnabled: YES]; 170 if (updateTimer == nil || ![updateTimer isValid]) { 171 // XXX this logic (and the timer) should really go into PSAlarm, to send notifications for status updates instead. Timer starts when people are watching, stops when people aren't. 172 // NSLog(@"setting timer"); 173 if (isInterval) { 174 updateTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: YES]; 175 } else { 176 updateTimer = [NSTimer scheduledTimerWithTimeInterval: [alarm interval] target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: NO]; 177 } 178 [updateTimer retain]; 179 } 180 } else { 181 [setButton setEnabled: NO]; 182 [self setStatus: [alarm invalidMessage]]; 183 [self _stopUpdateTimer]; 167 if (![alarm isValid]) { 168 [setButton setEnabled: NO]; 169 [self setStatus: [alarm invalidMessage]]; 170 [self _stopUpdateTimer]; 171 return; 172 } 173 174 const int day = 60 * 60 * 24; 175 int daysUntilAlarm = [alarm daysFromToday]; 176 NSString *onString; 177 switch (daysUntilAlarm) { 178 case 0: onString = @"today,"; break; 179 case 1: onString = @"tomorrow,"; break; 180 default: onString = @"on"; 181 } 182 183 [self setStatus: [NSString stringWithFormat: @"Alarm will be set for %@\n%@ %@.", [alarm timeString], onString, [alarm dateString]]]; 184 [setButton setEnabled: YES]; 185 if (updateTimer == nil || ![updateTimer isValid]) { 186 // XXX this logic (and the timer) should really go into PSAlarm, to send notifications for status updates instead. Timer starts when people are watching, stops when people aren't. 187 // NSLog(@"setting timer"); 188 if (isInterval) { 189 updateTimer = [NSTimer scheduledTimerWithTimeInterval: 1 target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: YES]; 190 } else { 191 // XXX time/time zone change 192 NSTimeInterval interval = [alarm interval]; 193 if (daysUntilAlarm < 2 && interval > day) 194 interval = [[alarm midnightOnDate] timeIntervalSinceNow]; 195 updateTimer = [NSTimer scheduledTimerWithTimeInterval: interval target: self selector: @selector(updateDateDisplay:) userInfo: nil repeats: NO]; 196 } 197 [updateTimer retain]; 184 198 } 185 199 }
Note:
See TracChangeset
for help on using the changeset viewer.